vfa-tui 0.0.18

Enterprise-grade terminal UI for the Vanguard Frontier Agentic marketplace catalog
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
use std::path::{Path, PathBuf};

/// Identifies a supported harness directory type.
///
/// Each variant maps 1:1 to a well-known directory that a downstream workspace
/// may contain. The names are stable identifiers — use [`HarnessDir::dir_name`]
/// to obtain the on-disk directory name.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum HarnessDir {
    /// `.claude/` — Claude Code CLI agent definitions (markdown files).
    Claude,
    /// `.cursor/` — Cursor IDE agent configuration (JSON configs).
    Cursor,
    /// `.kiro/` — Kiro IDE steering files with agent references.
    Kiro,
    /// `.codex/` — Codex plugin.json-based agent entries.
    Codex,
    /// `.opencode/` — OpenCode TOML/YAML agent definitions.
    Opencode,
}

impl HarnessDir {
    /// Returns the directory name (without a leading `.`) as it appears on disk,
    /// e.g. `".claude"` for [`HarnessDir::Claude`].
    pub fn dir_name(&self) -> &'static str {
        match self {
            HarnessDir::Claude => ".claude",
            HarnessDir::Cursor => ".cursor",
            HarnessDir::Kiro => ".kiro",
            HarnessDir::Codex => ".codex",
            HarnessDir::Opencode => ".opencode",
        }
    }

    /// Iterate over all five known harness variants in declaration order.
    pub fn all() -> [HarnessDir; 5] {
        [
            HarnessDir::Claude,
            HarnessDir::Cursor,
            HarnessDir::Kiro,
            HarnessDir::Codex,
            HarnessDir::Opencode,
        ]
    }
}

/// Scans `workspace_root` for the five known harness directories and returns
/// every one that is present as a `(HarnessDir, PathBuf)` pair.
///
/// Only directories that actually exist on the filesystem are returned; the
/// order matches the declaration order in [`HarnessDir::all`].
pub fn detect_harness_dirs(workspace_root: &Path) -> Vec<(HarnessDir, PathBuf)> {
    HarnessDir::all()
        .into_iter()
        .filter_map(|h| {
            let path = workspace_root.join(h.dir_name());
            if path.is_dir() {
                Some((h, path))
            } else {
                None
            }
        })
        .collect()
}

/// Outcome of a harness-layout validation check.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum LayoutMatch {
    /// The directory contains at least one file that matches the expected
    /// harness layout pattern.
    Matches,
    /// The directory exists but contains no files that match the expected
    /// layout, or it is empty.
    NoMatch,
}

/// Validates whether `path` matches the expected on-disk layout for `dir`.
///
/// Each harness has a characteristic layout heuristic:
///
/// | Harness   | Recognised layout signal                                           |
/// |-----------|-------------------------------------------------------------------|
/// | Claude    | At least one `.md` file (agent ID encoded in filename).           |
/// | Cursor    | At least one `.json` file (config referencing agent paths).       |
/// | Kiro      | At least one `.md` or `.txt` file (steering files).               |
/// | Codex     | A `plugin.json` file at the directory root.                       |
/// | Opencode  | At least one `.toml` or `.yaml`/`.yml` file (agent definitions).  |
///
/// Returns [`LayoutMatch::NoMatch`] for any I/O errors so callers can treat
/// an unreadable directory as "skip with warning".
pub fn validate_harness_layout(dir: &HarnessDir, path: &Path) -> LayoutMatch {
    match dir {
        HarnessDir::Claude => has_file_with_extensions(path, &[".md"]),
        HarnessDir::Cursor => has_file_with_extensions(path, &[".json"]),
        HarnessDir::Kiro => has_file_with_extensions(path, &[".md", ".txt"]),
        HarnessDir::Codex => has_exact_file(path, "plugin.json"),
        HarnessDir::Opencode => has_file_with_extensions(path, &[".toml", ".yaml", ".yml"]),
    }
}

// ---------------------------------------------------------------------------
// Private helpers
// ---------------------------------------------------------------------------

/// Returns `LayoutMatch::Matches` if `dir` contains at least one regular file
/// whose name ends with any of the given `extensions` (case-sensitive).
/// Searches only the top level of the directory (non-recursive).
fn has_file_with_extensions(dir: &Path, extensions: &[&str]) -> LayoutMatch {
    let entries = match std::fs::read_dir(dir) {
        Ok(e) => e,
        Err(_) => return LayoutMatch::NoMatch,
    };

    for entry in entries.flatten() {
        let path = entry.path();
        if !path.is_file() {
            continue;
        }
        if let Some(name) = path.file_name().and_then(|n| n.to_str()) {
            if extensions.iter().any(|ext| name.ends_with(ext)) {
                return LayoutMatch::Matches;
            }
        }
    }

    LayoutMatch::NoMatch
}

/// Returns `LayoutMatch::Matches` if `dir` contains a regular file with
/// exactly the given `filename` at the top level.
fn has_exact_file(dir: &Path, filename: &str) -> LayoutMatch {
    let candidate = dir.join(filename);
    if candidate.is_file() {
        LayoutMatch::Matches
    } else {
        LayoutMatch::NoMatch
    }
}

// ---------------------------------------------------------------------------
// Tests
// ---------------------------------------------------------------------------

#[cfg(test)]
mod tests {
    use super::*;
    use std::fs;
    use tempfile::TempDir;

    // -----------------------------------------------------------------------
    // detect_harness_dirs — presence detection
    // -----------------------------------------------------------------------

    #[test]
    fn detect_none_when_no_harness_dirs() {
        let tmp = TempDir::new().unwrap();
        let result = detect_harness_dirs(tmp.path());
        assert!(
            result.is_empty(),
            "expected no harness dirs, got {result:?}"
        );
    }

    #[test]
    fn detect_all_five_harness_dirs() {
        let tmp = TempDir::new().unwrap();
        for h in HarnessDir::all() {
            fs::create_dir(tmp.path().join(h.dir_name())).unwrap();
        }
        let result = detect_harness_dirs(tmp.path());
        assert_eq!(
            result.len(),
            5,
            "expected 5 harness dirs, got {}",
            result.len()
        );
        let found: Vec<&HarnessDir> = result.iter().map(|(h, _)| h).collect();
        assert!(found.contains(&&HarnessDir::Claude));
        assert!(found.contains(&&HarnessDir::Cursor));
        assert!(found.contains(&&HarnessDir::Kiro));
        assert!(found.contains(&&HarnessDir::Codex));
        assert!(found.contains(&&HarnessDir::Opencode));
    }

    #[test]
    fn detect_subset_of_harness_dirs() {
        let tmp = TempDir::new().unwrap();
        fs::create_dir(tmp.path().join(".claude")).unwrap();
        fs::create_dir(tmp.path().join(".kiro")).unwrap();
        let result = detect_harness_dirs(tmp.path());
        assert_eq!(
            result.len(),
            2,
            "expected 2 harness dirs, got {}",
            result.len()
        );
        let found: Vec<&HarnessDir> = result.iter().map(|(h, _)| h).collect();
        assert!(found.contains(&&HarnessDir::Claude));
        assert!(found.contains(&&HarnessDir::Kiro));
        assert!(!found.contains(&&HarnessDir::Cursor));
    }

    #[test]
    fn detect_returns_absolute_paths() {
        let tmp = TempDir::new().unwrap();
        fs::create_dir(tmp.path().join(".cursor")).unwrap();
        let result = detect_harness_dirs(tmp.path());
        assert_eq!(result.len(), 1);
        let (_, path) = &result[0];
        assert!(path.is_absolute(), "expected absolute path, got {path:?}");
        assert_eq!(path, &tmp.path().join(".cursor"));
    }

    #[test]
    fn detect_ignores_files_named_like_harness_dirs() {
        // A file named `.claude` (not a directory) should NOT be detected.
        let tmp = TempDir::new().unwrap();
        fs::write(tmp.path().join(".claude"), "not a dir").unwrap();
        let result = detect_harness_dirs(tmp.path());
        assert!(
            result.is_empty(),
            "files named like harness dirs should be ignored: {result:?}"
        );
    }

    // -----------------------------------------------------------------------
    // validate_harness_layout — Claude (.md files)
    // -----------------------------------------------------------------------

    #[test]
    fn claude_layout_matches_md_file() {
        let tmp = TempDir::new().unwrap();
        let claude_dir = tmp.path().join(".claude");
        fs::create_dir(&claude_dir).unwrap();
        fs::write(claude_dir.join("security-agent-v1.md"), "# agent content").unwrap();
        assert_eq!(
            validate_harness_layout(&HarnessDir::Claude, &claude_dir),
            LayoutMatch::Matches
        );
    }

    #[test]
    fn claude_layout_no_match_wrong_extension() {
        let tmp = TempDir::new().unwrap();
        let claude_dir = tmp.path().join(".claude");
        fs::create_dir(&claude_dir).unwrap();
        fs::write(claude_dir.join("config.json"), "{}").unwrap();
        assert_eq!(
            validate_harness_layout(&HarnessDir::Claude, &claude_dir),
            LayoutMatch::NoMatch
        );
    }

    #[test]
    fn claude_layout_no_match_empty_dir() {
        let tmp = TempDir::new().unwrap();
        let claude_dir = tmp.path().join(".claude");
        fs::create_dir(&claude_dir).unwrap();
        assert_eq!(
            validate_harness_layout(&HarnessDir::Claude, &claude_dir),
            LayoutMatch::NoMatch
        );
    }

    // -----------------------------------------------------------------------
    // validate_harness_layout — Cursor (.json files)
    // -----------------------------------------------------------------------

    #[test]
    fn cursor_layout_matches_json_file() {
        let tmp = TempDir::new().unwrap();
        let cursor_dir = tmp.path().join(".cursor");
        fs::create_dir(&cursor_dir).unwrap();
        fs::write(cursor_dir.join("agents.json"), r#"{"agents": []}"#).unwrap();
        assert_eq!(
            validate_harness_layout(&HarnessDir::Cursor, &cursor_dir),
            LayoutMatch::Matches
        );
    }

    #[test]
    fn cursor_layout_no_match_md_only() {
        let tmp = TempDir::new().unwrap();
        let cursor_dir = tmp.path().join(".cursor");
        fs::create_dir(&cursor_dir).unwrap();
        fs::write(cursor_dir.join("readme.md"), "docs").unwrap();
        assert_eq!(
            validate_harness_layout(&HarnessDir::Cursor, &cursor_dir),
            LayoutMatch::NoMatch
        );
    }

    // -----------------------------------------------------------------------
    // validate_harness_layout — Kiro (.md or .txt steering files)
    // -----------------------------------------------------------------------

    #[test]
    fn kiro_layout_matches_md_file() {
        let tmp = TempDir::new().unwrap();
        let kiro_dir = tmp.path().join(".kiro");
        fs::create_dir(&kiro_dir).unwrap();
        fs::write(kiro_dir.join("steering.md"), "## steering").unwrap();
        assert_eq!(
            validate_harness_layout(&HarnessDir::Kiro, &kiro_dir),
            LayoutMatch::Matches
        );
    }

    #[test]
    fn kiro_layout_matches_txt_file() {
        let tmp = TempDir::new().unwrap();
        let kiro_dir = tmp.path().join(".kiro");
        fs::create_dir(&kiro_dir).unwrap();
        fs::write(kiro_dir.join("agents.txt"), "agent-ref-1\nagent-ref-2").unwrap();
        assert_eq!(
            validate_harness_layout(&HarnessDir::Kiro, &kiro_dir),
            LayoutMatch::Matches
        );
    }

    #[test]
    fn kiro_layout_no_match_json_only() {
        let tmp = TempDir::new().unwrap();
        let kiro_dir = tmp.path().join(".kiro");
        fs::create_dir(&kiro_dir).unwrap();
        fs::write(kiro_dir.join("config.json"), "{}").unwrap();
        assert_eq!(
            validate_harness_layout(&HarnessDir::Kiro, &kiro_dir),
            LayoutMatch::NoMatch
        );
    }

    // -----------------------------------------------------------------------
    // validate_harness_layout — Codex (plugin.json)
    // -----------------------------------------------------------------------

    #[test]
    fn codex_layout_matches_plugin_json() {
        let tmp = TempDir::new().unwrap();
        let codex_dir = tmp.path().join(".codex");
        fs::create_dir(&codex_dir).unwrap();
        fs::write(codex_dir.join("plugin.json"), r#"{"name": "my-plugin"}"#).unwrap();
        assert_eq!(
            validate_harness_layout(&HarnessDir::Codex, &codex_dir),
            LayoutMatch::Matches
        );
    }

    #[test]
    fn codex_layout_no_match_wrong_filename() {
        let tmp = TempDir::new().unwrap();
        let codex_dir = tmp.path().join(".codex");
        fs::create_dir(&codex_dir).unwrap();
        // "plugins.json" ≠ "plugin.json"
        fs::write(codex_dir.join("plugins.json"), r#"{"name": "my-plugin"}"#).unwrap();
        assert_eq!(
            validate_harness_layout(&HarnessDir::Codex, &codex_dir),
            LayoutMatch::NoMatch
        );
    }

    #[test]
    fn codex_layout_no_match_empty_dir() {
        let tmp = TempDir::new().unwrap();
        let codex_dir = tmp.path().join(".codex");
        fs::create_dir(&codex_dir).unwrap();
        assert_eq!(
            validate_harness_layout(&HarnessDir::Codex, &codex_dir),
            LayoutMatch::NoMatch
        );
    }

    // -----------------------------------------------------------------------
    // validate_harness_layout — Opencode (.toml / .yaml / .yml)
    // -----------------------------------------------------------------------

    #[test]
    fn opencode_layout_matches_toml_file() {
        let tmp = TempDir::new().unwrap();
        let oc_dir = tmp.path().join(".opencode");
        fs::create_dir(&oc_dir).unwrap();
        fs::write(oc_dir.join("agent.toml"), "[agent]\nname = \"foo\"").unwrap();
        assert_eq!(
            validate_harness_layout(&HarnessDir::Opencode, &oc_dir),
            LayoutMatch::Matches
        );
    }

    #[test]
    fn opencode_layout_matches_yaml_file() {
        let tmp = TempDir::new().unwrap();
        let oc_dir = tmp.path().join(".opencode");
        fs::create_dir(&oc_dir).unwrap();
        fs::write(oc_dir.join("agent.yaml"), "name: foo").unwrap();
        assert_eq!(
            validate_harness_layout(&HarnessDir::Opencode, &oc_dir),
            LayoutMatch::Matches
        );
    }

    #[test]
    fn opencode_layout_matches_yml_file() {
        let tmp = TempDir::new().unwrap();
        let oc_dir = tmp.path().join(".opencode");
        fs::create_dir(&oc_dir).unwrap();
        fs::write(oc_dir.join("agent.yml"), "name: foo").unwrap();
        assert_eq!(
            validate_harness_layout(&HarnessDir::Opencode, &oc_dir),
            LayoutMatch::Matches
        );
    }

    #[test]
    fn opencode_layout_no_match_json_only() {
        let tmp = TempDir::new().unwrap();
        let oc_dir = tmp.path().join(".opencode");
        fs::create_dir(&oc_dir).unwrap();
        fs::write(oc_dir.join("config.json"), "{}").unwrap();
        assert_eq!(
            validate_harness_layout(&HarnessDir::Opencode, &oc_dir),
            LayoutMatch::NoMatch
        );
    }

    // -----------------------------------------------------------------------
    // validate_harness_layout — nonexistent / unreadable dir
    // -----------------------------------------------------------------------

    #[test]
    fn validate_nonexistent_dir_returns_no_match() {
        let tmp = TempDir::new().unwrap();
        let ghost = tmp.path().join(".ghost");
        // ghost does not exist at all
        assert_eq!(
            validate_harness_layout(&HarnessDir::Claude, &ghost),
            LayoutMatch::NoMatch
        );
    }

    // -----------------------------------------------------------------------
    // HarnessDir helpers
    // -----------------------------------------------------------------------

    #[test]
    fn harness_dir_names_are_correct() {
        assert_eq!(HarnessDir::Claude.dir_name(), ".claude");
        assert_eq!(HarnessDir::Cursor.dir_name(), ".cursor");
        assert_eq!(HarnessDir::Kiro.dir_name(), ".kiro");
        assert_eq!(HarnessDir::Codex.dir_name(), ".codex");
        assert_eq!(HarnessDir::Opencode.dir_name(), ".opencode");
    }

    #[test]
    fn harness_dir_all_returns_five_variants() {
        assert_eq!(HarnessDir::all().len(), 5);
    }
}