devboy-cli 0.28.0

Command-line interface for devboy-tools — `devboy` binary. Primary distribution is npm (@devboy-tools/cli); `cargo install devboy-cli` is the secondary channel.
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
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
use crate::doctor::{CheckResult, CheckStatus, DiagnosticCheck, DiagnosticContext};
use async_trait::async_trait;
use serde_json::json;

pub struct ConfigExistsCheck;
pub struct ConfigValidTomlCheck;
pub struct ActiveContextCheck;

#[async_trait]
impl DiagnosticCheck for ConfigExistsCheck {
    fn id(&self) -> &'static str {
        "config.exists"
    }

    fn name(&self) -> &'static str {
        "Config file exists"
    }

    fn category(&self) -> &'static str {
        "Configuration"
    }

    async fn run(&self, ctx: &DiagnosticContext) -> CheckResult {
        match &ctx.config_path {
            Some(path) if ctx.config_exists => CheckResult {
                id: self.id().to_string(),
                category: self.category().to_string(),
                name: self.name().to_string(),
                status: CheckStatus::Pass,
                message: format!("Config file found ({})", path.display()),
                details: ctx
                    .verbose
                    .then(|| json!({ "path": path, "source": ctx.config_source })),
                fix_command: None,
                fix_url: None,
            },
            Some(path) => CheckResult {
                id: self.id().to_string(),
                category: self.category().to_string(),
                name: self.name().to_string(),
                status: CheckStatus::Warning,
                message: format!("Config file missing ({})", path.display()),
                details: ctx
                    .verbose
                    .then(|| json!({ "path": path, "source": ctx.config_source })),
                fix_command: Some("devboy init".to_string()),
                fix_url: None,
            },
            None => CheckResult {
                id: self.id().to_string(),
                category: self.category().to_string(),
                name: self.name().to_string(),
                status: CheckStatus::Error,
                message: "Could not determine config file path".to_string(),
                details: ctx
                    .verbose
                    .then(|| json!({ "error": ctx.config_path_error })),
                fix_command: None,
                fix_url: None,
            },
        }
    }
}

#[async_trait]
impl DiagnosticCheck for ConfigValidTomlCheck {
    fn id(&self) -> &'static str {
        "config.valid_toml"
    }

    fn name(&self) -> &'static str {
        "Config file valid TOML"
    }

    fn category(&self) -> &'static str {
        "Configuration"
    }

    async fn run(&self, ctx: &DiagnosticContext) -> CheckResult {
        if !ctx.config_exists {
            return CheckResult {
                id: self.id().to_string(),
                category: self.category().to_string(),
                name: self.name().to_string(),
                status: CheckStatus::Skipped,
                message: "Skipped because no config file was found".to_string(),
                details: None,
                fix_command: None,
                fix_url: None,
            };
        }

        match (&ctx.config, &ctx.config_load_error) {
            (Some(_), _) => CheckResult {
                id: self.id().to_string(),
                category: self.category().to_string(),
                name: self.name().to_string(),
                status: CheckStatus::Pass,
                message: "Config file parsed successfully".to_string(),
                details: ctx.verbose.then(|| {
                    json!({
                        "path": ctx.config_path,
                        "source": ctx.config_source,
                    })
                }),
                fix_command: None,
                fix_url: None,
            },
            (_, Some(error)) => CheckResult {
                id: self.id().to_string(),
                category: self.category().to_string(),
                name: self.name().to_string(),
                status: CheckStatus::Error,
                message: format!("Config file is invalid: {error}"),
                details: ctx.verbose.then(|| json!({ "error": error })),
                fix_command: None,
                fix_url: None,
            },
            _ => CheckResult {
                id: self.id().to_string(),
                category: self.category().to_string(),
                name: self.name().to_string(),
                status: CheckStatus::Error,
                message: "Config file could not be loaded".to_string(),
                details: None,
                fix_command: None,
                fix_url: None,
            },
        }
    }
}

#[async_trait]
impl DiagnosticCheck for ActiveContextCheck {
    fn id(&self) -> &'static str {
        "config.active_context"
    }

    fn name(&self) -> &'static str {
        "Active context valid"
    }

    fn category(&self) -> &'static str {
        "Configuration"
    }

    async fn run(&self, ctx: &DiagnosticContext) -> CheckResult {
        let Some(config) = &ctx.config else {
            return CheckResult {
                id: self.id().to_string(),
                category: self.category().to_string(),
                name: self.name().to_string(),
                status: CheckStatus::Skipped,
                message: "Skipped because config could not be loaded".to_string(),
                details: None,
                fix_command: None,
                fix_url: None,
            };
        };

        match config.resolve_active_context_name() {
            Some(active) => CheckResult {
                id: self.id().to_string(),
                category: self.category().to_string(),
                name: self.name().to_string(),
                status: CheckStatus::Pass,
                message: format!("Active context: {active}"),
                details: ctx.verbose.then(|| {
                    json!({
                        "active_context": active,
                        "contexts": config.context_names(),
                    })
                }),
                fix_command: None,
                fix_url: None,
            },
            // Issue #229: a `[remote_config]`-only or
            // `[[proxy_mcp_servers]]` install is the supported "thin
            // client" mode — the actual tool surface is exposed by the
            // remote MCP server we proxy to. `DEVBOY_REMOTE_CONFIG_URL`
            // env var is also respected even when `[remote_config]` is
            // absent (see `devboy_core::remote_config::resolve_url`).
            // There are no local contexts by design; the generic "no
            // context" warning would otherwise loop the user into
            // re-running `devboy init`.
            None if devboy_core::remote_config::resolve_url(config).is_some()
                || !config.proxy_mcp_servers.is_empty() =>
            {
                let proxy_names: Vec<String> = config
                    .proxy_mcp_servers
                    .iter()
                    .map(|p| p.name.clone())
                    .collect();
                let resolved_url = devboy_core::remote_config::resolve_url(config);
                let redacted = resolved_url
                    .as_deref()
                    .map(devboy_core::remote_config::redact_url_for_display);
                let message = match (&redacted, proxy_names.is_empty()) {
                    (Some(url), _) => format!(
                        "Remote-config install detected; local contexts are not required (url: {url})"
                    ),
                    (None, false) => format!(
                        "Proxy MCP install detected; local contexts are not required (servers: {})",
                        proxy_names.join(", ")
                    ),
                    (None, true) => unreachable!("guarded by `if` arm"),
                };
                CheckResult {
                    id: self.id().to_string(),
                    category: self.category().to_string(),
                    name: self.name().to_string(),
                    status: CheckStatus::Pass,
                    message,
                    details: ctx.verbose.then(|| {
                        json!({
                            // Note: redacted (userinfo + query stripped) for
                            // safe display in `--verbose` output too.
                            "remote_config_url": redacted,
                            "proxy_mcp_servers": proxy_names,
                        })
                    }),
                    fix_command: None,
                    fix_url: None,
                }
            }
            None => CheckResult {
                id: self.id().to_string(),
                category: self.category().to_string(),
                name: self.name().to_string(),
                status: CheckStatus::Warning,
                message: "No active context could be resolved".to_string(),
                details: ctx.verbose.then(|| {
                    json!({
                        "active_context": config.active_context,
                        "contexts": config.context_names(),
                    })
                }),
                fix_command: Some("devboy init".to_string()),
                fix_url: None,
            },
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use devboy_core::{Config, ContextConfig, GitHubConfig};
    use devboy_storage::MemoryStore;
    use std::collections::BTreeMap;
    use std::path::PathBuf;
    use std::sync::Arc;

    fn test_context(
        config: Option<Config>,
        config_path: Option<PathBuf>,
        config_exists: bool,
        config_path_error: Option<&str>,
        config_load_error: Option<&str>,
        verbose: bool,
    ) -> DiagnosticContext {
        DiagnosticContext {
            config,
            config_path,
            config_exists,
            config_source: "test",
            config_path_error: config_path_error.map(ToString::to_string),
            config_load_error: config_load_error.map(ToString::to_string),
            credential_store: Arc::new(MemoryStore::new()),
            verbose,
        }
    }

    fn config_with_active_context() -> Config {
        let mut contexts = BTreeMap::new();
        contexts.insert(
            "workspace".to_string(),
            ContextConfig {
                github: Some(GitHubConfig {
                    owner: "owner".to_string(),
                    repo: "repo".to_string(),
                    base_url: None,
                }),
                ..Default::default()
            },
        );

        Config {
            contexts,
            active_context: Some("workspace".to_string()),
            ..Default::default()
        }
    }

    #[tokio::test]
    async fn config_exists_check_passes_when_file_exists() {
        let ctx = test_context(
            Some(Config::default()),
            Some(PathBuf::from("config.toml")),
            true,
            None,
            None,
            true,
        );

        let result = ConfigExistsCheck.run(&ctx).await;

        assert_eq!(result.status, CheckStatus::Pass);
        assert!(result.message.contains("Config file found"));
        assert_eq!(result.details.unwrap()["source"], "test");
    }

    #[tokio::test]
    async fn config_exists_check_errors_when_path_is_unknown() {
        let ctx = test_context(None, None, false, Some("no path"), None, true);

        let result = ConfigExistsCheck.run(&ctx).await;

        assert_eq!(result.status, CheckStatus::Error);
        assert_eq!(result.details.unwrap()["error"], "no path");
    }

    #[tokio::test]
    async fn config_valid_toml_check_skips_when_config_missing() {
        let ctx = test_context(
            None,
            Some(PathBuf::from("missing.toml")),
            false,
            None,
            None,
            false,
        );

        let result = ConfigValidTomlCheck.run(&ctx).await;

        assert_eq!(result.status, CheckStatus::Skipped);
        assert!(
            result
                .message
                .contains("Skipped because no config file was found")
        );
    }

    #[tokio::test]
    async fn config_valid_toml_check_passes_when_config_loaded() {
        let ctx = test_context(
            Some(Config::default()),
            Some(PathBuf::from("config.toml")),
            true,
            None,
            None,
            true,
        );

        let result = ConfigValidTomlCheck.run(&ctx).await;

        assert_eq!(result.status, CheckStatus::Pass);
        assert_eq!(result.details.unwrap()["source"], "test");
    }

    #[tokio::test]
    async fn config_valid_toml_check_errors_when_load_fails_without_parse_error() {
        let ctx = test_context(
            None,
            Some(PathBuf::from("config.toml")),
            true,
            None,
            None,
            false,
        );

        let result = ConfigValidTomlCheck.run(&ctx).await;

        assert_eq!(result.status, CheckStatus::Error);
        assert_eq!(result.message, "Config file could not be loaded");
    }

    #[tokio::test]
    async fn active_context_check_skips_when_config_missing() {
        let ctx = test_context(
            None,
            Some(PathBuf::from("config.toml")),
            true,
            None,
            None,
            false,
        );

        let result = ActiveContextCheck.run(&ctx).await;

        assert_eq!(result.status, CheckStatus::Skipped);
    }

    #[tokio::test]
    async fn active_context_check_warns_when_no_context_resolves() {
        let ctx = test_context(
            Some(Config::default()),
            Some(PathBuf::from("config.toml")),
            true,
            None,
            None,
            true,
        );

        let result = ActiveContextCheck.run(&ctx).await;

        assert_eq!(result.status, CheckStatus::Warning);
        assert_eq!(result.fix_command.as_deref(), Some("devboy init"));
        assert_eq!(
            result.details.unwrap()["contexts"]
                .as_array()
                .unwrap()
                .len(),
            0
        );
    }

    #[tokio::test]
    async fn active_context_check_passes_when_context_resolves() {
        let ctx = test_context(
            Some(config_with_active_context()),
            Some(PathBuf::from("config.toml")),
            true,
            None,
            None,
            true,
        );

        let result = ActiveContextCheck.run(&ctx).await;

        assert_eq!(result.status, CheckStatus::Pass);
        assert!(result.message.contains("workspace"));
        assert_eq!(result.details.unwrap()["active_context"], "workspace");
    }

    /// Issue #229: a `[remote_config]`-only install (the supported
    /// thin-client / proxy mode) must not warn about a missing context
    /// nor suggest re-running `devboy init` (which would loop).
    #[tokio::test]
    async fn active_context_check_passes_for_remote_config_install() {
        use devboy_core::config::RemoteConfigSettings;

        let config = Config {
            remote_config: Some(RemoteConfigSettings {
                url: Some("https://example.com/api/config/mcp".to_string()),
                token_key: Some("remote_config.token".to_string()),
            }),
            ..Default::default()
        };
        let ctx = test_context(
            Some(config),
            Some(PathBuf::from("config.toml")),
            true,
            None,
            None,
            true,
        );

        let result = ActiveContextCheck.run(&ctx).await;

        assert_eq!(result.status, CheckStatus::Pass);
        assert!(result.message.contains("Remote-config"));
        assert!(
            result
                .message
                .contains("https://example.com/api/config/mcp")
        );
        assert!(result.fix_command.is_none());
    }

    /// Issue #229: same goes for an install where the runtime fetch
    /// has already populated `[[proxy_mcp_servers]]` (no
    /// `[remote_config]` block, but the proxy is configured).
    #[tokio::test]
    async fn active_context_check_passes_when_proxy_servers_configured() {
        use devboy_core::config::ProxyMcpServerConfig;

        let config = Config {
            proxy_mcp_servers: vec![ProxyMcpServerConfig {
                name: "remote-1".to_string(),
                url: "https://example.com/api/mcp".to_string(),
                auth_type: "none".to_string(),
                token_key: None,
                tool_prefix: None,
                transport: "streamable-http".to_string(),
                routing: None,
            }],
            ..Default::default()
        };
        let ctx = test_context(
            Some(config),
            Some(PathBuf::from("config.toml")),
            true,
            None,
            None,
            true,
        );

        let result = ActiveContextCheck.run(&ctx).await;

        assert_eq!(result.status, CheckStatus::Pass);
        assert!(result.fix_command.is_none());
    }
}