kcode-k1-access-profile-values 0.1.0

Owned non-wire access profile values and principal resolution for K1
Documentation
# Access profile values

This library owns the non-wire authorization-profile values, their invariants, request-principal substitution, and resolved-profile evidence. It reexports the access identities `Authorizations`, `OwnerSubject`, `RequestPrincipal`, and `ViewerSubject`, and the groups identities `GroupId`, `ModelId`, `TxId`, and `UserId`.

## Public API

```rust
pub struct ProfileId(TxId);
pub enum ProfileOwner { RequestUser, User(UserId), Group(GroupId) }
pub enum ProfileViewer {
    RequestUser, RequestModel, User(UserId), Group(GroupId), Model(ModelId)
}
pub struct AuthorizationProfile;
pub enum ProfileSelection { BuiltIn, Saved(ProfileId), Inline(AuthorizationProfile) }
pub enum ProfileSource { BuiltIn, Saved(ProfileId), Inline }
pub struct ProfileRevision;
pub struct ResolvedProfile;

impl ProfileId { pub const fn new(TxId) -> Self; pub const fn txid(self) -> TxId; }
impl AuthorizationProfile {
    pub fn new(Vec<ProfileOwner>, Vec<ProfileViewer>) -> Result<Self, String>;
    pub fn owners(&self) -> &[ProfileOwner];
    pub fn viewers(&self) -> &[ProfileViewer];
    pub fn resolve(&self, RequestPrincipal) -> Result<Authorizations, String>;
}
impl ProfileRevision {
    pub const fn new(ProfileId, TxId) -> Self;
    pub const fn profile_id(&self) -> ProfileId;
    pub const fn txid(&self) -> TxId;
}
impl ResolvedProfile {
    pub fn new(Authorizations, ProfileSource, Option<ProfileRevision>)
        -> Result<Self, String>;
    pub fn authorizations(&self) -> &Authorizations;
    pub const fn source(&self) -> ProfileSource;
    pub const fn saved_revision(&self) -> Option<ProfileRevision>;
    pub fn into_authorizations(self) -> Authorizations;
}
pub fn built_in_profile() -> AuthorizationProfile;
pub fn resolve_built_in(RequestPrincipal) -> Result<ResolvedProfile, String>;
```

`ProfileId`, `ProfileOwner`, `ProfileViewer`, `ProfileSource`, and `ProfileRevision` implement `Copy`, `Clone`, `Debug`, `Eq`, `Hash`, `Ord`, `PartialEq`, and `PartialOrd`. `AuthorizationProfile`, `ProfileSelection`, and `ResolvedProfile` implement `Clone`, `Debug`, `Eq`, and `PartialEq`.

Construction rejects empty owners with `authorization profile requires at least one owner`, then sorts and deduplicates exact template subjects. Resolution substitutes request user/model values and delegates concrete normalization, deduplication, and owner-viewer overlap removal to `Authorizations::new`.

A saved source requires a revision for the same profile ID (`saved profile requires a revision` or `saved profile revision does not match profile ID`). Built-in and inline sources reject revisions with `only a saved profile may have a revision`. Revisions are evidence, not authority.

The built-in template is exactly owner `RequestUser` and viewer `Group(ALL_MODELS)`; resolution marks it built-in with no revision.

Construction and resolution perform `O(O log O + V log V)` normalization with allocations proportional to complete owned inputs and outputs. Accessors, fixed-size value construction, and fixed-size identifier comparisons are constant work; consuming a resolved profile transfers its owned authorizations without subject normalization. Operations are synchronous and have no shared state, I/O, persistence, authentication decision, codec, wire format, retry, timeout, callback, or background work. Allocation and scheduler latency have no finite wall-clock bound.