vfa-tui 0.0.24

Enterprise-grade terminal UI for the Vanguard Frontier Agentic marketplace catalog
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
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
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,
    /// `.github/` — Copilot CLI agent definitions (`agents/<id>.agent.md`).
    ///
    /// Unlike the other variants this directory exists in almost every
    /// repository for unrelated reasons, so the top level will often match the
    /// layout on a stray template file. That is harmless: layout only decides
    /// whether a directory is walked, and confirming an asset still requires
    /// two independent detection signals, which an issue template has neither of.
    Copilot,
    /// `.gemini/` — Gemini agent definitions (markdown files).
    Gemini,
}

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",
            HarnessDir::Copilot => ".github",
            HarnessDir::Gemini => ".gemini",
        }
    }

    /// Iterate over every known harness variant in declaration order.
    pub fn all() -> [HarnessDir; 7] {
        [
            HarnessDir::Claude,
            HarnessDir::Cursor,
            HarnessDir::Kiro,
            HarnessDir::Codex,
            HarnessDir::Opencode,
            HarnessDir::Copilot,
            HarnessDir::Gemini,
        ]
    }
}

/// Scans `workspace_root` for every known harness directory 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` or `.md` file.                               |
/// | Kiro      | At least one `.md`, `.txt` or `.json` file.                       |
/// | Codex     | A `plugin.json` file, or at least one `.toml` agent file.         |
/// | Opencode  | At least one `.toml` or `.yaml`/`.yml` file (agent definitions).  |
/// | Copilot   | At least one `.md` file (`<id>.agent.md` exports).                |
/// | Gemini    | At least one `.md` file.                                          |
///
/// 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"]),
        // cursor exports write `.cursor/agents/<id>.md`, not JSON, so a
        // `.json`-only layout rejected a correct export.
        HarnessDir::Cursor => has_file_with_extensions(path, &[".json", ".md"]),
        // `.kiro/agents` receives both harnesses: kiro-ide writes `.md` and
        // kiro-cli writes `.json`. Accepting only `.md`/`.txt` meant a
        // kiro-cli-only export failed layout validation and its agents were
        // reported as not installed.
        HarnessDir::Kiro => has_file_with_extensions(path, &[".md", ".txt", ".json"]),
        // `vfa-export-agents --platform codex` writes `.codex/agents/<id>.toml`
        // and never a plugin.json, so requiring plugin.json alone meant a
        // correctly exported Codex workspace failed layout validation and its
        // agents were reported as not installed. Accept either signal.
        HarnessDir::Codex => match has_exact_file(path, "plugin.json") {
            LayoutMatch::Matches => LayoutMatch::Matches,
            LayoutMatch::NoMatch => has_file_with_extensions(path, &[".toml"]),
        },
        HarnessDir::Opencode => has_file_with_extensions(path, &[".toml", ".yaml", ".yml"]),
        // copilot exports write `.github/agents/<id>.agent.md`; gemini exports
        // write `.gemini/agents/<id>.md`.
        HarnessDir::Copilot => has_file_with_extensions(path, &[".md"]),
        HarnessDir::Gemini => has_file_with_extensions(path, &[".md"]),
    }
}

// ---------------------------------------------------------------------------
// 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:?}"
        );
    }

    /// Count derived from `HarnessDir::all()` rather than frozen, so adding a
    /// harness variant does not break this test.
    #[test]
    fn detect_all_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(),
            HarnessDir::all().len(),
            "expected every known harness dir, 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));
        assert!(found.contains(&&HarnessDir::Copilot));
        assert!(found.contains(&&HarnessDir::Gemini));
    }

    #[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
        );
    }

    /// Contract change: this previously asserted that a `.md` file must NOT
    /// satisfy the Cursor layout, which contradicted the exporter — cursor
    /// exports are `.cursor/agents/<id>.md`, so the rule rejected every correct
    /// export. Markdown now satisfies it.
    ///
    /// The original intent, that a stray document should not be mistaken for an
    /// installed asset, is preserved elsewhere and more strongly: layout is only
    /// a cheap pre-filter for walking a directory, and confirmation still
    /// requires two independent detection signals, which a readme has neither of.
    #[test]
    fn cursor_layout_matches_markdown_because_exports_are_markdown() {
        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::Matches
        );
    }

    #[test]
    fn cursor_layout_no_match_unrelated_extension() {
        let tmp = TempDir::new().unwrap();
        let cursor_dir = tmp.path().join(".cursor");
        fs::create_dir(&cursor_dir).unwrap();
        fs::write(cursor_dir.join("notes.txt"), "notes").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
        );
    }

    /// Contract change: this previously asserted that a `.json` file must NOT
    /// satisfy the Kiro layout. `.kiro/agents` receives both harnesses — kiro-ide
    /// writes `.md` and kiro-cli writes `.json` — so the rule rejected every
    /// correct kiro-cli export. JSON now satisfies it; confirmation still needs
    /// two independent detection signals, which a bare config file lacks.
    #[test]
    fn kiro_layout_matches_json_because_kiro_cli_exports_json() {
        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::Matches
        );
    }

    #[test]
    fn kiro_layout_no_match_unrelated_extension() {
        let tmp = TempDir::new().unwrap();
        let kiro_dir = tmp.path().join(".kiro");
        fs::create_dir(&kiro_dir).unwrap();
        fs::write(kiro_dir.join("notes.rst"), "notes").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
        );
    }

    /// Regression: `vfa-export-agents --platform codex` writes
    /// `.codex/agents/<id>.toml` and no plugin.json. Requiring plugin.json
    /// alone made a correctly exported Codex workspace fail layout validation,
    /// so its agents were reported as not installed.
    #[test]
    fn codex_layout_matches_exported_toml_agents() {
        let tmp = TempDir::new().unwrap();
        let codex_agents = tmp.path().join(".codex").join("agents");
        fs::create_dir_all(&codex_agents).unwrap();
        fs::write(
            codex_agents.join("aws-iam-least-privilege-review-agent.toml"),
            "name = \"aws-iam-least-privilege-review-agent\"\n",
        )
        .unwrap();
        assert_eq!(
            validate_harness_layout(&HarnessDir::Codex, &codex_agents),
            LayoutMatch::Matches
        );
    }

    /// Regression: `vfa-export-agents --platform kiro-cli` writes
    /// `.kiro/agents/<id>.json`, which the `.md`/`.txt` layout rejected.
    #[test]
    fn kiro_layout_matches_exported_json_agents() {
        let tmp = TempDir::new().unwrap();
        let kiro_agents = tmp.path().join(".kiro").join("agents");
        fs::create_dir_all(&kiro_agents).unwrap();
        fs::write(
            kiro_agents.join("aws-iam-least-privilege-review-agent.json"),
            r#"{"x-vfa-export":{"id":"aws-iam-least-privilege-review-agent"},"name":"IAM"}"#,
        )
        .unwrap();
        assert_eq!(
            validate_harness_layout(&HarnessDir::Kiro, &kiro_agents),
            LayoutMatch::Matches
        );
    }

    /// Regression: `vfa-export-agents --platform cursor` writes
    /// `.cursor/agents/<id>.md`, which the `.json`-only layout rejected.
    #[test]
    fn cursor_layout_matches_exported_md_agents() {
        let tmp = TempDir::new().unwrap();
        let cursor_agents = tmp.path().join(".cursor").join("agents");
        fs::create_dir_all(&cursor_agents).unwrap();
        fs::write(
            cursor_agents.join("aws-iam-least-privilege-review-agent.md"),
            "---\nname: IAM\n---\nbody\n",
        )
        .unwrap();
        assert_eq!(
            validate_harness_layout(&HarnessDir::Cursor, &cursor_agents),
            LayoutMatch::Matches
        );
    }

    /// Regression: `vfa-export-agents --platform copilot` writes
    /// `.github/agents/<id>.agent.md`, which had no HarnessDir variant at all,
    /// so the scanner never looked at it.
    #[test]
    fn copilot_layout_matches_exported_agent_markdown() {
        let tmp = TempDir::new().unwrap();
        let dir = tmp.path().join(".github").join("agents");
        fs::create_dir_all(&dir).unwrap();
        fs::write(
            dir.join("aws-iam-least-privilege-review-agent.agent.md"),
            "---\nname: IAM\n---\n",
        )
        .unwrap();
        assert_eq!(
            validate_harness_layout(&HarnessDir::Copilot, &dir),
            LayoutMatch::Matches
        );
    }

    /// Regression: `vfa-export-agents --platform gemini` writes
    /// `.gemini/agents/<id>.md`, likewise previously invisible.
    #[test]
    fn gemini_layout_matches_exported_markdown() {
        let tmp = TempDir::new().unwrap();
        let dir = tmp.path().join(".gemini").join("agents");
        fs::create_dir_all(&dir).unwrap();
        fs::write(
            dir.join("aws-iam-least-privilege-review-agent.md"),
            "---\nname: IAM\n---\n",
        )
        .unwrap();
        assert_eq!(
            validate_harness_layout(&HarnessDir::Gemini, &dir),
            LayoutMatch::Matches
        );
    }

    #[test]
    fn all_variants_have_distinct_dir_names() {
        let names: Vec<&str> = HarnessDir::all().iter().map(|h| h.dir_name()).collect();
        let unique: std::collections::HashSet<&&str> = names.iter().collect();
        assert_eq!(names.len(), unique.len(), "dir_name collision: {names:?}");
    }

    #[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]
    /// `all()` drives `detect_harness_dirs`, so a variant missing from it is
    /// invisible to the scanner. Assert the membership rather than a count: a
    /// bare length check passes just as happily when someone swaps one variant
    /// for another.
    fn harness_dir_all_lists_every_variant() {
        let all = HarnessDir::all();
        for expected in [
            HarnessDir::Claude,
            HarnessDir::Cursor,
            HarnessDir::Kiro,
            HarnessDir::Codex,
            HarnessDir::Opencode,
            HarnessDir::Copilot,
            HarnessDir::Gemini,
        ] {
            assert!(
                all.contains(&expected),
                "HarnessDir::all() is missing {expected:?}"
            );
        }
        assert!(
            all.iter().all(|h| h.dir_name().starts_with('.')),
            "every harness dir_name must be dot-prefixed"
        );
    }
}