1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
use std::path::PathBuf;
use clap::{Args, CommandFactory, Parser, Subcommand};
#[derive(Debug, Parser)]
#[command(
name = "axiom",
about = "Axiom neural hypervisor runtime",
version,
disable_help_subcommand = true
)]
pub struct AxiomCli {
#[command(subcommand)]
pub command: Option<AxiomCommand>,
}
#[derive(Debug, Subcommand)]
pub enum AxiomCommand {
/// Scaffold ~/.axiom with config, logs, run state, and model cache paths.
Init(InitArgs),
/// Manage the background Neural VFS and swarm listener daemon.
Daemon {
#[command(subcommand)]
command: DaemonCommand,
},
/// Attach a directory to the running user-mode VFS hypervisor.
Mount {
/// Directory to mount into the hypervisor.
path: PathBuf,
},
/// Warm-start the persistent vibe memory by absorbing a codebase through TTT.
Prime {
/// Directory to crawl and absorb (defaults to the current directory).
#[arg(default_value = ".")]
path: PathBuf,
},
/// Measure compression: token savings + structural round-trip fidelity.
Bench {
/// Directory to crawl and measure (defaults to the current directory).
#[arg(default_value = ".")]
path: PathBuf,
},
/// Autonomy (Pillar 3): drive a failing verify command to green by chaining
/// environment self-healing and Poly JIT / LLM source repair, then
/// remembering what worked. With no --source, the faulty file is localized
/// automatically from the verify command's own output (works across Rust,
/// Python, JS/TS, Go, C/C++, …). `axiom solve [--source PATH] -- <cmd>`.
Solve {
/// Max environment-heal + source-repair rounds.
#[arg(long, default_value_t = 2)]
max_rounds: usize,
/// Restart budget for the environment supervisor each round.
#[arg(long, default_value_t = 3)]
max_restarts: usize,
/// Source file to repair (reversible). Optional: when omitted, the file
/// is auto-detected from the failure trace. Pass it to pin the target.
#[arg(long)]
source: Option<PathBuf>,
/// The verify command to drive to green, followed by its arguments.
/// Optional: with none, the project language is detected and a default
/// check is used (e.g. `cargo test`, `pytest`, `go test`).
#[arg(trailing_var_arg = true, num_args = 0..)]
command: Vec<String>,
},
/// Agentic Core: goal-directed autonomous coding. Drive a verify command to
/// green toward an objective, editing files under an all-or-nothing,
/// verifier-gated, reversible transaction loop (a rejected change is rolled
/// back byte-for-byte; identical failed changes are never retried). Repair is
/// the special case (omit --goal). `axiom task --goal "<desc>" [--file P]... -- <cmd>`.
Task {
/// What to accomplish, in natural language. Omit to mean "make the verify
/// command pass" (pure repair).
#[arg(long, default_value = "")]
goal: String,
/// A file the agent may edit (repeatable). With none, target files are
/// localized automatically from the verify command's failure output.
#[arg(long = "file")]
files: Vec<PathBuf>,
/// Max verifier-gated attempts.
#[arg(long, default_value_t = 4)]
max_attempts: usize,
/// The verify command that grounds acceptance, followed by its arguments.
#[arg(trailing_var_arg = true, required = true, num_args = 1..)]
command: Vec<String>,
},
/// Measure the autonomous loop's capability as a reproducible score: run the
/// built-in seeded broken-repo fixtures through the real solve loop and report
/// how many it repairs end-to-end (deterministic, no LLM required).
EvalAgentic {},
/// Run a program under self-healing supervision: failures are absorbed into
/// the TTT fast-weights, the environment is repaired (e.g. missing
/// directories created), and the program is restarted until it succeeds.
Run {
/// Restart budget after the first attempt.
#[arg(long, default_value_t = 3)]
max_restarts: usize,
/// Predict from learned immunity whether the command would fail now,
/// then exit WITHOUT running it (anticipatory pre-flight).
#[arg(long)]
dry_run: bool,
/// The command to supervise, followed by its arguments.
#[arg(trailing_var_arg = true, required = true, num_args = 1..)]
command: Vec<String>,
},
/// Manage DWE swarm peers.
Swarm {
#[command(subcommand)]
command: SwarmCommand,
},
/// Report what Axiom has learned about program failures (acquired immunity):
/// remembered heals, per-program failure-tension history, and confidence.
Immunity {
/// Optional case-insensitive command substring to filter by.
query: Option<String>,
/// Forget faded heals: drop records whose confidence has decayed below
/// the prune floor (memory waning → clonal deletion).
#[arg(long)]
prune: bool,
},
/// Run AXIOM's in-tree ChimeraLang (AI-cognition DSL): check, run, prove
/// (emit a signed certificate), or verify a certificate. `.chimera` programs
/// execute on the same belief/provenance substrate as the engine itself.
Chimera {
#[command(subcommand)]
command: ChimeraCommand,
},
}
#[derive(Debug, Subcommand)]
pub enum ChimeraCommand {
/// Lex + parse a `.chimera` file, reporting syntax errors (the verify gate).
Check {
/// Path to the `.chimera` source file.
file: PathBuf,
},
/// Execute a `.chimera` file and print emitted values + any guard violations.
Run {
/// Path to the `.chimera` source file.
file: PathBuf,
},
/// Execute and emit a tamper-evident certificate of the run (SHA-256, plus
/// HMAC when `AXIOM_FLEET_KEY` is set), reusing AXIOM's provenance layer.
Prove {
/// Path to the `.chimera` source file.
file: PathBuf,
/// Where to write the certificate JSON (defaults to stdout).
#[arg(long)]
out: Option<PathBuf>,
},
/// Verify a certificate produced by `prove`, offline.
Verify {
/// Path to the certificate JSON.
cert: PathBuf,
},
}
#[derive(Debug, Args, Default)]
pub struct InitArgs {
/// Skip automatic base-model download during initialization.
#[arg(long)]
pub no_fetch: bool,
/// Skip bootstrapping a local checkpoint. By default `init` trains a small
/// model locally (no network) when none exists, so the proxy never boots on
/// random weights.
#[arg(long)]
pub no_train: bool,
}
#[derive(Debug, Subcommand)]
pub enum DaemonCommand {
/// Start the Axiom hypervisor in the background.
Start,
/// Stop the background hypervisor if it is running.
Stop,
/// Print daemon PID, health, and log path.
Status,
}
#[derive(Debug, Subcommand)]
pub enum SwarmCommand {
/// Persist a DWE peer address in ~/.axiom/config.toml.
Connect {
/// Peer IP or host:port. Bare hosts default to port 9191.
ip: String,
},
/// Pull a peer's heal memory and merge it into this node's (swarm
/// immunity): heals learned anywhere in the fleet immunize this machine.
Immunity {
/// Peer Axiom server, host:port (the HTTP proxy port, e.g. 3000).
peer: String,
},
}
#[derive(Debug)]
pub enum ParsedCli {
Command(AxiomCommand),
HelpPrinted,
Legacy,
}
pub fn parse_entry() -> Result<ParsedCli, clap::Error> {
let argv: Vec<String> = std::env::args().collect();
if should_use_legacy_parser(&argv) {
return Ok(ParsedCli::Legacy);
}
if argv.len() == 1 {
AxiomCli::command().print_long_help()?;
println!();
return Ok(ParsedCli::HelpPrinted);
}
let cli = match AxiomCli::try_parse_from(argv) {
Ok(cli) => cli,
Err(err)
if matches!(
err.kind(),
clap::error::ErrorKind::DisplayHelp | clap::error::ErrorKind::DisplayVersion
) =>
{
let _ = err.print();
return Ok(ParsedCli::HelpPrinted);
}
Err(err) => return Err(err),
};
match cli.command {
Some(command) => Ok(ParsedCli::Command(command)),
None => {
AxiomCli::command().print_long_help()?;
println!();
Ok(ParsedCli::HelpPrinted)
}
}
}
fn should_use_legacy_parser(argv: &[String]) -> bool {
let Some(first) = argv.get(1).map(String::as_str) else {
return false;
};
matches!(
first,
"--mode"
| "--lsp"
| "--epochs"
| "--steps-per-epoch"
| "--batch-size"
| "--seq-len"
| "--max-new-tokens"
| "--checkpoint"
| "--tokenizer"
| "--context-api-url"
| "--context-api-key"
| "--max-context-tokens"
| "--host"
| "--port"
| "--device"
)
}
pub fn normalize_peer(input: &str) -> String {
let trimmed = input.trim();
if trimmed.is_empty() || trimmed.contains(':') {
trimmed.to_string()
} else {
format!("{trimmed}:9191")
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn legacy_mode_flags_stay_compatible() {
let argv = vec![
"axiom".to_string(),
"--mode".to_string(),
"server".to_string(),
];
assert!(should_use_legacy_parser(&argv));
}
#[test]
fn bare_swarm_peer_gets_default_port() {
assert_eq!(normalize_peer("10.0.0.2"), "10.0.0.2:9191");
assert_eq!(normalize_peer("10.0.0.2:9292"), "10.0.0.2:9292");
}
}