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 / spark-inquisitor / src / constitution.rs

256 lines · 10068 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
16use regex::Regex;
17use std::sync::OnceLock;
18
19static AWS_REGEX: OnceLock<Regex> = OnceLock::new();
20static GITHUB_PAT_REGEX: OnceLock<Regex> = OnceLock::new();
21static GITHUB_FINE_PAT_REGEX: OnceLock<Regex> = OnceLock::new();
22static PRIV_KEY_REGEX: OnceLock<Regex> = OnceLock::new();
23static DELVE_RE: OnceLock<Regex> = OnceLock::new();
24static TAPESTRY_RE: OnceLock<Regex> = OnceLock::new();
25static TESTAMENT_RE: OnceLock<Regex> = OnceLock::new();
26static CRUCIAL_RE: OnceLock<Regex> = OnceLock::new();
27static PIVOTAL_RE: OnceLock<Regex> = OnceLock::new();
28static ELEVATE_RE: OnceLock<Regex> = OnceLock::new();
29static GAME_CHANGER_RE: OnceLock<Regex> = OnceLock::new();
30static UNLEASH_RE: OnceLock<Regex> = OnceLock::new();
31static BEACON_TROPE_RE: OnceLock<Regex> = OnceLock::new();
32static HARNESS_VERB_RE: OnceLock<Regex> = OnceLock::new();
33static ANTITHESIS_NOT_ONLY_RE: OnceLock<Regex> = OnceLock::new();
34static ANTITHESIS_NOT_X_BUT_Y_RE: OnceLock<Regex> = OnceLock::new();
35
36#[derive(Debug, Clone, PartialEq, Eq)]
37pub enum ViolationKind {
38 Dash(String),
39 Buzzword(String),
40 AntithesisTrope(String),
41 Secret(String),
42 EnvFile(String),
43}
44
45pub struct ConstitutionalChecker;
46
47/// Shown in place of a line that holds a plaintext secret, so no finding (style,
48/// telemetry or secret) ever echoes the credential into a report or a log.
49pub const REDACTED_SECRET_LINE: &str = "[line redacted: it contains a plaintext secret]";
50
51impl ConstitutionalChecker {
52 fn aws_key(line: &str) -> bool {
53 AWS_REGEX
54 .get_or_init(|| Regex::new(r"\bAKIA[0-9A-Z]{16}\b").unwrap())
55 .is_match(line)
56 }
57
58 fn github_token(line: &str) -> bool {
59 let github_pat_regex =
60 GITHUB_PAT_REGEX.get_or_init(|| Regex::new(r"\bghp_[A-Za-z0-9]{36,}\b").unwrap());
61 let github_fine_pat_regex = GITHUB_FINE_PAT_REGEX
62 .get_or_init(|| Regex::new(r"\bgithub_pat_[A-Za-z0-9_]{50,}\b").unwrap());
63 github_pat_regex.is_match(line) || github_fine_pat_regex.is_match(line)
64 }
65
66 fn private_key(line: &str) -> bool {
67 PRIV_KEY_REGEX
68 .get_or_init(|| {
69 Regex::new(r"-----BEGIN (?:[A-Z0-9 ]+)?PRIVATE KEY-----|BEGIN RSA PRIVATE KEY")
70 .unwrap()
71 })
72 .is_match(line)
73 }
74
75 /// True when the line matches any plaintext secret pattern.
76 pub fn line_has_secret(line: &str) -> bool {
77 Self::aws_key(line) || Self::github_token(line) || Self::private_key(line)
78 }
79
80 /// The text a finding may quote for this line: the trimmed line, or a redaction
81 /// marker when the line holds a secret.
82 pub fn displayable(line: &str) -> &str {
83 if Self::line_has_secret(line) {
84 REDACTED_SECRET_LINE
85 } else {
86 line.trim()
87 }
88 }
89
90 pub fn check_line(line: &str, _file_path: &str) -> Vec<ViolationKind> {
91 let mut violations = Vec::new();
92 let shown = Self::displayable(line);
93
94 // 1. Dash detection: em dash (\u{2014}) and en dash (\u{2013})
95 if line.contains('\u{2014}') || line.contains('\u{2013}') {
96 violations.push(ViolationKind::Dash(format!(
97 "Em/En dash detected in line: {}",
98 shown
99 )));
100 }
101
102 let lower = line.to_lowercase();
103
104 // 2. Plaintext Secrets
105 // AWS Access Key ID: AKIA followed by 16 alphanumeric uppercase
106 if Self::aws_key(line) {
107 violations.push(ViolationKind::Secret(
108 "Plaintext AWS Access Key detected in line: [REDACTED_AWS_KEY]".to_string(),
109 ));
110 }
111
112 // GitHub Personal Access Tokens (ghp_... or github_pat_...)
113 if Self::github_token(line) {
114 violations.push(ViolationKind::Secret(
115 "Plaintext GitHub Personal Access Token detected in line: [REDACTED_GH_TOKEN]"
116 .to_string(),
117 ));
118 }
119
120 // Private Keys
121 if Self::private_key(line) {
122 violations.push(ViolationKind::Secret(
123 "Plaintext Private Key header detected in line: [REDACTED_PRIVATE_KEY]".to_string(),
124 ));
125 }
126
127 // 3. Banned AI Buzzwords & Tropes
128 // Delve
129 let delve_re = DELVE_RE.get_or_init(|| Regex::new(r"\bdelv(?:e|es|ed|ing)\b").unwrap());
130 if delve_re.is_match(&lower) {
131 violations.push(ViolationKind::Buzzword(format!(
132 "Forbidden AI buzzword 'delve' detected in line: {}",
133 shown
134 )));
135 }
136
137 // Tapestry
138 let tapestry_re = TAPESTRY_RE.get_or_init(|| Regex::new(r"\btapestr(?:y|ies)\b").unwrap());
139 if tapestry_re.is_match(&lower) {
140 violations.push(ViolationKind::Buzzword(format!(
141 "Forbidden AI buzzword 'tapestry' detected in line: {}",
142 shown
143 )));
144 }
145
146 // Testament
147 let testament_re = TESTAMENT_RE.get_or_init(|| Regex::new(r"\btestament\b").unwrap());
148 if testament_re.is_match(&lower) {
149 violations.push(ViolationKind::Buzzword(format!(
150 "Forbidden AI buzzword 'testament' detected in line: {}",
151 shown
152 )));
153 }
154
155 // Crucial
156 let crucial_re = CRUCIAL_RE.get_or_init(|| Regex::new(r"\bcrucial\b").unwrap());
157 if crucial_re.is_match(&lower) {
158 violations.push(ViolationKind::Buzzword(format!(
159 "Forbidden AI buzzword 'crucial' detected in line: {}",
160 shown
161 )));
162 }
163
164 // Pivotal
165 let pivotal_re = PIVOTAL_RE.get_or_init(|| Regex::new(r"\bpivotal\b").unwrap());
166 if pivotal_re.is_match(&lower) {
167 violations.push(ViolationKind::Buzzword(format!(
168 "Forbidden AI buzzword 'pivotal' detected in line: {}",
169 shown
170 )));
171 }
172
173 // Elevate (exclude CLI flags like --elevate or identifiers with hyphens/underscores)
174 let elevate_re =
175 ELEVATE_RE.get_or_init(|| Regex::new(r"\belevat(?:e|es|ed|ing)\b").unwrap());
176 if elevate_re.is_match(&lower)
177 && !lower.contains("--elevate")
178 && !lower.contains("elevate_")
179 {
180 violations.push(ViolationKind::Buzzword(format!(
181 "Forbidden AI buzzword 'elevate' detected in line: {}",
182 shown
183 )));
184 }
185
186 // Game-changer
187 let game_changer_re =
188 GAME_CHANGER_RE.get_or_init(|| Regex::new(r"\bgame[ -]?changer\b").unwrap());
189 if game_changer_re.is_match(&lower) {
190 violations.push(ViolationKind::Buzzword(format!(
191 "Forbidden AI buzzword 'game-changer' detected in line: {}",
192 shown
193 )));
194 }
195
196 // Unleash (exclude CLI flags like --unleash or --unleash-features or identifiers with hyphens/underscores)
197 let unleash_re =
198 UNLEASH_RE.get_or_init(|| Regex::new(r"\bunleash(?:es|ed|ing)?\b").unwrap());
199 if unleash_re.is_match(&lower)
200 && !lower.contains("--unleash")
201 && !lower.contains("unleash_")
202 {
203 violations.push(ViolationKind::Buzzword(format!(
204 "Forbidden AI buzzword 'unleash' detected in line: {}",
205 shown
206 )));
207 }
208
209 // Beacon: when used as trope
210 let beacon_trope_re = BEACON_TROPE_RE.get_or_init(|| {
211 Regex::new(
212 r"\b(?:(?:a|shining)\s+)?beacon\s+(?:of|for|in|to|that)\b|\bas\s+a\s+beacon\b",
213 )
214 .unwrap()
215 });
216 if beacon_trope_re.is_match(&lower) {
217 violations.push(ViolationKind::Buzzword(format!(
218 "Forbidden AI buzzword trope 'beacon' detected in line: {}",
219 shown
220 )));
221 }
222
223 // Harness (as verb)
224 let harness_verb_re = HARNESS_VERB_RE.get_or_init(|| Regex::new(r"\b(?:to|can|could|will|would|must|shall|should|may|might|let's|lets)\s+harness\b|\bharness(?:es|ed|ing)\s+(?:the|our|their|its|this|these|those|power|potential|all)\b|\bharnessing\b").unwrap());
225 if harness_verb_re.is_match(&lower) {
226 violations.push(ViolationKind::Buzzword(format!(
227 "Forbidden AI buzzword 'harness' (as verb) detected in line: {}",
228 shown
229 )));
230 }
231
232 // 4. Banned Antithesis Tropes:
233 let antithesis_not_only_re = ANTITHESIS_NOT_ONLY_RE
234 .get_or_init(|| Regex::new(r"\bnot\s+only\s+[^,;\n]+,\s*but\s+").unwrap());
235 let antithesis_not_x_but_y_re = ANTITHESIS_NOT_X_BUT_Y_RE.get_or_init(|| {
236 Regex::new(
237 r"\b(?:it(?:'s|\s+is)\s+)?not\s+([a-zA-Z0-9_\-]+),\s*but\s+([a-zA-Z0-9_\-]+)\b",
238 )
239 .unwrap()
240 });
241 if antithesis_not_only_re.is_match(&lower) || antithesis_not_x_but_y_re.is_match(&lower) {
242 violations.push(ViolationKind::AntithesisTrope(format!(
243 "Forbidden antithesis trope detected in line: {}",
244 shown
245 )));
246 }
247
248 violations
249 }
250
251 pub fn is_env_file(path: &str) -> bool {
252 let clean_path = path.trim().trim_matches('"').trim_matches('\'');
253 let filename = clean_path.split('/').next_back().unwrap_or(clean_path);
254 filename == ".env" || filename.starts_with(".env.")
255 }
256}