aien-sovereign-core-mv
AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
Brought by drakestapleton
aien-sovereign-core-mv / crates / aien-allen-profile / src / refusal.rs
| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | |
| 16 | //! Every way a profile operation can say no, in plain words. |
| 17 | use std::fmt; |
| 18 | |
| 19 | #[derive(Debug, Clone, PartialEq, Eq)] |
| 20 | pub enum ProfileRefusal { |
| 21 | /// ALLEN is not engaged on this machine: there is no identity to attach a profile to. |
| 22 | NotEngaged, |
| 23 | /// `expected` revision differs from the current one (or another writer won the race). |
| 24 | StaleUpdate { |
| 25 | expected: u64, |
| 26 | current: u64, |
| 27 | }, |
| 28 | /// A stored revision names another agent or root than the engaged identity. |
| 29 | ForeignProfile(String), |
| 30 | /// A stored file is damaged, has an unknown schema/field, is oversize, or breaks the chain. |
| 31 | Damaged(String), |
| 32 | /// A requested value is not allowed. |
| 33 | Invalid(String), |
| 34 | /// Permissions are not profile fields. |
| 35 | PermissionKey(String), |
| 36 | /// The change would leave the profile exactly as it is. |
| 37 | NothingToChange, |
| 38 | /// `revert --to N` names a revision that does not exist. |
| 39 | UnknownRevision(u64), |
| 40 | /// Reset or revert with no profile yet. |
| 41 | NoProfile, |
| 42 | Io(String), |
| 43 | /// Test seam only (feature `fault-injection`): the write was stopped on purpose. |
| 44 | Crashed(String), |
| 45 | } |
| 46 | |
| 47 | impl ProfileRefusal { |
| 48 | /// Short stable code for scripts. |
| 49 | pub fn code(&self) -> &'static str { |
| 50 | use ProfileRefusal::*; |
| 51 | match self { |
| 52 | NotEngaged => "not_engaged", |
| 53 | StaleUpdate { .. } => "stale_update", |
| 54 | ForeignProfile(_) => "foreign_profile", |
| 55 | Damaged(_) => "damaged", |
| 56 | Invalid(_) => "invalid", |
| 57 | PermissionKey(_) => "permission_key", |
| 58 | NothingToChange => "nothing_to_change", |
| 59 | UnknownRevision(_) => "unknown_revision", |
| 60 | NoProfile => "no_profile", |
| 61 | Io(_) => "io", |
| 62 | Crashed(_) => "crashed", |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | impl fmt::Display for ProfileRefusal { |
| 68 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 69 | use ProfileRefusal::*; |
| 70 | match self { |
| 71 | NotEngaged => write!( |
| 72 | f, |
| 73 | "ALLEN is not engaged on this machine, so there is no identity to attach a profile to. Nothing was changed." |
| 74 | ), |
| 75 | StaleUpdate { expected, current } => write!( |
| 76 | f, |
| 77 | "The profile is at revision {current}, not {expected}. Someone or something changed it since you looked. Show it again, then retry with --expect {current}. Nothing was changed." |
| 78 | ), |
| 79 | ForeignProfile(w) => write!( |
| 80 | f, |
| 81 | "The saved profile belongs to a different ALLEN identity ({w}). It was not used or changed." |
| 82 | ), |
| 83 | Damaged(w) => write!( |
| 84 | f, |
| 85 | "The saved profile is damaged or not understood ({w}). It was not replaced; ask the operator to inspect the profile folder." |
| 86 | ), |
| 87 | Invalid(w) => write!(f, "Not allowed: {w}. Nothing was changed."), |
| 88 | PermissionKey(k) => write!( |
| 89 | f, |
| 90 | "Not allowed: \"{k}\" looks like a permission. Permissions are not profile fields; approvals go through the approval desk. Nothing was changed." |
| 91 | ), |
| 92 | NothingToChange => write!(f, "That would leave the profile exactly as it is. Nothing was changed."), |
| 93 | UnknownRevision(n) => write!(f, "There is no revision {n} in this profile's history. Nothing was changed."), |
| 94 | NoProfile => write!(f, "No profile has been saved yet, so there is nothing to revert or reset. Nothing was changed."), |
| 95 | Io(w) => write!(f, "Could not read or write the profile store: {w}. Nothing was changed."), |
| 96 | Crashed(w) => write!(f, "write stopped on purpose (test): {w}"), |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | impl std::error::Error for ProfileRefusal {} |