Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .codegraph/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# CodeGraph data files — local to each machine, not for committing.
# Ignore everything in .codegraph/ except this file itself, so transient
# files (the database, daemon.pid, sockets, logs) never show up in git.
*
!.gitignore
1 change: 1 addition & 0 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ boundaries above remain the target modular MSA architecture.
| `tepp_simulation` | known-truth temporal/event data generation |
| `validation_core` | RMSE, bias, coverage, graph, and Monte Carlo metrics |
| `tepp_api` | versioned DTO, schema, and export contracts |
| `corpus_background` | corpus-background wording is not unique latent content and not stopword deletion |

No crate exposes placeholder production behavior in Task 1. This prevents an
empty façade from becoming a de facto public API before its invariants and tests
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to TEPP are documented here. The format follows Keep a Chang

### Added

- `corpus_background` identity gate: corpus-level background wording is not unique latent content and is not erased by a stopword list; recovered background kinds match known truth at a higher computed rate than collapsing every token to unique content (ADR 0004/0012).
- `tepp_api` naruon live loopback HTTP/1.1 listener: `serve_one` installs a read/write deadline, requires a loopback `Host`, refuses `Transfer-Encoding` and NIM/proxy credential headers, parses `knowledge_cutoff` as RFC 3339 and refuses a future cutoff, keys analysis-run idempotency by tenant plus key, and proves both analysis-run and export POSTs over a real `TcpStream`. Not a production TLS/`$PORT` service (ADR 0011).
- `tepp_api` adaptive orchestration router (ADR 0010): versioned `direct`/`verify`/`committee`/`conductor`/`abstain` selection from CPU `f64` risk, ambiguity, evidence, and token-budget inputs; recorded stages, recursion, decomposition, access lists, and role-specific reasoning effort; fail-closed document-controlled policy/access/credentials; LLM plans remain proposals under deterministic statistical authority; comparable-budget ablation requires a direct baseline; credential-free contextual-orchestrator binding. Live NIM HTTP remains accepted-target.
- `tepp_api` purpose-bound provider-payload minimization: time-bounded `PurposeGrant` evaluation, fail-closed expired/not-yet-valid/inverted/cross-tenant/impossible-calendar denial, semantic UTC calendar validation, refusal to copy identity mappings into model-provider payloads or ordinary logs, preservation of opaque analytical identifiers and membership roles (no blanket PII mask), a separately authorized scientific re-identification path, and an internally bound FIPS 180-4 SHA-256 audit digest appended through `ReidentificationAuditSink` before disclosure.
Expand Down
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ members = [
"crates/tepp_simulation",
"crates/validation_core",
"crates/tepp_api",
"crates/corpus_background",
]
default-members = [
"crates/evidence_core",
Expand All @@ -23,6 +24,7 @@ default-members = [
"crates/tepp_simulation",
"crates/validation_core",
"crates/tepp_api",
"crates/corpus_background",
]

[workspace.package]
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ implemented in Rust.
## Current implementation state

This branch establishes the Task 1 Rust workspace and quality-gate foundation.
The ten bounded crates compile independently but intentionally expose no
The eleven bounded crates compile independently but intentionally expose no
placeholder production APIs. Domain behavior begins in Task 2 with immutable
evidence identifiers and source records.

Expand All @@ -22,6 +22,7 @@ crates/corpus_split
crates/tepp_simulation
crates/validation_core
crates/tepp_api
crates/corpus_background
```

## Local verification
Expand Down
17 changes: 17 additions & 0 deletions crates/corpus_background/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "corpus_background"
description = "Corpus-background wording is not unique content and not stopword deletion."
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
authors.workspace = true
repository.workspace = true
homepage.workspace = true
readme.workspace = true
keywords.workspace = true
categories.workspace = true
publish = false

[lints]
workspace = true
57 changes: 57 additions & 0 deletions crates/corpus_background/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//! Fail-closed corpus-background errors.

use std::fmt;

/// A fail-closed corpus-background error.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[non_exhaustive]
pub enum CorpusBackgroundError {
/// Corpus-background wording was treated as unique latent content.
CorpusBackgroundIsNotUniqueContent,
/// Corpus-background wording was treated as stopword deletion.
CorpusBackgroundIsNotStopwordDeletion,
/// A recovery slice was empty or length-mismatched.
InvalidCorpusBackgroundPayload,
}

impl fmt::Display for CorpusBackgroundError {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
let message = match self {
Self::CorpusBackgroundIsNotUniqueContent => {
"corpus-background wording is not unique latent content"
}
Self::CorpusBackgroundIsNotStopwordDeletion => {
"corpus-background wording is not stopword deletion"
}
Self::InvalidCorpusBackgroundPayload => "invalid corpus-background payload",
};
formatter.write_str(message)
}
}

impl std::error::Error for CorpusBackgroundError {}

#[cfg(test)]
mod tests {
use super::CorpusBackgroundError;

#[test]
fn error_messages_are_stable() {
for (error, message) in [
(
CorpusBackgroundError::CorpusBackgroundIsNotUniqueContent,
"corpus-background wording is not unique latent content",
),
(
CorpusBackgroundError::CorpusBackgroundIsNotStopwordDeletion,
"corpus-background wording is not stopword deletion",
),
(
CorpusBackgroundError::InvalidCorpusBackgroundPayload,
"invalid corpus-background payload",
),
] {
assert_eq!(error.to_string(), message);
}
}
}
145 changes: 145 additions & 0 deletions crates/corpus_background/src/kind.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
//! Corpus-background wording versus unique latent content.

use crate::CorpusBackgroundError;

/// Closed vocabulary of corpus-background token treatments.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum CorpusBackgroundKind {
/// Corpus-level background language, not unique document meaning.
CorpusBackground,
/// Token treatment reserved for unique latent content.
UniqueContent,
}

impl CorpusBackgroundKind {
/// Return the stable wire kind name.
#[must_use]
pub const fn wire_name(self) -> &'static str {
match self {
Self::CorpusBackground => "corpus_background",
Self::UniqueContent => "unique_content",
}
}

/// Parse a stable wire kind name.
///
/// # Errors
///
/// Returns [`CorpusBackgroundError::InvalidCorpusBackgroundPayload`] for
/// unrecognized names.
pub fn from_wire_name(name: &str) -> Result<Self, CorpusBackgroundError> {
match name {
"corpus_background" => Ok(Self::CorpusBackground),
"unique_content" => Ok(Self::UniqueContent),
_ => Err(CorpusBackgroundError::InvalidCorpusBackgroundPayload),
}
}
}

/// Refuse to treat corpus-background wording as unique latent content.
///
/// # Errors
///
/// Returns [`CorpusBackgroundError::CorpusBackgroundIsNotUniqueContent`] when
/// `kind` is [`CorpusBackgroundKind::CorpusBackground`].
pub fn refuse_corpus_background_as_unique_content(
kind: CorpusBackgroundKind,
) -> Result<(), CorpusBackgroundError> {
match kind {
CorpusBackgroundKind::CorpusBackground => {
Err(CorpusBackgroundError::CorpusBackgroundIsNotUniqueContent)
}
CorpusBackgroundKind::UniqueContent => Ok(()),
}
}

/// Refuse to treat corpus-background wording as stopword deletion.
///
/// # Errors
///
/// Returns [`CorpusBackgroundError::CorpusBackgroundIsNotStopwordDeletion`]
/// when `kind` is [`CorpusBackgroundKind::CorpusBackground`].
pub fn refuse_corpus_background_as_stopword_deletion(
kind: CorpusBackgroundKind,
) -> Result<(), CorpusBackgroundError> {
match kind {
CorpusBackgroundKind::CorpusBackground => {
Err(CorpusBackgroundError::CorpusBackgroundIsNotStopwordDeletion)
}
CorpusBackgroundKind::UniqueContent => Ok(()),
}
}

/// Fraction of recovered corpus-background kinds that match known truth.
///
/// # Errors
///
/// Returns [`CorpusBackgroundError::InvalidCorpusBackgroundPayload`] when
/// either slice is empty or the lengths differ.
pub fn identity_recovery_rate(
truth: &[CorpusBackgroundKind],
decided: &[CorpusBackgroundKind],
) -> Result<f64, CorpusBackgroundError> {
if truth.is_empty() || truth.len() != decided.len() {
return Err(CorpusBackgroundError::InvalidCorpusBackgroundPayload);
}
let mut matches = 0_u32;
for (truth_kind, decided_kind) in truth.iter().zip(decided) {
if truth_kind == decided_kind {
matches += 1;
}
}
Ok(f64::from(matches) / truth.len() as f64)
}

#[cfg(test)]
mod tests {
use super::{
CorpusBackgroundKind, identity_recovery_rate,
refuse_corpus_background_as_stopword_deletion, refuse_corpus_background_as_unique_content,
};
use crate::CorpusBackgroundError;

#[test]
fn local_branches_cover_kinds_payloads_and_wire_names() {
assert_eq!(
refuse_corpus_background_as_unique_content(CorpusBackgroundKind::CorpusBackground),
Err(CorpusBackgroundError::CorpusBackgroundIsNotUniqueContent)
);
assert_eq!(
refuse_corpus_background_as_stopword_deletion(CorpusBackgroundKind::CorpusBackground),
Err(CorpusBackgroundError::CorpusBackgroundIsNotStopwordDeletion)
);
refuse_corpus_background_as_unique_content(CorpusBackgroundKind::UniqueContent)
.expect("unique");
refuse_corpus_background_as_stopword_deletion(CorpusBackgroundKind::UniqueContent)
.expect("unique");
for kind in [
CorpusBackgroundKind::CorpusBackground,
CorpusBackgroundKind::UniqueContent,
] {
assert_eq!(
CorpusBackgroundKind::from_wire_name(kind.wire_name()).expect("round-trip"),
kind
);
}
assert_eq!(
CorpusBackgroundKind::from_wire_name("stopword"),
Err(CorpusBackgroundError::InvalidCorpusBackgroundPayload)
);
let matched = identity_recovery_rate(
&[CorpusBackgroundKind::CorpusBackground],
&[CorpusBackgroundKind::CorpusBackground],
)
.expect("rate");
assert!((matched - 1.0).abs() < f64::EPSILON);
assert_eq!(
identity_recovery_rate(&[], &[]),
Err(CorpusBackgroundError::InvalidCorpusBackgroundPayload)
);
assert_eq!(
identity_recovery_rate(&[CorpusBackgroundKind::CorpusBackground], &[]),
Err(CorpusBackgroundError::InvalidCorpusBackgroundPayload)
);
}
}
22 changes: 22 additions & 0 deletions crates/corpus_background/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#![forbid(unsafe_code)]
#![deny(missing_docs)]
#![allow(clippy::cast_precision_loss)]
//! Corpus-background wording is not unique latent content.
//!
//! Corpus-level background language stays explicit method/background
//! structure. It is not unique document meaning and is not erased by a
//! stopword list (ADR 0004/0012).

mod error;
mod kind;

/// Fail-closed corpus-background errors.
pub use error::CorpusBackgroundError;
/// Closed vocabulary of corpus-background token treatments.
pub use kind::CorpusBackgroundKind;
/// Fraction of recovered corpus-background kinds that match known truth.
pub use kind::identity_recovery_rate;
/// Refuse to treat corpus-background wording as stopword deletion.
pub use kind::refuse_corpus_background_as_stopword_deletion;
/// Refuse to treat corpus-background wording as unique latent content.
pub use kind::refuse_corpus_background_as_unique_content;
72 changes: 72 additions & 0 deletions crates/corpus_background/tests/corpus_background_contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//! Corpus-background wording is not unique content and not stopword deletion.

use corpus_background::{
CorpusBackgroundError, CorpusBackgroundKind, identity_recovery_rate,
refuse_corpus_background_as_stopword_deletion, refuse_corpus_background_as_unique_content,
};

#[test]
fn corpus_background_cannot_become_unique_content_or_stopword_deletion() {
assert_eq!(
refuse_corpus_background_as_unique_content(CorpusBackgroundKind::CorpusBackground),
Err(CorpusBackgroundError::CorpusBackgroundIsNotUniqueContent)
);
assert_eq!(
refuse_corpus_background_as_stopword_deletion(CorpusBackgroundKind::CorpusBackground),
Err(CorpusBackgroundError::CorpusBackgroundIsNotStopwordDeletion)
);
refuse_corpus_background_as_unique_content(CorpusBackgroundKind::UniqueContent)
.expect("unique");
refuse_corpus_background_as_stopword_deletion(CorpusBackgroundKind::UniqueContent)
.expect("unique");
}

#[test]
fn recovered_kinds_match_known_truth_better_than_a_unique_content_collapse() {
let truth = [
CorpusBackgroundKind::CorpusBackground,
CorpusBackgroundKind::UniqueContent,
CorpusBackgroundKind::CorpusBackground,
];
let recovered = truth;
let collapsed = [
CorpusBackgroundKind::UniqueContent,
CorpusBackgroundKind::UniqueContent,
CorpusBackgroundKind::UniqueContent,
];
let recovered_rate = identity_recovery_rate(&truth, &recovered).expect("recovered");
let collapsed_rate = identity_recovery_rate(&truth, &collapsed).expect("collapsed");
let expected = {
let mut matches = 0_u32;
for (truth_kind, decided_kind) in truth.iter().zip(recovered.iter()) {
if truth_kind == decided_kind {
matches += 1;
}
}
f64::from(matches) / f64::from(u32::try_from(truth.len()).expect("len"))
};
assert!((recovered_rate - expected).abs() < f64::EPSILON);
assert!(recovered_rate > collapsed_rate);
}

#[test]
fn empty_or_mismatched_kind_payloads_fail_closed() {
assert_eq!(
identity_recovery_rate(&[], &[]),
Err(CorpusBackgroundError::InvalidCorpusBackgroundPayload)
);
assert_eq!(
identity_recovery_rate(&[CorpusBackgroundKind::CorpusBackground], &[]),
Err(CorpusBackgroundError::InvalidCorpusBackgroundPayload)
);
assert_eq!(
identity_recovery_rate(
&[
CorpusBackgroundKind::CorpusBackground,
CorpusBackgroundKind::UniqueContent
],
&[CorpusBackgroundKind::CorpusBackground]
),
Err(CorpusBackgroundError::InvalidCorpusBackgroundPayload)
);
}
7 changes: 7 additions & 0 deletions crates/corpus_background/tests/crate_contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! Integration contract for the `corpus_background` package identity.

#[test]
fn package_identity_is_stable() {
let observed = std::hint::black_box(env!("CARGO_PKG_NAME"));
assert_eq!(observed, "corpus_background");
}
Loading
Loading