interplane.Get Omega
Read in your language

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

branch main Branches Tags History

aien-sovereign-core-mv / crates / aien-capability / src / effects.rs

91 lines · 3105 bytes Raw Blame History
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/// Operations a tool declares. A tool may set more than one bit.
17#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
18pub struct ToolEffects(u32);
19
20impl ToolEffects {
21 pub const PURE: Self = Self(0);
22 pub const READ_FILESYSTEM: Self = Self(1 << 0);
23 pub const READ_NETWORK: Self = Self(1 << 1);
24 pub const SPAWN_PROCESS: Self = Self(1 << 2);
25 pub const WORLD_MUTATION: Self = Self(1 << 3);
26 pub const LOCAL_EPHEMERAL: Self = Self(1 << 4);
27 pub const EXTERNAL_WRITE: Self = Self(1 << 5);
28 pub const EXTERNAL_IRREVERSIBLE: Self = Self(1 << 6);
29 pub const SECRET_BEARING: Self = Self(1 << 7);
30
31 pub const fn bits(self) -> u32 {
32 self.0
33 }
34
35 pub const fn intersects(self, other: Self) -> bool {
36 self.0 & other.0 != 0
37 }
38
39 pub const fn contains(self, other: Self) -> bool {
40 other.0 != 0 && self.0 & other.0 == other.0
41 }
42}
43
44impl std::ops::BitOr for ToolEffects {
45 type Output = Self;
46
47 fn bitor(self, rhs: Self) -> Self {
48 Self(self.0 | rhs.0)
49 }
50}
51
52/// Single routing class derived from the highest declared effect bit.
53#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
54pub enum EffectClass {
55 Pure,
56 ReadOnly,
57 LocalEphemeral,
58 WorldMutation,
59 ExternalWrite,
60 ExternalIrreversible,
61}
62
63const UNSAFE_FOR_SPECULATION: ToolEffects = ToolEffects(
64 ToolEffects::WORLD_MUTATION.0
65 | ToolEffects::EXTERNAL_WRITE.0
66 | ToolEffects::EXTERNAL_IRREVERSIBLE.0,
67);
68
69pub fn routing_class(effects: ToolEffects) -> EffectClass {
70 if effects.contains(ToolEffects::EXTERNAL_IRREVERSIBLE) {
71 EffectClass::ExternalIrreversible
72 } else if effects.contains(ToolEffects::EXTERNAL_WRITE) {
73 EffectClass::ExternalWrite
74 } else if effects.contains(ToolEffects::WORLD_MUTATION) {
75 EffectClass::WorldMutation
76 } else if effects.intersects(ToolEffects::SPAWN_PROCESS | ToolEffects::LOCAL_EPHEMERAL) {
77 EffectClass::LocalEphemeral
78 } else if effects.intersects(ToolEffects::READ_FILESYSTEM | ToolEffects::READ_NETWORK) {
79 EffectClass::ReadOnly
80 } else {
81 EffectClass::Pure
82 }
83}
84
85/// True when J-Space may request the call before a winning World exists.
86///
87/// `SECRET_BEARING` does not by itself make a call unsafe. The session owner
88/// materializes credentials. The branch receives the tool result.
89pub fn speculation_safe(effects: ToolEffects) -> bool {
90 !effects.intersects(UNSAFE_FOR_SPECULATION)
91}