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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
use clap::{Parser, Subcommand, ValueEnum};
use omega_cognitive_kernel::api::{ExternalOutcome, LoopBenchmarkScenario};
use omega_cognitive_kernel::config::LoopPreset;
use omega_cognitive_kernel::task::{
L2_GAIN_DEFAULT_EPISODES, L2_GAIN_DEFAULT_RUNS, L2_GAIN_DEFAULT_STEPS,
};
use std::path::PathBuf;
#[derive(Copy, Clone, Debug, ValueEnum)]
pub(crate) enum CliLoopBenchmarkScenario {
Steady,
Shift,
Noisy,
}
impl From<CliLoopBenchmarkScenario> for LoopBenchmarkScenario {
fn from(scenario: CliLoopBenchmarkScenario) -> Self {
match scenario {
CliLoopBenchmarkScenario::Steady => Self::Steady,
CliLoopBenchmarkScenario::Shift => Self::Shift,
CliLoopBenchmarkScenario::Noisy => Self::Noisy,
}
}
}
#[derive(Copy, Clone, Debug, ValueEnum)]
pub(crate) enum CliLoopPreset {
Deterministic,
HotPatcher,
MetaGuard,
FastAdapt,
SteadyPrior,
ControlPlane,
FullKernel,
}
impl From<CliLoopPreset> for LoopPreset {
fn from(preset: CliLoopPreset) -> Self {
match preset {
CliLoopPreset::Deterministic => Self::Deterministic,
CliLoopPreset::HotPatcher => Self::HotPatcher,
CliLoopPreset::MetaGuard => Self::MetaGuard,
CliLoopPreset::FastAdapt => Self::FastAdapt,
CliLoopPreset::SteadyPrior => Self::SteadyPrior,
CliLoopPreset::ControlPlane => Self::ControlPlane,
CliLoopPreset::FullKernel => Self::FullKernel,
}
}
}
#[derive(Copy, Clone, Debug, ValueEnum)]
pub(crate) enum CliExternalOutcome {
Improved,
Degraded,
Timeout,
}
impl From<CliExternalOutcome> for ExternalOutcome {
fn from(outcome: CliExternalOutcome) -> Self {
match outcome {
CliExternalOutcome::Improved => Self::AcceptedAndImproved,
CliExternalOutcome::Degraded => Self::Degraded,
CliExternalOutcome::Timeout => Self::TimeoutOrSkipped,
}
}
}
#[derive(Parser)]
#[command(
name = "omega-kernel",
version,
about = "Omega Cognitive Kernel — self-improving cognitive runtime (L0/L1/L2)"
)]
pub(crate) struct Cli {
/// Path to omega.toml (optional). Applied after open; --state overrides config state_path.
#[arg(long, global = true)]
pub(crate) config: Option<PathBuf>,
#[arg(long, global = true, conflicts_with = "store")]
pub(crate) state: Option<PathBuf>,
/// State store URI (default: file storage). Use `sqlite://<path>` with the sqlite feature.
/// Relative paths resolve from the current working directory; use `sqlite:///path` for absolute paths.
/// This replaces state_path from --config and cannot be combined with --state.
#[arg(long, global = true, value_name = "URI")]
pub(crate) store: Option<String>,
/// Closed-loop layer preset (deterministic, hot-patcher, meta-guard, fast-adapt, steady-prior, control-plane, full-kernel).
#[arg(long, global = true, value_enum)]
pub(crate) preset: Option<CliLoopPreset>,
#[command(subcommand)]
pub(crate) command: Commands,
}
#[derive(Subcommand)]
pub(crate) enum Commands {
Run {
#[arg(
long,
default_value = "maintain coherent self-model while acting in world"
)]
goal: String,
#[arg(long, default_value_t = 12)]
steps: u32,
#[arg(long)]
no_save: bool,
},
/// Print kernel status (human text or --json).
Status {
/// Emit KernelStatus as JSON (for scripts / HTTP shims).
#[arg(long)]
json: bool,
},
Reset {
#[arg(long)]
yes: bool,
},
Demo {
#[arg(long, default_value_t = 12)]
steps: u32,
},
/// Show audit trail (tail) or operator summary panel.
Audit {
#[arg(long, default_value_t = 20)]
tail: usize,
/// Print rollup panel instead of raw events.
#[arg(long)]
summary: bool,
},
/// Offline replay of trajectory.jsonl (no world re-execution).
Replay {
/// Explicit trajectory path; default is trajectory.jsonl beside --state.
#[arg(long)]
path: Option<PathBuf>,
#[arg(long, default_value_t = 20)]
tail: usize,
},
Checkpoints,
Checkpoint {
#[arg(long, default_value = "manual")]
label: String,
},
Rollback {
id: String,
},
Task {
#[arg(long, default_value_t = 6)]
episodes: u32,
#[arg(long, default_value_t = 4)]
steps: u32,
},
/// Compare identical seeded runs with L2 interventions disabled/enabled.
BenchmarkL2 {
/// stable, nonstationary, degraded, fixedpoint, regime_shift, or cyclic_shift
#[arg(long, default_value = "nonstationary")]
scenario: String,
#[arg(long, default_value_t = 5)]
runs: u32,
#[arg(long, default_value_t = 8)]
episodes: u32,
#[arg(long, default_value_t = 8)]
steps: u32,
#[arg(long, default_value_t = 20261115)]
seed: u64,
/// L2 commit score threshold used by the treatment arm.
#[arg(long)]
commit_threshold: Option<f64>,
/// Cooldown steps after a committed modulation.
#[arg(long)]
commit_cooldown: Option<u64>,
/// Consecutive negative rewards required for reward_change signal.
#[arg(long)]
negative_reward_required: Option<u32>,
/// Opt-in spectral experiment; default benchmark remains the baseline.
#[arg(long)]
spectral_control: bool,
#[arg(long, requires = "spectral_control")]
no_purity_prior: bool,
#[arg(long, requires = "spectral_control")]
no_reverse_brake: bool,
#[arg(long, requires = "spectral_control")]
no_history_discount: bool,
/// Include per-step diagnostics in each treatment run.
#[arg(long)]
diagnostics: bool,
/// Emit machine-readable JSON.
#[arg(long)]
json: bool,
},
/// Compare L0, L1-only, L2-only, and L1+L2 on the same seeded task.
BenchmarkL1l2 {
/// stable, nonstationary, degraded, fixedpoint, regime_shift, or cyclic_shift
#[arg(long, default_value = "regime_shift")]
scenario: String,
#[arg(long, default_value_t = 5)]
runs: u32,
#[arg(long, default_value_t = 8)]
episodes: u32,
#[arg(long, default_value_t = 8)]
steps: u32,
#[arg(long, default_value_t = 20261115)]
seed: u64,
#[arg(long)]
commit_threshold: Option<f64>,
#[arg(long)]
commit_cooldown: Option<u64>,
#[arg(long)]
negative_reward_required: Option<u32>,
/// Emit machine-readable JSON with all four per-seed reports.
#[arg(long)]
json: bool,
},
/// Run the fixed four-scenario, discovery/validation L2 gain matrix.
BenchmarkL2Gain {
/// Paired seeds per scenario; must be at least two for intervals.
#[arg(long, default_value_t = L2_GAIN_DEFAULT_RUNS)]
runs: u32,
#[arg(long, default_value_t = L2_GAIN_DEFAULT_EPISODES)]
episodes: u32,
#[arg(long, default_value_t = L2_GAIN_DEFAULT_STEPS)]
steps: u32,
/// Run a quick two-seed preflight; not effectiveness evidence.
#[arg(long, conflicts_with_all = ["runs", "episodes", "steps"])]
smoke: bool,
/// Emit all eight factorial reports and the preregistered assessment.
#[arg(long)]
json: bool,
},
/// Operator nudge: set strategy weight (0.1–10).
StrategyWeight {
/// Strategy name (e.g. observe, explore).
name: String,
/// New weight in [0.1, 10].
weight: f64,
},
/// Incremental audit poll (byte cursor). Prints new events and next offset.
AuditPoll {
/// Byte offset from a previous poll (0 = from start / resync).
#[arg(long, default_value_t = 0)]
offset: u64,
},
/// Run a single external-telemetry step for L0-off presets (hot-patcher, meta-guard, control-plane).
StepExternal {
/// Monotonically increasing step identifier.
#[arg(long, default_value_t = 1)]
step_id: u64,
/// Observed prediction or policy error.
#[arg(long)]
error: f64,
/// Observed action risk in [0, 1].
#[arg(long, default_value_t = 0.0)]
risk: f64,
/// Outcome of the previous directive, if any.
#[arg(long, value_enum)]
outcome: Option<CliExternalOutcome>,
/// Run L1 in shadow-only mode without mutating cooldown state.
#[arg(long)]
shadow: bool,
/// Emit ControlDirective as JSON.
#[arg(long)]
json: bool,
/// Do not persist updated external closed-loop state after stepping.
#[arg(long)]
no_save: bool,
},
/// Benchmark all 7 (L0, L1, L2) closed-loop presets under steady, shift, or noisy workloads.
BenchmarkLoops {
/// Workload scenario (steady, shift, noisy).
#[arg(long, value_enum, default_value_t = CliLoopBenchmarkScenario::Shift)]
scenario: CliLoopBenchmarkScenario,
/// Steps to execute per preset.
#[arg(long, default_value_t = 24)]
steps: u32,
/// Emit machine-readable JSON report.
#[arg(long)]
json: bool,
},
/// Benchmark true closed-loop multi-parameter adaptation (baseline vs L1 vs L1+L2).
BenchmarkClosedLoop {
/// Total steps per arm (default 150: steady -> drift -> noisy).
#[arg(long, default_value_t = 150)]
steps: u32,
/// Emit machine-readable JSON report.
#[arg(long)]
json: bool,
},
/// Run the preregistered Adaptive Kernel Protocol v1 Phase 3 Shadow vs Active evaluation.
AdaptiveEval {
/// Emit machine-readable JSON instead of a human-readable summary table.
#[arg(long)]
json: bool,
},
/// Inspect persisted Adaptive Kernel Protocol v1 state (confirmed policy, pending/reconciliation status).
AdaptiveStatus {
/// Emit machine-readable JSON instead of human-readable text.
#[arg(long)]
json: bool,
},
/// Generate a monotonic versioned recovery snapshot from persisted Adaptive Kernel Protocol v1 state.
AdaptiveRecover {
/// Optional target baseline parameters as a JSON object (defaults to current confirmed params).
#[arg(long)]
params_json: Option<String>,
/// Emit machine-readable JSON instead of human-readable text.
#[arg(long)]
json: bool,
},
/// Run a native JSON-RPC 2.0 MCP stdio guardrail server backed by file or SQLite persistence.
McpServe {
/// Guard mode: keep, shadow (default), or active.
#[arg(long, default_value = "shadow")]
mode: String,
/// Baseline policy parameters as a JSON object.
#[arg(
long,
default_value = r#"{"max_concurrency":4.0,"retry_backoff_ms":40.0}"#
)]
baseline_json: String,
/// Optional per-parameter safety bounds JSON object ({"param":{"min":...,"max":...,"max_step_delta":...}}).
#[arg(long)]
bounds_json: Option<String>,
},
}