aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / crates / allen-reflex / src / action.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 | //! The 15 decisions of the exam contract (`docs/native/pi5-8/orchestrator-exam/system_prompt.txt`). |
| 17 | //! The 12 verbs are exactly the card-script verbs of `native/kernel/core/agent_cmd.c`; |
| 18 | //! `none`, `clarify` and `refuse` are the three non-actions. |
| 19 | |
| 20 | /// One decision label. |
| 21 | #[derive(Clone, Copy, PartialEq, Eq, Debug, PartialOrd, Ord, Hash)] |
| 22 | #[repr(u8)] |
| 23 | pub enum Action { |
| 24 | Status = 0, |
| 25 | Help, |
| 26 | Evidence, |
| 27 | Recall, |
| 28 | Facts, |
| 29 | Remember, |
| 30 | Prefer, |
| 31 | Task, |
| 32 | Prompt, |
| 33 | Approve, |
| 34 | Deny, |
| 35 | Cancel, |
| 36 | None, |
| 37 | Clarify, |
| 38 | Refuse, |
| 39 | } |
| 40 | |
| 41 | /// Number of labels. |
| 42 | pub const N_LABELS: usize = 15; |
| 43 | |
| 44 | impl Action { |
| 45 | /// All labels in index order. |
| 46 | pub const ALL: [Action; N_LABELS] = [ |
| 47 | Action::Status, |
| 48 | Action::Help, |
| 49 | Action::Evidence, |
| 50 | Action::Recall, |
| 51 | Action::Facts, |
| 52 | Action::Remember, |
| 53 | Action::Prefer, |
| 54 | Action::Task, |
| 55 | Action::Prompt, |
| 56 | Action::Approve, |
| 57 | Action::Deny, |
| 58 | Action::Cancel, |
| 59 | Action::None, |
| 60 | Action::Clarify, |
| 61 | Action::Refuse, |
| 62 | ]; |
| 63 | |
| 64 | /// Index 0..15. |
| 65 | pub fn idx(self) -> usize { |
| 66 | self as usize |
| 67 | } |
| 68 | |
| 69 | /// Label from index (panics never: out of range maps to Clarify). |
| 70 | pub fn from_idx(i: usize) -> Action { |
| 71 | if i < N_LABELS { |
| 72 | Action::ALL[i] |
| 73 | } else { |
| 74 | Action::Clarify |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | /// The action name used in the JSON decision. |
| 79 | pub fn name(self) -> &'static str { |
| 80 | match self { |
| 81 | Action::Status => "status", |
| 82 | Action::Help => "help", |
| 83 | Action::Evidence => "evidence", |
| 84 | Action::Recall => "recall", |
| 85 | Action::Facts => "facts", |
| 86 | Action::Remember => "remember", |
| 87 | Action::Prefer => "prefer", |
| 88 | Action::Task => "task", |
| 89 | Action::Prompt => "prompt", |
| 90 | Action::Approve => "approve", |
| 91 | Action::Deny => "deny", |
| 92 | Action::Cancel => "cancel", |
| 93 | Action::None => "none", |
| 94 | Action::Clarify => "clarify", |
| 95 | Action::Refuse => "refuse", |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | /// Parse an action name (exact, lower case). |
| 100 | pub fn from_name(s: &str) -> Option<Action> { |
| 101 | Action::ALL.iter().copied().find(|a| a.name() == s) |
| 102 | } |
| 103 | |
| 104 | /// The four verbs that carry text (1..48 printable ASCII bytes). |
| 105 | pub fn has_text(self) -> bool { |
| 106 | matches!( |
| 107 | self, |
| 108 | Action::Remember | Action::Prefer | Action::Task | Action::Prompt |
| 109 | ) |
| 110 | } |
| 111 | |
| 112 | /// approve, deny and cancel need a pending task (lifecycle_fsm.c). |
| 113 | pub fn needs_pending(self) -> bool { |
| 114 | matches!(self, Action::Approve | Action::Deny | Action::Cancel) |
| 115 | } |
| 116 | |
| 117 | /// task and prompt create a pending item; approve, deny, cancel clear it. |
| 118 | pub fn creates_pending(self) -> bool { |
| 119 | matches!(self, Action::Task | Action::Prompt) |
| 120 | } |
| 121 | } |