agent-hub-runtime 0.6.0

AgentHub desktop and companion CLI runtime for Tauri applications
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
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
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::PathBuf;

/// Top-level grouping for sidebar/overview display. Does not affect skill
/// deployment, sync, or any other backend behavior — purely a UI taxonomy.
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum ToolCategory {
    /// Coding agents (Claude Code, Cursor, Codex, etc.). The default.
    #[default]
    Coding,
    /// Lobster-class personal AI assistants (OpenClaw ecosystem, Hermes Agent).
    Lobster,
}

#[derive(Debug, Clone, Serialize)]
pub struct ToolAdapter {
    pub key: String,
    pub display_name: String,
    pub relative_skills_dir: String,
    pub relative_detect_dir: String,
    /// Additional directories to scan for skills (e.g. plugin/marketplace dirs).
    /// These are only used for discovery, not for deployment.
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub additional_scan_dirs: Vec<String>,
    /// When set, overrides the computed skills_dir with this absolute path.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub override_skills_dir: Option<String>,
    /// Whether this is a user-defined custom agent (not built-in).
    #[serde(default)]
    pub is_custom: bool,
    /// When true, scan the skills directory recursively for skill directories
    /// (directories containing SKILL.md) instead of treating immediate children as skills.
    /// Used by tools with nested category directories (e.g., Hermes Agent).
    #[serde(default)]
    pub recursive_scan: bool,
    /// Optional override for the project-level skills path. When `None`, the
    /// project-level path falls back to `relative_skills_dir`. Used by tools
    /// like OpenCode where the global path (`~/.config/opencode/skills`)
    /// differs from the project path (`.opencode/skills`).
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub project_relative_skills_dir: Option<String>,
    /// UI grouping. See [`ToolCategory`].
    #[serde(default)]
    pub category: ToolCategory,
}

/// Serializable custom tool definition stored in settings.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CustomToolDef {
    pub key: String,
    pub display_name: String,
    pub skills_dir: String,
    #[serde(default)]
    pub project_relative_skills_dir: Option<String>,
    #[serde(default)]
    pub category: ToolCategory,
}

impl ToolAdapter {
    fn home() -> PathBuf {
        dirs::home_dir().expect("Cannot determine home directory")
    }

    fn candidate_paths(relative: &str) -> Vec<PathBuf> {
        let mut candidates = vec![Self::home().join(relative)];

        if let Some(suffix) = relative.strip_prefix(".config/") {
            if let Some(config_dir) = dirs::config_dir() {
                let config_path = config_dir.join(suffix);
                if !candidates.contains(&config_path) {
                    candidates.push(config_path);
                }
            }
        }

        candidates
    }

    fn select_existing_or_default(paths: &[PathBuf]) -> PathBuf {
        paths
            .iter()
            .find(|path| path.exists())
            .cloned()
            .unwrap_or_else(|| paths[0].clone())
    }

    pub fn skills_dir(&self) -> PathBuf {
        if let Some(ref abs) = self.override_skills_dir {
            return PathBuf::from(abs);
        }
        let candidates = Self::candidate_paths(&self.relative_skills_dir);
        Self::select_existing_or_default(&candidates)
    }

    /// Project-relative skills path used when scanning workspaces. Falls back
    /// to `relative_skills_dir` when no project-specific override is set.
    pub fn project_relative_skills_dir(&self) -> &str {
        self.project_relative_skills_dir
            .as_deref()
            .unwrap_or(&self.relative_skills_dir)
    }

    /// Returns all directories to scan for skills: the primary skills_dir plus any additional scan dirs.
    pub fn all_scan_dirs(&self) -> Vec<PathBuf> {
        let mut dirs = vec![self.skills_dir()];
        for c in self.additional_existing_scan_dirs() {
            if !dirs.contains(&c) {
                dirs.push(c);
            }
        }
        dirs
    }

    /// Returns the existing additional discovery roots for this adapter.
    pub fn additional_existing_scan_dirs(&self) -> Vec<PathBuf> {
        let mut dirs = Vec::new();
        for rel in &self.additional_scan_dirs {
            let candidates = Self::candidate_paths(rel);
            for c in candidates {
                if c.exists() && !dirs.contains(&c) {
                    dirs.push(c);
                }
            }
        }
        dirs
    }

    /// Whether executable code for this Agent is installed on this machine.
    pub fn is_installed(&self) -> bool {
        super::tool_detection::is_installed(&self.key)
    }

    /// Explicit destinations remain usable for manual/custom deployment, but
    /// configuring a destination is never evidence of an installed Agent.
    pub fn can_deploy(&self) -> bool {
        self.is_custom || self.override_skills_dir.is_some() || self.is_installed()
    }

    /// Whether this adapter's skills_dir has been overridden from the default.
    pub fn has_path_override(&self) -> bool {
        self.override_skills_dir.is_some()
    }
}

/// Shared user-level Skills root, independent of per-Agent overrides.
pub fn shared_skills_dir() -> PathBuf {
    crate::product::home_directory(&ToolAdapter::home()).join("skills")
}

pub fn default_tool_adapters() -> Vec<ToolAdapter> {
    vec![
        ToolAdapter {
            key: "cursor".into(),
            display_name: "Cursor".into(),
            relative_skills_dir: ".cursor/skills".into(),
            relative_detect_dir: ".cursor".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "claude_code".into(),
            display_name: "Claude Code".into(),
            relative_skills_dir: ".claude/skills".into(),
            relative_detect_dir: ".claude".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            // oh-my-pi (omp) reads native skills from asymmetric paths: the
            // user-level scan is `~/.omp/agent/skills` (the active profile's
            // agent dir), while the project-level scan walks up for
            // `<repo>/.omp/skills` (no `agent` segment). See the `native`
            // provider in oh-my-pi `discovery/builtin.ts`.
            key: "omp_agent".into(),
            display_name: "OMP Agent".into(),
            relative_skills_dir: ".omp/agent/skills".into(),
            relative_detect_dir: ".omp/agent".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: Some(".omp/skills".into()),
        },
        ToolAdapter {
            // Codex CLI reads user-level skills from `~/.codex/skills/` and
            // project-level skills from `<repo>/.codex/skills/`. The shared
            // `~/.agents/skills` location is kept as a discovery fallback so
            // skills synced there by other adapters (or by older agent-hub
            // versions that deployed Codex there by mistake) still surface in
            // the Codex tab.
            //
            // Note: `AGENT_SKILLS_PATH` (openai/codex#13074) is a proposed
            // env var that would let Codex load from `<custom>/.agents/skills`;
            // until it ships, `.codex/skills` is the only path Codex CLI
            // actually reads.
            key: "codex".into(),
            display_name: "Codex".into(),
            relative_skills_dir: ".codex/skills".into(),
            relative_detect_dir: ".codex".into(),
            additional_scan_dirs: vec![".agents/skills".into()],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            // Grok reads user-level skills from `~/.grok/skills/` and
            // project-level skills from `<repo>/.grok/skills/`.
            // See https://docs.x.ai/build/features/skills-plugins-marketplaces
            key: "grok".into(),
            display_name: "Grok".into(),
            relative_skills_dir: ".grok/skills".into(),
            relative_detect_dir: ".grok".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "opencode".into(),
            display_name: "OpenCode".into(),
            relative_skills_dir: ".config/opencode/skills".into(),
            relative_detect_dir: ".config/opencode".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: Some(".opencode/skills".into()),
        },
        ToolAdapter {
            key: "antigravity".into(),
            display_name: "Antigravity".into(),
            relative_skills_dir: ".gemini/antigravity/skills".into(),
            relative_detect_dir: ".gemini/antigravity".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "amp".into(),
            display_name: "Amp".into(),
            relative_skills_dir: ".config/agents/skills".into(),
            relative_detect_dir: ".config/agents".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "kilo_code".into(),
            display_name: "Kilo Code".into(),
            relative_skills_dir: ".kilocode/skills".into(),
            relative_detect_dir: ".kilocode".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "roo_code".into(),
            display_name: "Roo Code".into(),
            relative_skills_dir: ".roo/skills".into(),
            relative_detect_dir: ".roo".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "goose".into(),
            display_name: "Goose".into(),
            relative_skills_dir: ".config/goose/skills".into(),
            relative_detect_dir: ".config/goose".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "gemini_cli".into(),
            display_name: "Gemini CLI".into(),
            relative_skills_dir: ".gemini/skills".into(),
            relative_detect_dir: ".gemini".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "github_copilot".into(),
            display_name: "GitHub Copilot".into(),
            relative_skills_dir: ".copilot/skills".into(),
            relative_detect_dir: ".copilot".into(),
            // GitHub Copilot now reads skills from the unified `~/.agents/skills` location too.
            additional_scan_dirs: vec![".agents/skills".into()],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "openclaw".into(),
            display_name: "OpenClaw".into(),
            relative_skills_dir: ".openclaw/skills".into(),
            relative_detect_dir: ".openclaw".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Lobster,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "droid".into(),
            display_name: "Droid".into(),
            relative_skills_dir: ".factory/skills".into(),
            relative_detect_dir: ".factory".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "windsurf".into(),
            display_name: "Windsurf".into(),
            relative_skills_dir: ".codeium/windsurf/skills".into(),
            relative_detect_dir: ".codeium/windsurf".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "trae".into(),
            display_name: "TRAE IDE".into(),
            relative_skills_dir: ".trae/skills".into(),
            relative_detect_dir: ".trae".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "cline".into(),
            display_name: "Cline".into(),
            relative_skills_dir: ".agents/skills".into(),
            relative_detect_dir: ".cline".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "deepagents".into(),
            display_name: "Deep Agents".into(),
            relative_skills_dir: ".deepagents/agent/skills".into(),
            relative_detect_dir: ".deepagents".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "firebender".into(),
            display_name: "Firebender".into(),
            relative_skills_dir: ".firebender/skills".into(),
            relative_detect_dir: ".firebender".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "kimi".into(),
            display_name: "Kimi Code CLI".into(),
            relative_skills_dir: ".kimi-code/skills".into(),
            relative_detect_dir: ".kimi-code".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: Some(".kimi-code/skills".into()),
        },
        ToolAdapter {
            key: "replit".into(),
            display_name: "Replit".into(),
            relative_skills_dir: ".config/agents/skills".into(),
            relative_detect_dir: ".replit".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "warp".into(),
            display_name: "Warp".into(),
            relative_skills_dir: ".agents/skills".into(),
            relative_detect_dir: ".warp".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "augment".into(),
            display_name: "Augment".into(),
            relative_skills_dir: ".augment/skills".into(),
            relative_detect_dir: ".augment".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "bob".into(),
            display_name: "IBM Bob".into(),
            relative_skills_dir: ".bob/skills".into(),
            relative_detect_dir: ".bob".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "codebuddy".into(),
            display_name: "CodeBuddy".into(),
            relative_skills_dir: ".codebuddy/skills".into(),
            relative_detect_dir: ".codebuddy".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "command_code".into(),
            display_name: "Command Code".into(),
            relative_skills_dir: ".commandcode/skills".into(),
            relative_detect_dir: ".commandcode".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "continue".into(),
            display_name: "Continue".into(),
            relative_skills_dir: ".continue/skills".into(),
            relative_detect_dir: ".continue".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "cortex".into(),
            display_name: "Cortex Code".into(),
            relative_skills_dir: ".snowflake/cortex/skills".into(),
            relative_detect_dir: ".snowflake/cortex".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "crush".into(),
            display_name: "Crush".into(),
            relative_skills_dir: ".config/crush/skills".into(),
            relative_detect_dir: ".config/crush".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "iflow".into(),
            display_name: "iFlow CLI".into(),
            relative_skills_dir: ".iflow/skills".into(),
            relative_detect_dir: ".iflow".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "junie".into(),
            display_name: "Junie".into(),
            relative_skills_dir: ".junie/skills".into(),
            relative_detect_dir: ".junie".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "kiro".into(),
            display_name: "Kiro CLI".into(),
            relative_skills_dir: ".kiro/skills".into(),
            relative_detect_dir: ".kiro".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "kode".into(),
            display_name: "Kode".into(),
            relative_skills_dir: ".kode/skills".into(),
            relative_detect_dir: ".kode".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "mcpjam".into(),
            display_name: "MCPJam".into(),
            relative_skills_dir: ".mcpjam/skills".into(),
            relative_detect_dir: ".mcpjam".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "mistral_vibe".into(),
            display_name: "Mistral Vibe".into(),
            relative_skills_dir: ".vibe/skills".into(),
            relative_detect_dir: ".vibe".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "mux".into(),
            display_name: "Mux".into(),
            relative_skills_dir: ".mux/skills".into(),
            relative_detect_dir: ".mux".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "neovate".into(),
            display_name: "Neovate".into(),
            relative_skills_dir: ".neovate/skills".into(),
            relative_detect_dir: ".neovate".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "openhands".into(),
            display_name: "OpenHands".into(),
            relative_skills_dir: ".openhands/skills".into(),
            relative_detect_dir: ".openhands".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            // Pi loads user-level skills from `~/.pi/agent/skills/` (note the
            // `agent` segment) and project-level skills from `<repo>/.pi/skills/`
            // (no `agent` segment) — the same split as its oh-my-pi fork above.
            // `~/.agents/skills` is a second user-level root Pi reads, kept here
            // as a discovery fallback so skills deployed there for Codex/Copilot
            // still surface in the Pi tab. See pi-coding-agent `docs/skills.md`.
            key: "pi".into(),
            display_name: "Pi".into(),
            relative_skills_dir: ".pi/agent/skills".into(),
            relative_detect_dir: ".pi/agent".into(),
            additional_scan_dirs: vec![".agents/skills".into()],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: Some(".pi/skills".into()),
        },
        ToolAdapter {
            key: "pochi".into(),
            display_name: "Pochi".into(),
            relative_skills_dir: ".pochi/skills".into(),
            relative_detect_dir: ".pochi".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "qoder".into(),
            display_name: "Qoder".into(),
            relative_skills_dir: ".qoder/skills".into(),
            relative_detect_dir: ".qoder".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "qwen_code".into(),
            display_name: "Qwen Code".into(),
            relative_skills_dir: ".qwen/skills".into(),
            relative_detect_dir: ".qwen".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "trae_cn".into(),
            display_name: "TRAE CN".into(),
            relative_skills_dir: ".trae-cn/skills".into(),
            relative_detect_dir: ".trae-cn".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "zencoder".into(),
            display_name: "Zencoder".into(),
            relative_skills_dir: ".zencoder/skills".into(),
            relative_detect_dir: ".zencoder".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "zcode".into(),
            display_name: "ZCode".into(),
            relative_skills_dir: ".zcode/skills".into(),
            relative_detect_dir: ".zcode".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "adal".into(),
            display_name: "AdaL".into(),
            relative_skills_dir: ".adal/skills".into(),
            relative_detect_dir: ".adal".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "hermes".into(),
            display_name: "Hermes Agent".into(),
            relative_skills_dir: ".hermes/skills".into(),
            relative_detect_dir: ".hermes".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Lobster,
            is_custom: false,
            recursive_scan: true,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "qclaw".into(),
            display_name: "QClaw".into(),
            relative_skills_dir: ".qclaw/skills".into(),
            relative_detect_dir: ".qclaw".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Lobster,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "easyclaw".into(),
            display_name: "EasyClaw".into(),
            relative_skills_dir: ".easyclaw/skills".into(),
            relative_detect_dir: ".easyclaw".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Lobster,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            key: "autoclaw".into(),
            display_name: "AutoClaw".into(),
            relative_skills_dir: ".openclaw-autoclaw/skills".into(),
            relative_detect_dir: ".openclaw-autoclaw".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Lobster,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            // WorkBuddy's user skill directory is `~/.workbuddy/skills/` — that
            // is where its own skill import unpacks to and what it scans as
            // `source='user'`. `~/.workbuddy/skills-marketplace/` is a different
            // thing: a vendor cache that `BuiltinSkillMarketplaceUpdater` wipes
            // and re-extracts wholesale on every marketplace version bump, so
            // anything deployed under it is destroyed on the next update.
            key: "workbuddy".into(),
            display_name: "WorkBuddy".into(),
            relative_skills_dir: ".workbuddy/skills".into(),
            relative_detect_dir: ".workbuddy".into(),
            additional_scan_dirs: vec![],
            override_skills_dir: None,
            category: ToolCategory::Lobster,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            // DeepSeek Harness resolves its home as `$DSH_HOME` or `~/.dsh`
            // (`packages/util/home-paths/src/index.ts`) and scans `skills`
            // beneath it, so the deploy target is `~/.dsh/skills`.
            //
            // It also reads the shared `~/.agents/skills` root (`$DSH_AGENTS_HOME`
            // or `~/.agents`) — discovery only, like Codex and Copilot, so a
            // deployment lands in its own directory and cannot be mistaken for
            // another agent's.
            //
            // Project roots are `<project>/.dsh/skills` and
            // `<project>/.agents/skills`; the former is the higher-ranked of the
            // two and matches the global path, so no project override is needed.
            // Verified against `packages/skill/skill-filesystem/src/index.ts`
            // rather than the README alone.
            key: "deepseek_harness".into(),
            display_name: "DeepSeek Harness".into(),
            relative_skills_dir: ".dsh/skills".into(),
            relative_detect_dir: ".dsh".into(),
            additional_scan_dirs: vec![".agents/skills".into()],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: None,
        },
        ToolAdapter {
            // The GitLab Duo CLI (launched as `glab duo cli`) resolves its
            // config home to `%APPDATA%\GitLab\duo` on Windows,
            // `$GLAB_CONFIG_DIR` or `$XDG_CONFIG_HOME/gitlab/duo` when either
            // is set (GLAB_CONFIG_DIR wins), and `~/.gitlab/duo` otherwise --
            // then scans `skills` beneath it.
            //
            // Adapters resolve paths from the home directory and read no env
            // vars, so `~/.gitlab/duo/skills` is right on Linux and macOS at
            // their defaults and nowhere else. THREE cases need a manual path
            // override, Windows included: there the real location is
            // `%APPDATA%\GitLab\duo`, not `%USERPROFILE%\.gitlab\duo`, so
            // `is_installed()` finds nothing and Duo shows as not installed.
            // Covering that properly needs per-platform adapter paths, which
            // no adapter has today -- tracked separately, do not bolt a
            // GitLab-shaped special case into `candidate_paths`.
            //
            // Duo also reads the shared `~/.agents/skills` root -- the location
            // `glab skills install --global` writes to. Discovery only, like
            // Codex and Copilot, so a deployment lands in Duo's own directory
            // and cannot be mistaken for another agent's. This one *is* right
            // on all three platforms: the shared root is `%USERPROFILE%\.agents\skills`
            // on Windows, which is what resolving from the home dir already gives.
            //
            // Its project-level roots are `<repo>/.agents/skills` and
            // `<repo>/skills`. The bare `skills` variant would claim any
            // unrelated directory of that name in a workspace, so the project
            // target is the spec-compliant `.agents/skills`.
            //
            // Paths verified by reading the `AgentSkillsResolver` in the
            // bundled Duo CLI binary, not the documentation.
            key: "gitlab_duo".into(),
            display_name: "GitLab Duo".into(),
            relative_skills_dir: ".gitlab/duo/skills".into(),
            relative_detect_dir: ".gitlab/duo".into(),
            additional_scan_dirs: vec![".agents/skills".into()],
            override_skills_dir: None,
            category: ToolCategory::Coding,
            is_custom: false,
            recursive_scan: false,
            project_relative_skills_dir: Some(".agents/skills".into()),
        },
    ]
}

/// Read custom tool path overrides from store.
pub fn custom_tool_paths(store: &crate::core::skill_store::SkillStore) -> HashMap<String, String> {
    store
        .get_setting("custom_tool_paths")
        .ok()
        .flatten()
        .and_then(|v| serde_json::from_str(&v).ok())
        .unwrap_or_default()
}

/// Read per-tool project-relative skills path overrides for built-in adapters.
/// Maps tool key -> project-relative path (e.g. `.cursor/skills`). Custom tools
/// store their project path inside [`CustomToolDef`] instead.
pub fn custom_tool_project_paths(
    store: &crate::core::skill_store::SkillStore,
) -> HashMap<String, String> {
    store
        .get_setting("custom_tool_project_paths")
        .ok()
        .flatten()
        .and_then(|v| serde_json::from_str(&v).ok())
        .unwrap_or_default()
}

/// Read user-defined custom tools from store.
pub fn custom_tools(store: &crate::core::skill_store::SkillStore) -> Vec<CustomToolDef> {
    store
        .get_setting("custom_tools")
        .ok()
        .flatten()
        .and_then(|v| serde_json::from_str(&v).ok())
        .unwrap_or_default()
}

fn apply_builtin_path_overrides(
    adapter: &mut ToolAdapter,
    overrides: &HashMap<String, String>,
    project_overrides: &HashMap<String, String>,
) {
    if let Some(path) = overrides.get(&adapter.key) {
        adapter.override_skills_dir = Some(path.clone());
    }

    if let Some(project_path) = project_overrides.get(&adapter.key) {
        adapter.project_relative_skills_dir = Some(project_path.clone());
    }
}

fn custom_tool_adapter(ct: CustomToolDef) -> ToolAdapter {
    ToolAdapter {
        key: ct.key,
        display_name: ct.display_name,
        relative_skills_dir: ct.project_relative_skills_dir.unwrap_or_default(),
        relative_detect_dir: String::new(),
        additional_scan_dirs: vec![],
        override_skills_dir: Some(ct.skills_dir),
        category: ct.category,
        is_custom: true,
        recursive_scan: false,
        project_relative_skills_dir: None,
    }
}

/// Returns all tool adapters: built-in (with path overrides applied) + custom tools.
pub fn all_tool_adapters(store: &crate::core::skill_store::SkillStore) -> Vec<ToolAdapter> {
    let overrides = custom_tool_paths(store);
    let project_overrides = custom_tool_project_paths(store);
    let customs = custom_tools(store);

    let mut adapters: Vec<ToolAdapter> = default_tool_adapters()
        .into_iter()
        .map(|mut adapter| {
            apply_builtin_path_overrides(&mut adapter, &overrides, &project_overrides);
            adapter
        })
        .collect();

    for custom in customs {
        if adapters.iter().any(|adapter| adapter.key == custom.key) {
            continue;
        }
        adapters.push(custom_tool_adapter(custom));
    }

    adapters
}

#[allow(dead_code)]
pub fn find_adapter(key: &str) -> Option<ToolAdapter> {
    default_tool_adapters().into_iter().find(|a| a.key == key)
}

/// Find an adapter by key, considering custom tools and path overrides.
pub fn find_adapter_with_store(
    store: &crate::core::skill_store::SkillStore,
    key: &str,
) -> Option<ToolAdapter> {
    let overrides = custom_tool_paths(store);
    let project_overrides = custom_tool_project_paths(store);
    let customs = custom_tools(store);

    if let Some(mut adapter) = default_tool_adapters().into_iter().find(|a| a.key == key) {
        apply_builtin_path_overrides(&mut adapter, &overrides, &project_overrides);
        return Some(adapter);
    }

    customs
        .into_iter()
        .find(|ct| ct.key == key)
        .map(custom_tool_adapter)
}

/// Returns adapters that are installed and not in the disabled list.
pub fn enabled_deployable_adapters(
    store: &crate::core::skill_store::SkillStore,
) -> Vec<ToolAdapter> {
    let disabled: Vec<String> = store
        .get_setting("disabled_tools")
        .ok()
        .flatten()
        .and_then(|v| serde_json::from_str(&v).ok())
        .unwrap_or_default();
    all_tool_adapters(store)
        .into_iter()
        .filter(|a| a.can_deploy() && !disabled.contains(&a.key))
        .collect()
}

#[cfg(test)]
mod tests;