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-crumbs / src / main.rs

255 lines · 8448 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 clap::{Parser, Subcommand};
17use spark_crumbs::local::{is_valid_agent_id, SHARED_CONSTANT_IDENTITIES};
18use spark_crumbs::{
19 add_crumb_whisper, dir_crumb_card, process_identity, record_crumb_action, seed_directory_tree,
20 sniff_crumb, AgentIdentity,
21};
22use std::path::PathBuf;
23use std::process::ExitCode;
24
25#[derive(Parser, Debug)]
26#[command(name = "spark-crumbs")]
27#[command(author = "AIEN <aien@aienos.com>")]
28#[command(version = "0.1.0")]
29#[command(
30 about = "High-speed native Rust distributed breadcrumb and agent scent engine for Sovereign SparkOS",
31 long_about = "High-speed native Rust distributed breadcrumb and agent scent engine for Sovereign SparkOS.\n\n\
32 .crumb.local holds advisory notes, not a claim; claims belong to the crumb tool.\n\
33 Without --agent the identity comes from AIEN_AGENT_ID, else\n\
34 <AIEN_AGENT_NAME or spark-crumbs>.<AIEN_SESSION_ID or HERMES_SESSION_ID>, else a\n\
35 generated per-process id. Identity variables are used verbatim: one that is\n\
36 set to a value with surrounding whitespace (or otherwise outside the agent\n\
37 pattern) is an error; one set to the empty string counts as unset.\n\
38 Exit 1 on any .crumb.local or identity error (show prints its card first).\n\
39 seed does not yet report a failure to write .crumb itself."
40)]
41struct Cli {
42 #[command(subcommand)]
43 command: Commands,
44}
45
46#[derive(Subcommand, Debug)]
47enum Commands {
48 /// Seed .crumb and .crumb.local in a directory or recursively across a repository
49 Seed {
50 #[arg(default_value = ".", help = "Root directory to seed")]
51 dir: PathBuf,
52
53 #[arg(short, long, help = "Recursively seed all subdirectories")]
54 recursive: bool,
55
56 #[arg(
57 short,
58 long,
59 help = "Agent ID creating the crumb (default: environment identity)"
60 )]
61 agent: Option<String>,
62
63 #[arg(short, long, help = "Initial whisper message to plant")]
64 whisper: Option<String>,
65 },
66
67 /// Sniff peer agent scent, recent history, and active whispers for a file or directory
68 Sniff {
69 #[arg(help = "Target file or directory path")]
70 path: PathBuf,
71
72 #[arg(short, long, help = "Current agent ID (default: environment identity)")]
73 agent: Option<String>,
74 },
75
76 /// Show rich topographic inspection card for a directory
77 Show {
78 #[arg(default_value = ".", help = "Target directory to inspect")]
79 dir: PathBuf,
80 },
81
82 /// Plant an inter-agent whisper message in a directory
83 Whisper {
84 #[arg(default_value = ".", help = "Target directory")]
85 dir: PathBuf,
86
87 #[arg(short, long, help = "Whisper message content")]
88 message: String,
89
90 #[arg(
91 short,
92 long,
93 help = "Agent ID whispering (default: environment identity)"
94 )]
95 agent: Option<String>,
96
97 #[arg(short, long, help = "Optional target file name")]
98 file: Option<String>,
99 },
100
101 /// Record an agent action vector in a directory crumb
102 Record {
103 #[arg(default_value = ".", help = "Target directory")]
104 dir: PathBuf,
105
106 #[arg(short, long, help = "Agent ID (default: environment identity)")]
107 agent: Option<String>,
108
109 #[arg(long, help = "Action type (e.g. edit, test, build, audit)")]
110 action: String,
111
112 #[arg(short, long, help = "Target artifact or file")]
113 target: String,
114
115 #[arg(short, long, help = "Operational intent")]
116 intent: String,
117
118 #[arg(short, long, help = "Vector description")]
119 vector: String,
120 },
121}
122
123/// `--agent` when given, else this process's identity from the environment.
124/// An explicit `--agent` keeps the process's session id and must itself be a
125/// valid, non-shared identity.
126fn identity(agent: Option<String>) -> Result<AgentIdentity, String> {
127 let resolved = process_identity("spark-crumbs").map_err(|e| e.to_string())?;
128 let Some(agent_id) = agent else {
129 return Ok(resolved);
130 };
131 if SHARED_CONSTANT_IDENTITIES.contains(&agent_id.as_str()) {
132 return Err(format!(
133 "--agent '{agent_id}' is a shared constant identity; use a per-worker id"
134 ));
135 }
136 if !is_valid_agent_id(&agent_id) {
137 return Err(format!(
138 "--agent '{agent_id}' does not match ^[A-Za-z0-9][A-Za-z0-9._@-]{{0,159}}$"
139 ));
140 }
141 Ok(AgentIdentity {
142 agent_id,
143 ..resolved
144 })
145}
146
147fn run(cli: Cli) -> Result<(), String> {
148 match cli.command {
149 Commands::Seed {
150 dir,
151 recursive,
152 agent,
153 whisper,
154 } => {
155 let who = identity(agent)?;
156 println!(
157 "Seeding directory crumbs at: {} (recursive: {})",
158 dir.display(),
159 recursive
160 );
161 let count = seed_directory_tree(&dir, recursive, &who.agent_id, whisper.as_deref())
162 .map_err(|e| e.to_string())?;
163 // The count is of directories visited: a failed durable .crumb
164 // write is not detected yet (see seed_directory_tree), so do not
165 // claim the crumbs were written.
166 println!(
167 "Visited {} directories; .crumb write failures are not reported.",
168 count
169 );
170 }
171 Commands::Sniff { path, agent } => {
172 let who = identity(agent)?;
173 match sniff_crumb(&path, &who.agent_id).map_err(|e| e.to_string())? {
174 Some(sniff) => println!("{}", sniff),
175 None => println!(
176 "No active peer scent or whispers detected on '{}'.",
177 path.display()
178 ),
179 }
180 }
181 Commands::Show { dir } => {
182 let (card, local_err) = dir_crumb_card(&dir);
183 println!("{}", card);
184 if let Some(e) = local_err {
185 return Err(e.to_string());
186 }
187 }
188 Commands::Whisper {
189 dir,
190 message,
191 agent,
192 file,
193 } => {
194 let who = identity(agent)?;
195 add_crumb_whisper(&dir, &who.agent_id, &message, file.as_deref())
196 .map_err(|e| e.to_string())?;
197 println!(
198 "Planted whisper from [{}] in {}: '{}'",
199 who.agent_id,
200 dir.display(),
201 message
202 );
203 }
204 Commands::Record {
205 dir,
206 agent,
207 action,
208 target,
209 intent,
210 vector,
211 } => {
212 let who = identity(agent)?;
213 record_crumb_action(
214 &dir,
215 &who.agent_id,
216 &who.session_id,
217 &action,
218 &target,
219 &intent,
220 &vector,
221 )
222 .map_err(|e| e.to_string())?;
223 println!(
224 "Recorded action '{}' on '{}' in {}.",
225 action,
226 target,
227 dir.display()
228 );
229 }
230 }
231 Ok(())
232}
233
234fn main() -> ExitCode {
235 match run(Cli::parse()) {
236 Ok(()) => ExitCode::SUCCESS,
237 Err(e) => {
238 eprintln!("spark-crumbs: error: {e}");
239 ExitCode::FAILURE
240 }
241 }
242}
243
244#[cfg(test)]
245mod tests {
246 use super::Cli;
247 use clap::CommandFactory;
248
249 #[test]
250 fn cli_definition_is_valid() {
251 // Every subcommand, including record, must build without a clap
252 // debug assertion (record once declared -a for both agent and action).
253 Cli::command().debug_assert();
254 }
255}