cueloop 0.4.0

A Rust CLI for managing AI agent loops with a structured JSON task queue
Documentation
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
//! Runner capabilities reporting.
//!
//! Purpose:
//! - Runner capabilities reporting.
//!
//! Responsibilities:
//! - Aggregate capability data from multiple sources.
//! - Format output as text or JSON.
//!
//! Not handled here:
//! - Binary detection (see detection.rs).
//! - CLI argument parsing (see cli/runner.rs).
//!
//! Usage:
//! - Used through the crate module tree or integration test harness.
//!
//! Invariants/Assumptions:
//! - Keep behavior aligned with CueLoop's canonical CLI, machine-contract, and queue semantics.

use serde::Serialize;

use crate::cli::runner::RunnerFormat;
use crate::contracts::Runner;
use crate::runner::default_model_for_runner;
use crate::runner::{BuiltInRunnerPlugin, RunnerPlugin};

use super::detection::check_runner_binary;

/// Complete capability report for a runner.
#[derive(Debug, Clone, Serialize)]
pub struct RunnerCapabilityReport {
    /// Runner identifier.
    pub runner: String,
    /// Human-readable runner name.
    pub name: String,
    /// Whether session resumption is supported.
    pub supports_session_resume: bool,
    /// Whether CueLoop must manage session IDs (e.g., Kimi).
    pub requires_managed_session_id: bool,
    /// Supported features.
    pub features: RunnerFeatures,
    /// Allowed models (None = arbitrary models allowed).
    pub allowed_models: Option<Vec<String>>,
    /// Default model for this runner.
    pub default_model: String,
    /// Binary status.
    pub binary: BinaryInfo,
}

#[derive(Debug, Clone, Serialize)]
pub struct RunnerFeatures {
    /// Reasoning effort control.
    pub reasoning_effort: bool,
    /// Sandbox mode control.
    pub sandbox: SandboxSupport,
    /// Runner-native plan mode support.
    pub plan_mode: bool,
    /// Verbose output control.
    pub verbose: bool,
    /// Approval mode control.
    pub approval_modes: Vec<String>,
}

#[derive(Debug, Clone, Serialize)]
pub struct SandboxSupport {
    pub supported: bool,
    pub modes: Vec<String>,
}

#[derive(Debug, Clone, Serialize)]
pub struct BinaryInfo {
    pub installed: bool,
    pub version: Option<String>,
    pub error: Option<String>,
}

#[derive(Debug, Clone)]
pub(crate) struct RunnerCatalogEntry {
    pub id: String,
    pub display_name: String,
    pub default_model: Option<String>,
    pub allowed_models: Vec<String>,
    pub reasoning_effort_supported: bool,
    pub supports_arbitrary_model: bool,
}

/// Get capabilities for a specific runner.
pub fn get_runner_capabilities(runner: &Runner, bin_name: &str) -> RunnerCapabilityReport {
    let plugin = runner_to_plugin(runner);
    let metadata = plugin.metadata();

    // Check binary status
    let binary_status = check_runner_binary(bin_name);
    let binary_info = BinaryInfo {
        installed: binary_status.installed,
        version: binary_status.version,
        error: binary_status.error,
    };

    // Get features based on runner type
    let features = get_runner_features(runner);

    // Get allowed models
    let allowed_models = get_allowed_models(runner);

    // Get default model
    let default_model = default_model_for_runner(runner);

    RunnerCapabilityReport {
        runner: runner.id().to_string(),
        name: metadata.name,
        supports_session_resume: metadata.supports_resume,
        requires_managed_session_id: plugin.requires_managed_session_id(),
        features,
        allowed_models,
        default_model: default_model.as_str().to_string(),
        binary: binary_info,
    }
}

pub(crate) fn built_in_runner_catalog() -> Vec<RunnerCatalogEntry> {
    built_in_runners()
        .into_iter()
        .map(|runner| {
            let metadata = runner_to_plugin(&runner).metadata();
            let allowed_models = get_allowed_models(&runner).unwrap_or_default();
            RunnerCatalogEntry {
                id: runner.id().to_string(),
                display_name: metadata.name,
                default_model: Some(default_model_for_runner(&runner).as_str().to_string()),
                allowed_models: allowed_models.clone(),
                reasoning_effort_supported: get_runner_features(&runner).reasoning_effort,
                supports_arbitrary_model: allowed_models.is_empty(),
            }
        })
        .collect()
}

fn built_in_runners() -> Vec<Runner> {
    vec![
        Runner::Claude,
        Runner::Codex,
        Runner::Opencode,
        Runner::Gemini,
        Runner::Cursor,
        Runner::Kimi,
        Runner::Pi,
    ]
}

fn runner_to_plugin(runner: &Runner) -> BuiltInRunnerPlugin {
    match runner {
        Runner::Codex => BuiltInRunnerPlugin::Codex,
        Runner::Opencode => BuiltInRunnerPlugin::Opencode,
        Runner::Gemini => BuiltInRunnerPlugin::Gemini,
        Runner::Claude => BuiltInRunnerPlugin::Claude,
        Runner::Kimi => BuiltInRunnerPlugin::Kimi,
        Runner::Pi => BuiltInRunnerPlugin::Pi,
        Runner::Cursor => BuiltInRunnerPlugin::Cursor,
        Runner::Plugin(_) => BuiltInRunnerPlugin::Claude, // Fallback
    }
}

pub(crate) fn get_runner_features(runner: &Runner) -> RunnerFeatures {
    match runner {
        Runner::Codex => RunnerFeatures {
            reasoning_effort: true,
            sandbox: SandboxSupport {
                supported: true,
                modes: vec!["default".into(), "enabled".into(), "disabled".into()],
            },
            plan_mode: false,
            verbose: false,
            approval_modes: vec!["config_file".into()], // Codex uses ~/.codex/config.json
        },
        Runner::Claude => RunnerFeatures {
            reasoning_effort: false,
            sandbox: SandboxSupport {
                supported: false,
                modes: vec![],
            },
            plan_mode: false,
            verbose: true,
            approval_modes: vec!["accept_edits".into(), "bypass_permissions".into()],
        },
        Runner::Gemini => RunnerFeatures {
            reasoning_effort: false,
            sandbox: SandboxSupport {
                supported: true,
                modes: vec!["default".into(), "enabled".into()],
            },
            plan_mode: false,
            verbose: false,
            approval_modes: vec!["yolo".into(), "auto_edit".into()],
        },
        Runner::Cursor => RunnerFeatures {
            reasoning_effort: false,
            sandbox: SandboxSupport {
                supported: true,
                modes: vec!["enabled".into(), "disabled".into()],
            },
            plan_mode: false,
            verbose: false,
            approval_modes: vec![],
        },
        Runner::Opencode => RunnerFeatures {
            reasoning_effort: false,
            sandbox: SandboxSupport {
                supported: false,
                modes: vec![],
            },
            plan_mode: false,
            verbose: false,
            approval_modes: vec![],
        },
        Runner::Kimi => RunnerFeatures {
            reasoning_effort: false,
            sandbox: SandboxSupport {
                supported: false,
                modes: vec![],
            },
            plan_mode: false,
            verbose: false,
            approval_modes: vec!["yolo".into()],
        },
        Runner::Pi => RunnerFeatures {
            reasoning_effort: true,
            sandbox: SandboxSupport {
                supported: true,
                modes: vec!["default".into(), "enabled".into()],
            },
            plan_mode: false,
            verbose: false,
            approval_modes: vec!["print".into()],
        },
        Runner::Plugin(_) => RunnerFeatures {
            reasoning_effort: false,
            sandbox: SandboxSupport {
                supported: false,
                modes: vec![],
            },
            plan_mode: false,
            verbose: false,
            approval_modes: vec![],
        },
    }
}

pub(crate) fn get_allowed_models(runner: &Runner) -> Option<Vec<String>> {
    match runner {
        Runner::Codex => Some(vec![
            "gpt-5.4".into(),
            "gpt-5.3-codex".into(),
            "gpt-5.3-codex-spark".into(),
            "gpt-5.3".into(),
        ]),
        _ => None, // All other runners support arbitrary models
    }
}

/// Handle the `cueloop runner capabilities` command.
pub fn handle_capabilities(runner_str: &str, format: RunnerFormat) -> anyhow::Result<()> {
    let runner: Runner = runner_str
        .parse()
        .map_err(|_| anyhow::anyhow!("unknown runner: {}", runner_str))?;

    let bin_name = get_bin_name(&runner);

    let report = get_runner_capabilities(&runner, &bin_name);

    match format {
        RunnerFormat::Text => print_capabilities_text(&report),
        RunnerFormat::Json => println!("{}", serde_json::to_string_pretty(&report)?),
    }

    Ok(())
}

fn get_bin_name(runner: &Runner) -> String {
    match runner {
        Runner::Codex => "codex".into(),
        Runner::Opencode => "opencode".into(),
        Runner::Gemini => "gemini".into(),
        Runner::Claude => "claude".into(),
        Runner::Cursor => "node".into(), // Cursor uses CueLoop's Node-based SDK bridge
        Runner::Kimi => "kimi".into(),
        Runner::Pi => "pi".into(),
        Runner::Plugin(id) => id.clone(),
    }
}

fn print_capabilities_text(report: &RunnerCapabilityReport) {
    println!("Runner: {} ({})", report.name, report.runner);
    println!();

    // Binary status
    println!("Binary:");
    if report.binary.installed {
        println!("  Status: installed");
        if let Some(ref v) = report.binary.version {
            println!("  Version: {}", v);
        }
    } else {
        println!("  Status: NOT INSTALLED");
        if let Some(ref e) = report.binary.error {
            println!("  Error: {}", e);
        }
    }
    println!();

    // Models
    println!("Models:");
    println!("  Default: {}", report.default_model);
    if let Some(ref models) = report.allowed_models {
        println!("  Allowed: {}", models.join(", "));
    } else {
        println!("  Allowed: (any model ID)");
    }
    println!();

    // Features
    println!("Features:");
    println!(
        "  Session resume: {}",
        if report.supports_session_resume {
            "yes"
        } else {
            "no"
        }
    );
    if report.requires_managed_session_id {
        println!("  Managed session ID: required (CueLoop supplies session ID)");
    }
    println!(
        "  Reasoning effort: {}",
        if report.features.reasoning_effort {
            "yes"
        } else {
            "no"
        }
    );
    println!(
        "  Plan mode: {}",
        if report.features.plan_mode {
            "yes"
        } else {
            "no"
        }
    );
    println!(
        "  Verbose output: {}",
        if report.features.verbose { "yes" } else { "no" }
    );

    // Sandbox
    if report.features.sandbox.supported {
        println!(
            "  Sandbox: {} (supported)",
            report.features.sandbox.modes.join(", ")
        );
    } else {
        println!("  Sandbox: not supported");
    }

    // Approval modes
    if !report.features.approval_modes.is_empty() {
        println!(
            "  Approval modes: {}",
            report.features.approval_modes.join(", ")
        );
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn codex_has_reasoning_effort_support() {
        let features = get_runner_features(&Runner::Codex);
        assert!(features.reasoning_effort);
        assert!(!features.plan_mode);
    }

    #[test]
    fn pi_has_reasoning_effort_support() {
        let features = get_runner_features(&Runner::Pi);
        assert!(features.reasoning_effort);
        assert!(!features.plan_mode);
    }

    #[test]
    fn cursor_sdk_does_not_expose_plan_mode() {
        let features = get_runner_features(&Runner::Cursor);
        assert!(!features.plan_mode);
        assert!(!features.reasoning_effort);
        assert!(features.approval_modes.is_empty());
    }

    #[test]
    fn codex_has_restricted_models() {
        let report = get_runner_capabilities(&Runner::Codex, "codex");
        assert!(report.allowed_models.is_some());
        let models = report.allowed_models.unwrap();
        assert!(models.contains(&"gpt-5.4".to_string()));
        assert!(models.contains(&"gpt-5.3-codex".to_string()));
        assert!(!models.contains(&"sonnet".to_string()));
    }

    #[test]
    fn claude_allows_arbitrary_models() {
        let report = get_runner_capabilities(&Runner::Claude, "claude");
        assert!(report.allowed_models.is_none());
    }

    #[test]
    fn kimi_requires_managed_session_id() {
        let report = get_runner_capabilities(&Runner::Kimi, "kimi");
        assert!(report.requires_managed_session_id);
    }
}