Huginn/crates/huginn-mind/src/lib.rs

82 lines
3.9 KiB
Rust
Raw Normal View History

Open a mind fail-closed over an owned redb store Cut 8, Huginn half, commit 1 of 4: the store port, the opener and the identity rules. `huginn-mind` gains its dependencies (`cultcache-rs` at Epiphany's pin `a0813c6`, `epiphany-pipeline` at `a65c6420`, the Epiphany half of this cut), `store.rs` with the one narrow `MindStore` trait that injects compare-and-swap, `mind.rs` with `Mind::open` and `open_with`, and `refusal.rs` with the organ's refusal vocabulary. The opener refuses in order and attaches nothing until every gate passes: a foreign type, a foreign epoch, a missing identity, an identity naming another instance. The path under the state root is derived from the slug; the `instance` document is the authority, so a store copied into another instance's directory is refused. The owned store's exclusive lock is the single-writer mechanism: a second `Mind::open` of the same path is `MindAlreadyOwned`. The receipt type and the two provenance shapes (`Faculty`, `PipelineProvenance`) land here rather than in the later commits because the opener registers the receipt's type id, and their only consumer is the receipt; the commit primitive itself is the next commit. `MindRefusal` carries a serde remote definition of the leaf's `PipelineRefusal`, which derives neither `Serialize` nor `JsonSchema` at the pinned rev; it is compiled against the leaf's type so a leaf change breaks the build rather than drifting. `Cargo.lock` is regenerated and gains 90 packages. The map predicted a CRLF-to-LF rewrite of the whole file; the file was already LF in the index and stays LF, so the diff is additions only. README and AGENTS now say `huginn-mind` is live and the other two crates are stubs. Builds: `cargo check -p huginn-mind --lib --tests` and `cargo test -p huginn-mind --lib` (4 tests) pass. This commit carries dead-code warnings on the store and cache accessors and the refusing test store; commits 2 and 3 consume them. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 17:04:23 +02:00
//! `huginn-mind`: one instance's mind as typed CultCache state.
//!
RS fix batch: read-side density, the smallest seal, R5's two shapes, stale prose F1: AdmissionIndex::build now calls receipt::head before copying any ordinal, so query and view refuse a receipt chain that is not exactly {1..=N} (duplicate, gap, zero, or above-N) instead of trusting a stored ordinal unchecked. New test query::tests::query_and_view_refuse_a_receipt_chain_that_is_not_dense pins it behaviourally: it plants each broken chain directly (bypassing admission) and asserts query and view both refuse. The schema's ordinal gets minimum: 1 (was 0), matched by #[schemars(range(min = 1))] on AdmissionFacts::ordinal. head's doc now says AdmissionIndex::build asks it too. F2: Mind::open_with is renamed to an internal open_checked, and a test-only Mind::open_with is gated behind cfg(test) or the test-support feature, exactly like store_path_for. Production reaches open_checked only through Mind::open, which takes the store's per-path lock first. mind::tests::a_mind_has_one_owner_at_a_time (pre-existing) still pins that a second Mind::open on the same path is refused. The full store seal against a second in-process owner over an arbitrary MindStore stays a recorded follow-up. lib.rs's crate doc now names Mind::open as the owner of "may this store be this instance's mind". F3: R5 is not binary. Two loosenings are pinned as R5b and R5c in mind.rs, with behavioural fixtures: a foreign type with no epoch record at all still refuses MissingIdentity, not ForeignStore (R5b); an epoch record at the current key with a foreign value, beside a foreign type, still refuses ForeignEpoch, not ForeignStore (R5c). F5: gate step numbering in mind.rs's doc comment and its test comments now read 2 (epoch), 3 (type), matching the code's actual order. docs.rs no longer credits resolutions_of/assignments_of with reading history, which RS-2 deleted. The two-door test in query.rs is renamed from a_ref_whose_kind_and_id_disagree_is_refused_by_both_doors to ..._by_view, since view is the only door left. Per the operator's ruling retiring the anchor-based mutation harness, this batch carries no .psd1 changes; the cut9/cut10/readside mutation files have uncommitted edits from the earlier pass (stale references to the old test names, and R3L's target) left for a later pass to fold in or drop. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-22 18:34:47 +02:00
//! The crate owns three decisions and nothing else. `Mind::open` owns "may
//! this store be this instance's mind": the opener refuses a foreign type, a
//! foreign epoch, a missing identity or a foreign identity before it attaches
//! anything, and takes the store's per-path lock first. `receipt::commit` owns "did a batch enter, whole, with a
Open a mind fail-closed over an owned redb store Cut 8, Huginn half, commit 1 of 4: the store port, the opener and the identity rules. `huginn-mind` gains its dependencies (`cultcache-rs` at Epiphany's pin `a0813c6`, `epiphany-pipeline` at `a65c6420`, the Epiphany half of this cut), `store.rs` with the one narrow `MindStore` trait that injects compare-and-swap, `mind.rs` with `Mind::open` and `open_with`, and `refusal.rs` with the organ's refusal vocabulary. The opener refuses in order and attaches nothing until every gate passes: a foreign type, a foreign epoch, a missing identity, an identity naming another instance. The path under the state root is derived from the slug; the `instance` document is the authority, so a store copied into another instance's directory is refused. The owned store's exclusive lock is the single-writer mechanism: a second `Mind::open` of the same path is `MindAlreadyOwned`. The receipt type and the two provenance shapes (`Faculty`, `PipelineProvenance`) land here rather than in the later commits because the opener registers the receipt's type id, and their only consumer is the receipt; the commit primitive itself is the next commit. `MindRefusal` carries a serde remote definition of the leaf's `PipelineRefusal`, which derives neither `Serialize` nor `JsonSchema` at the pinned rev; it is compiled against the leaf's type so a leaf change breaks the build rather than drifting. `Cargo.lock` is regenerated and gains 90 packages. The map predicted a CRLF-to-LF rewrite of the whole file; the file was already LF in the index and stays LF, so the diff is additions only. README and AGENTS now say `huginn-mind` is live and the other two crates are stubs. Builds: `cargo check -p huginn-mind --lib --tests` and `cargo test -p huginn-mind --lib` (4 tests) pass. This commit carries dead-code warnings on the store and cache accessors and the refusing test store; commits 2 and 3 consume them. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 17:04:23 +02:00
//! receipt": one compare-and-swap over the store, a receipt naming the exact
Admit a batch through one ordered path with every rule in it Cut 8, Huginn half, commit 3 of 4: `admission.rs`. `Mind::admit` prepares typed documents through the leaf and calls `admit_prepared`, the single commit path for this cut, Cut 10's sink, Cut 12's hand-off and import, and Cut 13's tools. The steps run in order and the first failing step is the outcome: the batch names this mind (A1), one to sixty-four envelopes (A2), the leaf's bounds, formats and key recomputation (A3), unique identities (A4), every instance-carrying document names this mind (A5), an empty mind's first batch carries exactly one `instance` document and a batch carrying one derives the epoch record (A6), every reference resolves in image or batch by `(kind, id)` (A7), the derived writes pass A3-A7 themselves, the per-kind rules and the resolution matrix (A8), an exact replay answers with the stored receipt only after validation (A9), no write collides with the image (A10), the commit (A11). Derived writes: a ruling that answers derives the `Answered` resolution of its question; a hand-off derives the stewardship withdrawal on its source side and the stewardship assignment on its receiving side. "In force" is computed at rule time from the resolutions in image and batch and never stored; the two derivations are the only resolutions a rule ignores when judging its own document. Two places the leaf is thinner than the spec assumed. `FindingWithoutRange` is unreachable: a finding envelope without `range` fails the leaf's decode as `Document(InvalidFormat { field: "payload" })` before any organ rule, and the test asserts that. A campaign with no repos has no refusal of its own in the spec's list; it is refused as `Document(FieldBound)` on `campaign.repos` with a minimum of one. `PipelineAdmissionBatch` cannot derive `JsonSchema` because the leaf's `PipelineDocument` does not; the outcome and refusal types do. The epoch record is derived whenever the batch carries the `instance` document, which only the first batch may, so a replay of the first batch digests to the same receipt and answers `AlreadyAdmitted` instead of colliding. Tests: 26 (the spec's 25 plus the replay-planting test, the receipt's deliberate second construction site). `cargo check -p huginn-mind --lib --tests` and `cargo test -p huginn-mind --lib` pass with zero warnings; `cargo check --workspace` passes. README says what the crate does now. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 17:13:44 +02:00
//! bytes read and written, and a typed conflict when the swap loses.
//! `Mind::admit_prepared` owns "may this batch enter": every cross-field and
//! cross-document rule, every derived write, and the replay check, in one
//! ordered path that `admit`, the daemon's sink and the hand-off all share.
Open a mind fail-closed over an owned redb store Cut 8, Huginn half, commit 1 of 4: the store port, the opener and the identity rules. `huginn-mind` gains its dependencies (`cultcache-rs` at Epiphany's pin `a0813c6`, `epiphany-pipeline` at `a65c6420`, the Epiphany half of this cut), `store.rs` with the one narrow `MindStore` trait that injects compare-and-swap, `mind.rs` with `Mind::open` and `open_with`, and `refusal.rs` with the organ's refusal vocabulary. The opener refuses in order and attaches nothing until every gate passes: a foreign type, a foreign epoch, a missing identity, an identity naming another instance. The path under the state root is derived from the slug; the `instance` document is the authority, so a store copied into another instance's directory is refused. The owned store's exclusive lock is the single-writer mechanism: a second `Mind::open` of the same path is `MindAlreadyOwned`. The receipt type and the two provenance shapes (`Faculty`, `PipelineProvenance`) land here rather than in the later commits because the opener registers the receipt's type id, and their only consumer is the receipt; the commit primitive itself is the next commit. `MindRefusal` carries a serde remote definition of the leaf's `PipelineRefusal`, which derives neither `Serialize` nor `JsonSchema` at the pinned rev; it is compiled against the leaf's type so a leaf change breaks the build rather than drifting. `Cargo.lock` is regenerated and gains 90 packages. The map predicted a CRLF-to-LF rewrite of the whole file; the file was already LF in the index and stays LF, so the diff is additions only. README and AGENTS now say `huginn-mind` is live and the other two crates are stubs. Builds: `cargo check -p huginn-mind --lib --tests` and `cargo test -p huginn-mind --lib` (4 tests) pass. This commit carries dead-code warnings on the store and cache accessors and the refusing test store; commits 2 and 3 consume them. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 17:04:23 +02:00
//!
//! The read side answers one typed selection (CultNet's, over rows this crate
//! supplies) from the mind's held image: a fold of the receipts, held by `Mind`,
//! advanced per commit, rebuilt on restart and on a lost swap. Status is derived
//! through the same `docs` the rules use; nothing is stored for it.
Read a mind: views, queries, open items and history `query.rs` is the read side, over a `&Mind<S>` with no store file, no daemon and no index. A `PipelineDocumentView` is four fields: the id, because a `PipelineDocument` does not carry its key and a client must never derive one; the document; the facts of its admission; and its status. The facts come from the commit receipts and from their `writes` alone, so a document a later batch cited as a strong read keeps the receipt that wrote it, and `admitted_at` is that receipt's `committed_at` -- the `now` admission was passed -- never the store's `stored_at`. A pipeline document the image holds and no receipt wrote is an integrity fault and refuses; the store has one writer and the receipt is its proof. Status is derived per call through `docs::Docs`, the same owner the admission rules ask, so a withdrawn resolution reopens its subject for a reader exactly when it reopens it for a rule. `closing_resolution` is `in_force_unless`'s own body asked for the resolution rather than the bool, so there is no second derivation to drift. Four reads: `view` by id, `query` over the filters (root, repo, cut, kinds, in force, faculty, an admission window), `open_items` for one campaign's unanswered questions, standing findings, follow-ups, unreported specs and unjudged reports, and `history` for every resolution a subject ever had or every assignment of a repo to this mind, withdrawn ones included with their reasons. A query is ordered by `(admitted_at, id)`, capped at 200, and carries `matched`, the count before the cap, so a truncation is never a short page that reads like the whole answer. `semantic` is accepted by the type and refused typed until Cut 11 owns the index; no substring filter lives here to become a second answer to "the text of a document". `cargo test -p huginn-mind --lib`: 56 passed, 0 failed, 0 warnings (46 + the ten tests). `cargo check --workspace` clean. No dependency, no target, no kind, no schema, no epoch; `Cargo.toml` and `Cargo.lock` untouched. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 21:22:41 +02:00
//!
//! The wire vocabulary and its operation envelope (`envelope`) are here too,
//! so the daemon and the client share one set
//! of types.
//!
//! Document shape, bounds, formats and keys are `eureka-pipeline`'s; the
Open a mind fail-closed over an owned redb store Cut 8, Huginn half, commit 1 of 4: the store port, the opener and the identity rules. `huginn-mind` gains its dependencies (`cultcache-rs` at Epiphany's pin `a0813c6`, `epiphany-pipeline` at `a65c6420`, the Epiphany half of this cut), `store.rs` with the one narrow `MindStore` trait that injects compare-and-swap, `mind.rs` with `Mind::open` and `open_with`, and `refusal.rs` with the organ's refusal vocabulary. The opener refuses in order and attaches nothing until every gate passes: a foreign type, a foreign epoch, a missing identity, an identity naming another instance. The path under the state root is derived from the slug; the `instance` document is the authority, so a store copied into another instance's directory is refused. The owned store's exclusive lock is the single-writer mechanism: a second `Mind::open` of the same path is `MindAlreadyOwned`. The receipt type and the two provenance shapes (`Faculty`, `PipelineProvenance`) land here rather than in the later commits because the opener registers the receipt's type id, and their only consumer is the receipt; the commit primitive itself is the next commit. `MindRefusal` carries a serde remote definition of the leaf's `PipelineRefusal`, which derives neither `Serialize` nor `JsonSchema` at the pinned rev; it is compiled against the leaf's type so a leaf change breaks the build rather than drifting. `Cargo.lock` is regenerated and gains 90 packages. The map predicted a CRLF-to-LF rewrite of the whole file; the file was already LF in the index and stays LF, so the diff is additions only. README and AGENTS now say `huginn-mind` is live and the other two crates are stubs. Builds: `cargo check -p huginn-mind --lib --tests` and `cargo test -p huginn-mind --lib` (4 tests) pass. This commit carries dead-code warnings on the store and cache accessors and the refusing test store; commits 2 and 3 consume them. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 17:04:23 +02:00
//! organ registers, prepares, decodes and validates through the leaf's four
//! doors and never re-derives a key. The store is CultLib's owned redb
//! CultCache, whose lifetime-long exclusive lock is the single-writer
//! invariant's mechanism. No function here reads a clock or the environment:
//! `now` is passed in.
Admit a batch through one ordered path with every rule in it Cut 8, Huginn half, commit 3 of 4: `admission.rs`. `Mind::admit` prepares typed documents through the leaf and calls `admit_prepared`, the single commit path for this cut, Cut 10's sink, Cut 12's hand-off and import, and Cut 13's tools. The steps run in order and the first failing step is the outcome: the batch names this mind (A1), one to sixty-four envelopes (A2), the leaf's bounds, formats and key recomputation (A3), unique identities (A4), every instance-carrying document names this mind (A5), an empty mind's first batch carries exactly one `instance` document and a batch carrying one derives the epoch record (A6), every reference resolves in image or batch by `(kind, id)` (A7), the derived writes pass A3-A7 themselves, the per-kind rules and the resolution matrix (A8), an exact replay answers with the stored receipt only after validation (A9), no write collides with the image (A10), the commit (A11). Derived writes: a ruling that answers derives the `Answered` resolution of its question; a hand-off derives the stewardship withdrawal on its source side and the stewardship assignment on its receiving side. "In force" is computed at rule time from the resolutions in image and batch and never stored; the two derivations are the only resolutions a rule ignores when judging its own document. Two places the leaf is thinner than the spec assumed. `FindingWithoutRange` is unreachable: a finding envelope without `range` fails the leaf's decode as `Document(InvalidFormat { field: "payload" })` before any organ rule, and the test asserts that. A campaign with no repos has no refusal of its own in the spec's list; it is refused as `Document(FieldBound)` on `campaign.repos` with a minimum of one. `PipelineAdmissionBatch` cannot derive `JsonSchema` because the leaf's `PipelineDocument` does not; the outcome and refusal types do. The epoch record is derived whenever the batch carries the `instance` document, which only the first batch may, so a replay of the first batch digests to the same receipt and answers `AlreadyAdmitted` instead of colliding. Tests: 26 (the spec's 25 plus the replay-planting test, the receipt's deliberate second construction site). `cargo check -p huginn-mind --lib --tests` and `cargo test -p huginn-mind --lib` pass with zero warnings; `cargo check --workspace` passes. README says what the crate does now. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 17:13:44 +02:00
pub mod admission;
mod desk;
pub mod desk_wire;
mod docs;
mod image;
pub mod envelope;
pub mod import;
pub mod index;
Open a mind fail-closed over an owned redb store Cut 8, Huginn half, commit 1 of 4: the store port, the opener and the identity rules. `huginn-mind` gains its dependencies (`cultcache-rs` at Epiphany's pin `a0813c6`, `epiphany-pipeline` at `a65c6420`, the Epiphany half of this cut), `store.rs` with the one narrow `MindStore` trait that injects compare-and-swap, `mind.rs` with `Mind::open` and `open_with`, and `refusal.rs` with the organ's refusal vocabulary. The opener refuses in order and attaches nothing until every gate passes: a foreign type, a foreign epoch, a missing identity, an identity naming another instance. The path under the state root is derived from the slug; the `instance` document is the authority, so a store copied into another instance's directory is refused. The owned store's exclusive lock is the single-writer mechanism: a second `Mind::open` of the same path is `MindAlreadyOwned`. The receipt type and the two provenance shapes (`Faculty`, `PipelineProvenance`) land here rather than in the later commits because the opener registers the receipt's type id, and their only consumer is the receipt; the commit primitive itself is the next commit. `MindRefusal` carries a serde remote definition of the leaf's `PipelineRefusal`, which derives neither `Serialize` nor `JsonSchema` at the pinned rev; it is compiled against the leaf's type so a leaf change breaks the build rather than drifting. `Cargo.lock` is regenerated and gains 90 packages. The map predicted a CRLF-to-LF rewrite of the whole file; the file was already LF in the index and stays LF, so the diff is additions only. README and AGENTS now say `huginn-mind` is live and the other two crates are stubs. Builds: `cargo check -p huginn-mind --lib --tests` and `cargo test -p huginn-mind --lib` (4 tests) pass. This commit carries dead-code warnings on the store and cache accessors and the refusing test store; commits 2 and 3 consume them. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 17:04:23 +02:00
pub mod mind;
pub mod persona;
mod rows;
#[cfg(any(test, feature = "test-support"))]
pub mod oracle;
Read a mind: views, queries, open items and history `query.rs` is the read side, over a `&Mind<S>` with no store file, no daemon and no index. A `PipelineDocumentView` is four fields: the id, because a `PipelineDocument` does not carry its key and a client must never derive one; the document; the facts of its admission; and its status. The facts come from the commit receipts and from their `writes` alone, so a document a later batch cited as a strong read keeps the receipt that wrote it, and `admitted_at` is that receipt's `committed_at` -- the `now` admission was passed -- never the store's `stored_at`. A pipeline document the image holds and no receipt wrote is an integrity fault and refuses; the store has one writer and the receipt is its proof. Status is derived per call through `docs::Docs`, the same owner the admission rules ask, so a withdrawn resolution reopens its subject for a reader exactly when it reopens it for a rule. `closing_resolution` is `in_force_unless`'s own body asked for the resolution rather than the bool, so there is no second derivation to drift. Four reads: `view` by id, `query` over the filters (root, repo, cut, kinds, in force, faculty, an admission window), `open_items` for one campaign's unanswered questions, standing findings, follow-ups, unreported specs and unjudged reports, and `history` for every resolution a subject ever had or every assignment of a repo to this mind, withdrawn ones included with their reasons. A query is ordered by `(admitted_at, id)`, capped at 200, and carries `matched`, the count before the cap, so a truncation is never a short page that reads like the whole answer. `semantic` is accepted by the type and refused typed until Cut 11 owns the index; no substring filter lives here to become a second answer to "the text of a document". `cargo test -p huginn-mind --lib`: 56 passed, 0 failed, 0 warnings (46 + the ten tests). `cargo check --workspace` clean. No dependency, no target, no kind, no schema, no epoch; `Cargo.toml` and `Cargo.lock` untouched. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 21:22:41 +02:00
pub mod query;
Open a mind fail-closed over an owned redb store Cut 8, Huginn half, commit 1 of 4: the store port, the opener and the identity rules. `huginn-mind` gains its dependencies (`cultcache-rs` at Epiphany's pin `a0813c6`, `epiphany-pipeline` at `a65c6420`, the Epiphany half of this cut), `store.rs` with the one narrow `MindStore` trait that injects compare-and-swap, `mind.rs` with `Mind::open` and `open_with`, and `refusal.rs` with the organ's refusal vocabulary. The opener refuses in order and attaches nothing until every gate passes: a foreign type, a foreign epoch, a missing identity, an identity naming another instance. The path under the state root is derived from the slug; the `instance` document is the authority, so a store copied into another instance's directory is refused. The owned store's exclusive lock is the single-writer mechanism: a second `Mind::open` of the same path is `MindAlreadyOwned`. The receipt type and the two provenance shapes (`Faculty`, `PipelineProvenance`) land here rather than in the later commits because the opener registers the receipt's type id, and their only consumer is the receipt; the commit primitive itself is the next commit. `MindRefusal` carries a serde remote definition of the leaf's `PipelineRefusal`, which derives neither `Serialize` nor `JsonSchema` at the pinned rev; it is compiled against the leaf's type so a leaf change breaks the build rather than drifting. `Cargo.lock` is regenerated and gains 90 packages. The map predicted a CRLF-to-LF rewrite of the whole file; the file was already LF in the index and stays LF, so the diff is additions only. README and AGENTS now say `huginn-mind` is live and the other two crates are stubs. Builds: `cargo check -p huginn-mind --lib --tests` and `cargo test -p huginn-mind --lib` (4 tests) pass. This commit carries dead-code warnings on the store and cache accessors and the refusing test store; commits 2 and 3 consume them. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 17:04:23 +02:00
pub mod receipt;
pub mod redact;
Open a mind fail-closed over an owned redb store Cut 8, Huginn half, commit 1 of 4: the store port, the opener and the identity rules. `huginn-mind` gains its dependencies (`cultcache-rs` at Epiphany's pin `a0813c6`, `epiphany-pipeline` at `a65c6420`, the Epiphany half of this cut), `store.rs` with the one narrow `MindStore` trait that injects compare-and-swap, `mind.rs` with `Mind::open` and `open_with`, and `refusal.rs` with the organ's refusal vocabulary. The opener refuses in order and attaches nothing until every gate passes: a foreign type, a foreign epoch, a missing identity, an identity naming another instance. The path under the state root is derived from the slug; the `instance` document is the authority, so a store copied into another instance's directory is refused. The owned store's exclusive lock is the single-writer mechanism: a second `Mind::open` of the same path is `MindAlreadyOwned`. The receipt type and the two provenance shapes (`Faculty`, `PipelineProvenance`) land here rather than in the later commits because the opener registers the receipt's type id, and their only consumer is the receipt; the commit primitive itself is the next commit. `MindRefusal` carries a serde remote definition of the leaf's `PipelineRefusal`, which derives neither `Serialize` nor `JsonSchema` at the pinned rev; it is compiled against the leaf's type so a leaf change breaks the build rather than drifting. `Cargo.lock` is regenerated and gains 90 packages. The map predicted a CRLF-to-LF rewrite of the whole file; the file was already LF in the index and stays LF, so the diff is additions only. README and AGENTS now say `huginn-mind` is live and the other two crates are stubs. Builds: `cargo check -p huginn-mind --lib --tests` and `cargo test -p huginn-mind --lib` (4 tests) pass. This commit carries dead-code warnings on the store and cache accessors and the refusing test store; commits 2 and 3 consume them. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 17:04:23 +02:00
pub mod refusal;
pub mod store;
pub mod wire;
Open a mind fail-closed over an owned redb store Cut 8, Huginn half, commit 1 of 4: the store port, the opener and the identity rules. `huginn-mind` gains its dependencies (`cultcache-rs` at Epiphany's pin `a0813c6`, `epiphany-pipeline` at `a65c6420`, the Epiphany half of this cut), `store.rs` with the one narrow `MindStore` trait that injects compare-and-swap, `mind.rs` with `Mind::open` and `open_with`, and `refusal.rs` with the organ's refusal vocabulary. The opener refuses in order and attaches nothing until every gate passes: a foreign type, a foreign epoch, a missing identity, an identity naming another instance. The path under the state root is derived from the slug; the `instance` document is the authority, so a store copied into another instance's directory is refused. The owned store's exclusive lock is the single-writer mechanism: a second `Mind::open` of the same path is `MindAlreadyOwned`. The receipt type and the two provenance shapes (`Faculty`, `PipelineProvenance`) land here rather than in the later commits because the opener registers the receipt's type id, and their only consumer is the receipt; the commit primitive itself is the next commit. `MindRefusal` carries a serde remote definition of the leaf's `PipelineRefusal`, which derives neither `Serialize` nor `JsonSchema` at the pinned rev; it is compiled against the leaf's type so a leaf change breaks the build rather than drifting. `Cargo.lock` is regenerated and gains 90 packages. The map predicted a CRLF-to-LF rewrite of the whole file; the file was already LF in the index and stays LF, so the diff is additions only. README and AGENTS now say `huginn-mind` is live and the other two crates are stubs. Builds: `cargo check -p huginn-mind --lib --tests` and `cargo test -p huginn-mind --lib` (4 tests) pass. This commit carries dead-code warnings on the store and cache accessors and the refusing test store; commits 2 and 3 consume them. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 17:04:23 +02:00
#[cfg(test)]
pub(crate) mod fixtures;
#[cfg(test)]
mod read_tests;
#[cfg(test)]
mod move_tests;
pub use desk::{DeskAnswerOutcome, DeskAnswerRequest, DeskBody, options_hash};
pub use desk_wire::{DeskRequest, DeskResponse, ForkAnswer, ForkAnswerCode, ForkAnswerRequest, ForkDeskAnswer, ForkRefusal, ForkRefusalCode};
pub use docs::CitationRole;
pub use index::{INDEX_TEXT_MAX_BYTES, INDEX_TEXT_VERSION, IndexEntry, index_text};
Admit a batch through one ordered path with every rule in it Cut 8, Huginn half, commit 3 of 4: `admission.rs`. `Mind::admit` prepares typed documents through the leaf and calls `admit_prepared`, the single commit path for this cut, Cut 10's sink, Cut 12's hand-off and import, and Cut 13's tools. The steps run in order and the first failing step is the outcome: the batch names this mind (A1), one to sixty-four envelopes (A2), the leaf's bounds, formats and key recomputation (A3), unique identities (A4), every instance-carrying document names this mind (A5), an empty mind's first batch carries exactly one `instance` document and a batch carrying one derives the epoch record (A6), every reference resolves in image or batch by `(kind, id)` (A7), the derived writes pass A3-A7 themselves, the per-kind rules and the resolution matrix (A8), an exact replay answers with the stored receipt only after validation (A9), no write collides with the image (A10), the commit (A11). Derived writes: a ruling that answers derives the `Answered` resolution of its question; a hand-off derives the stewardship withdrawal on its source side and the stewardship assignment on its receiving side. "In force" is computed at rule time from the resolutions in image and batch and never stored; the two derivations are the only resolutions a rule ignores when judging its own document. Two places the leaf is thinner than the spec assumed. `FindingWithoutRange` is unreachable: a finding envelope without `range` fails the leaf's decode as `Document(InvalidFormat { field: "payload" })` before any organ rule, and the test asserts that. A campaign with no repos has no refusal of its own in the spec's list; it is refused as `Document(FieldBound)` on `campaign.repos` with a minimum of one. `PipelineAdmissionBatch` cannot derive `JsonSchema` because the leaf's `PipelineDocument` does not; the outcome and refusal types do. The epoch record is derived whenever the batch carries the `instance` document, which only the first batch may, so a replay of the first batch digests to the same receipt and answers `AlreadyAdmitted` instead of colliding. Tests: 26 (the spec's 25 plus the replay-planting test, the receipt's deliberate second construction site). `cargo check -p huginn-mind --lib --tests` and `cargo test -p huginn-mind --lib` pass with zero warnings; `cargo check --workspace` passes. README says what the crate does now. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 17:13:44 +02:00
pub use admission::{BATCH_MAX, PipelineAdmissionBatch, PipelineAdmissionOutcome};
pub use import::{ImportBatch, ImportFault, ImportPlan, inert_in_window, plan};
Fourth fix batch: fill N1 in its owner, and correct two ledger claims N1 (medium-low). Moves the epiphany-pipeline pin to the leaf's new commit (9d3a3efd), which opens Slug::validate_slug. Huginn's own cultcache-rs pin is untouched; cargo tree -d still carries exactly one cultcache-rs. Mind::require_instance now validates the declared name's grammar before comparing identity, so admission's A1 and every read refuse a bad name identically, through one door. Mind::open and open_with validate the declared instance before path_for ever runs, so a Slug carrying `..` and a path separator (Soul's outer/inner probe) is refused before any store is created, not after it has already escaped the state root. require_grammatical_instance and its daemon-side branch in daemon.rs are deleted: the throwaway PipelineInstance wrapper it built is no longer the only door onto the leaf's grammar. The refusal now names the field a caller actually held the declared name under (declared, or instance) and the whole declared name, not the old wrapper's instance.instance field or a single failing label. Adds a leaf-escape regression test pinning Soul's probe and asserting no store is created, and a fullwidth-instance test showing Admit and Query refuse identically. Updates the cut10 grammar-fold mutant (S3wide) to the new function shape and the affected daemon test to the new field name. N5 and N6, prose only. The cut10 entries gain a note by S1 and S1d: neither mutant "dies on all three" faults its shared fixture carries, contrary to an earlier claim; S1d exempts the orphan fault by construction and is killed by the undecodable-document block instead, the next one the test body reaches. The cut9 header's self-contradiction at lines 18-25 is resolved (nothing in the suite exercises the door, not "nothing reaches it"), its self-reference now points at store.rs:18-19, and its line-1 range is corrected to V1-V24L. All three suites rerun clean after the pin move: cut8 67/67, cut9 38/38, cut10 65/65, every M0 green, restores hash-verified. cargo test --workspace: huginn-mind 61/61 (was 60), huginn-daemon 18/18 (was 17). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-22 05:14:34 +02:00
pub use mind::{HuginnMindEpoch, Mind};
pub use persona::{PersonaPutOutcome, PersonaStateView};
Read a mind: views, queries, open items and history `query.rs` is the read side, over a `&Mind<S>` with no store file, no daemon and no index. A `PipelineDocumentView` is four fields: the id, because a `PipelineDocument` does not carry its key and a client must never derive one; the document; the facts of its admission; and its status. The facts come from the commit receipts and from their `writes` alone, so a document a later batch cited as a strong read keeps the receipt that wrote it, and `admitted_at` is that receipt's `committed_at` -- the `now` admission was passed -- never the store's `stored_at`. A pipeline document the image holds and no receipt wrote is an integrity fault and refuses; the store has one writer and the receipt is its proof. Status is derived per call through `docs::Docs`, the same owner the admission rules ask, so a withdrawn resolution reopens its subject for a reader exactly when it reopens it for a rule. `closing_resolution` is `in_force_unless`'s own body asked for the resolution rather than the bool, so there is no second derivation to drift. Four reads: `view` by id, `query` over the filters (root, repo, cut, kinds, in force, faculty, an admission window), `open_items` for one campaign's unanswered questions, standing findings, follow-ups, unreported specs and unjudged reports, and `history` for every resolution a subject ever had or every assignment of a repo to this mind, withdrawn ones included with their reasons. A query is ordered by `(admitted_at, id)`, capped at 200, and carries `matched`, the count before the cap, so a truncation is never a short page that reads like the whole answer. `semantic` is accepted by the type and refused typed until Cut 11 owns the index; no substring filter lives here to become a second answer to "the text of a document". `cargo test -p huginn-mind --lib`: 56 passed, 0 failed, 0 warnings (46 + the ten tests). `cargo check --workspace` clean. No dependency, no target, no kind, no schema, no epoch; `Cargo.toml` and `Cargo.lock` untouched. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 21:22:41 +02:00
pub use query::{
AdmissionFacts, PipelineDocumentSummary, PipelineDocumentView, PipelineEdge, PipelineFacts, PipelinePageItems,
Members, PipelineSelectionPage, PipelineStatus, PipelineStatusSummary, Ranked, RootTouched, SUMMARY_MAX_BYTES, SemanticQuery,
Read a mind: views, queries, open items and history `query.rs` is the read side, over a `&Mind<S>` with no store file, no daemon and no index. A `PipelineDocumentView` is four fields: the id, because a `PipelineDocument` does not carry its key and a client must never derive one; the document; the facts of its admission; and its status. The facts come from the commit receipts and from their `writes` alone, so a document a later batch cited as a strong read keeps the receipt that wrote it, and `admitted_at` is that receipt's `committed_at` -- the `now` admission was passed -- never the store's `stored_at`. A pipeline document the image holds and no receipt wrote is an integrity fault and refuses; the store has one writer and the receipt is its proof. Status is derived per call through `docs::Docs`, the same owner the admission rules ask, so a withdrawn resolution reopens its subject for a reader exactly when it reopens it for a rule. `closing_resolution` is `in_force_unless`'s own body asked for the resolution rather than the bool, so there is no second derivation to drift. Four reads: `view` by id, `query` over the filters (root, repo, cut, kinds, in force, faculty, an admission window), `open_items` for one campaign's unanswered questions, standing findings, follow-ups, unreported specs and unjudged reports, and `history` for every resolution a subject ever had or every assignment of a repo to this mind, withdrawn ones included with their reasons. A query is ordered by `(admitted_at, id)`, capped at 200, and carries `matched`, the count before the cap, so a truncation is never a short page that reads like the whole answer. `semantic` is accepted by the type and refused typed until Cut 11 owns the index; no substring filter lives here to become a second answer to "the text of a document". `cargo test -p huginn-mind --lib`: 56 passed, 0 failed, 0 warnings (46 + the ten tests). `cargo check --workspace` clean. No dependency, no target, no kind, no schema, no epoch; `Cargo.toml` and `Cargo.lock` untouched. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-16 21:22:41 +02:00
};
pub use receipt::{DocumentVersion, Faculty, HuginnCommitReceipt, IMPORT_EXTERNAL_MAX, ImportSource, PipelineProvenance, RECEIPT_SCHEMA_VERSION};
pub use refusal::{MindRefusal, RunId};
pub use store::{MindStore, OwnedRedbMessagePackBackingStore};
pub use wire::{
DeferredAnswer, HuginnMindRequest, HuginnMindResponse, IndexStatus, MAX_DEFERRED_BODY_BYTES, MIND_REQUEST_SCHEMA, MIND_REQUEST_SCHEMA_JSON,
MIND_RESPONSE_SCHEMA, MIND_RESPONSE_SCHEMA_JSON, MIND_SERVICE_ID, MindStatus, PersonaStatus,
ACTIVITY_REPOS_MAX, CHAT_ROOMS_MAX, CHAT_WINDOW_MAX, ChatHit, ChatHits, ChatMessage, ChatQuery, ChatWindow, ChatWindowQuery, EVENT_ID_MAX, OpenPr, PrAction, RepoActivity, RepoChange, RepoEvent, RepoMoved, SOURCE_TEXTS_MAX, SOURCE_TOP_K_MAX, SourceHit, SourceHits, SourceModel, SourceQuery,
};
/// The leaf, whole, through the one crate that pins its rev: the daemon and
/// the client name `Slug`, `PipelineRef` and the document types from here, so
/// one `[dependencies]` entry decides which revision the workspace speaks.
pub use eureka_pipeline;