skls 0.6.0

TUI for listing and managing agent skills across Cursor, Claude Code, and Codex
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
//! Skill domain types for inventory, analytics, and TUI.

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::path::PathBuf;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Scope {
    Project,
    User,
}

/// Canonical skill identity: normalized id + scope + optional project root.
/// One type shared by the inventory merge, the multi-select marks, and the
/// stats-preserving reload.
pub type SkillKey = (String, Scope, Option<PathBuf>);

impl Scope {
    pub fn as_str(self) -> &'static str {
        match self {
            Scope::Project => "project",
            Scope::User => "user",
        }
    }
}

impl std::fmt::Display for Scope {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

/// Agent hosts that can own skill directories.
///
/// String ids match `gh skill list` `agentHosts` / `npx skills -a` where possible.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum Agent {
    Cursor,
    ClaudeCode,
    Codex,
    GeminiCli,
    Antigravity,
    AntigravityCli,
    #[serde(rename = "antigravity2.0")]
    Antigravity2,
    GitHubCopilot,
    OpenCode,
    Pi,
    Amp,
    KimiCli,
    Replit,
    QwenCode,
    Augment,
    Continue,
    /// Factory Droid (`gh` host: `droid`, path: `~/.factory/skills`)
    Droid,
    Kilo,
    Qoder,
    Roo,
    Trae,
    CodeBuddy,
    Grok,
    Cline,
    Warp,
    Universal,
    Devin,
}

/// One row of the single agent table. Order must match the `Agent` enum
/// declaration order — `as_str` indexes into it by discriminant and the
/// consistency test (`agent_tables_are_consistent`) guards the pairing.
struct AgentDef {
    agent: Agent,
    /// Canonical host string returned by `as_str` / accepted by `parse`.
    host: &'static str,
    /// Extra aliases accepted by `parse` (the host itself is always accepted).
    aliases: &'static [&'static str],
}

const AGENT_DEFS: &[AgentDef] = &[
    AgentDef {
        agent: Agent::Cursor,
        host: "cursor",
        aliases: &[],
    },
    AgentDef {
        agent: Agent::ClaudeCode,
        host: "claude-code",
        aliases: &["claude"],
    },
    AgentDef {
        agent: Agent::Codex,
        host: "codex",
        aliases: &[],
    },
    AgentDef {
        agent: Agent::GeminiCli,
        host: "gemini-cli",
        aliases: &["gemini"],
    },
    AgentDef {
        agent: Agent::Antigravity,
        host: "antigravity",
        aliases: &[],
    },
    AgentDef {
        agent: Agent::AntigravityCli,
        host: "antigravity-cli",
        aliases: &[],
    },
    AgentDef {
        agent: Agent::Antigravity2,
        host: "antigravity2.0",
        aliases: &["antigravity2"],
    },
    AgentDef {
        agent: Agent::GitHubCopilot,
        host: "github-copilot",
        aliases: &["copilot"],
    },
    AgentDef {
        agent: Agent::OpenCode,
        host: "opencode",
        aliases: &[],
    },
    AgentDef {
        agent: Agent::Pi,
        host: "pi",
        aliases: &[],
    },
    AgentDef {
        agent: Agent::Amp,
        host: "amp",
        aliases: &[],
    },
    AgentDef {
        agent: Agent::KimiCli,
        host: "kimi-cli",
        aliases: &["kimi"],
    },
    AgentDef {
        agent: Agent::Replit,
        host: "replit",
        aliases: &[],
    },
    AgentDef {
        agent: Agent::QwenCode,
        host: "qwen-code",
        aliases: &["qwen"],
    },
    AgentDef {
        agent: Agent::Augment,
        host: "augment",
        aliases: &[],
    },
    AgentDef {
        agent: Agent::Continue,
        host: "continue",
        aliases: &[],
    },
    AgentDef {
        agent: Agent::Droid,
        host: "droid",
        aliases: &["factory"],
    },
    AgentDef {
        agent: Agent::Kilo,
        host: "kilo",
        aliases: &["kilocode"],
    },
    AgentDef {
        agent: Agent::Qoder,
        host: "qoder",
        aliases: &[],
    },
    AgentDef {
        agent: Agent::Roo,
        host: "roo",
        aliases: &[],
    },
    AgentDef {
        agent: Agent::Trae,
        host: "trae",
        aliases: &[],
    },
    AgentDef {
        agent: Agent::CodeBuddy,
        host: "codebuddy",
        aliases: &[],
    },
    AgentDef {
        agent: Agent::Grok,
        host: "grok",
        aliases: &[],
    },
    AgentDef {
        agent: Agent::Cline,
        host: "cline",
        aliases: &[],
    },
    AgentDef {
        agent: Agent::Warp,
        host: "warp",
        aliases: &[],
    },
    AgentDef {
        agent: Agent::Universal,
        host: "universal",
        aliases: &[],
    },
    AgentDef {
        agent: Agent::Devin,
        host: "devin",
        aliases: &[],
    },
];

impl Agent {
    pub fn as_str(self) -> &'static str {
        AGENT_DEFS[self as usize].host
    }

    /// All known agents (inventory / filter order).
    pub fn all() -> &'static [Agent] {
        const ALL: [Agent; AGENT_DEFS.len()] = {
            let mut out = [Agent::Cursor; AGENT_DEFS.len()];
            let mut i = 0;
            while i < AGENT_DEFS.len() {
                out[i] = AGENT_DEFS[i].agent;
                i += 1;
            }
            out
        };
        &ALL
    }

    /// Default targets for add flow (common trio).
    pub fn primary() -> &'static [Agent] {
        &[Agent::Cursor, Agent::ClaudeCode, Agent::Codex]
    }

    pub fn parse(s: &str) -> Option<Self> {
        let idx = AGENT_DEFS
            .iter()
            .position(|d| d.host == s || d.aliases.contains(&s))?;
        Some(Agent::all()[idx])
    }
}

impl std::fmt::Display for Agent {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum InstallKind {
    Symlink,
    Copy,
    Unknown,
}

impl InstallKind {
    pub fn as_str(self) -> &'static str {
        match self {
            InstallKind::Symlink => "symlink",
            InstallKind::Copy => "copy",
            InstallKind::Unknown => "unknown",
        }
    }
}

impl std::fmt::Display for InstallKind {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.as_str())
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum InstallSource {
    Gh,
    Npx,
    Manual,
    /// Bundled inside an agent plugin (Claude Code / Cursor / Codex /
    /// `~/.agents/plugins`). Not managed by gh / npx.
    Plugin,
}

impl InstallSource {
    pub fn as_str(self) -> &'static str {
        match self {
            InstallSource::Gh => "gh",
            InstallSource::Npx => "npx",
            InstallSource::Manual => "manual",
            InstallSource::Plugin => "plugin",
        }
    }

    /// List / detail label. Distinguishes `gh skill` from `npx skills`.
    pub fn label(self) -> &'static str {
        match self {
            InstallSource::Gh => "gh skill",
            InstallSource::Npx => "npx skills",
            InstallSource::Manual => "manual",
            InstallSource::Plugin => "plugin",
        }
    }
}

impl std::fmt::Display for InstallSource {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "{}", self.label())
    }
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct SkillLocation {
    pub agent: Agent,
    pub scope: Scope,
    pub path: PathBuf,
    pub kind: InstallKind,
    /// Canonical target when `path` is a symlink.
    pub resolved: Option<PathBuf>,
}

#[derive(Debug, Clone, Default, PartialEq)]
pub struct SkillStats {
    pub hits: u64,
    pub sessions_total: u64,
    pub last_hit_at: Option<DateTime<Utc>>,
    pub activation_rate: Option<f64>,
    pub delete_score: f64,
}

#[derive(Debug, Clone, PartialEq)]
pub struct SkillRecord {
    pub id: String,
    pub name: String,
    pub description: String,
    pub scope: Scope,
    /// Canonical project root when this row came from a project-scope FS scan.
    /// `None` for user-scope rows and plugin-attributed project rows.
    pub project: Option<PathBuf>,
    pub agents: Vec<Agent>,
    pub locations: Vec<SkillLocation>,
    pub install_kind: InstallKind,
    pub source: InstallSource,
    pub source_url: Option<String>,
    pub author: Option<String>,
    pub version: Option<String>,
    pub pinned: bool,
    pub stats: SkillStats,
}

impl SkillRecord {
    /// The canonical inventory identity for this skill.
    pub fn key(&self) -> SkillKey {
        (self.id.clone(), self.scope, self.project.clone())
    }

    pub fn agents_label(&self) -> String {
        if self.agents.is_empty() {
            "-".into()
        } else {
            self.agents
                .iter()
                .map(|a| a.as_str())
                .collect::<Vec<_>>()
                .join(",")
        }
    }
}

/// Shared id normalization used everywhere a skill name/id is compared:
/// inventory merge keys, gh matching, and log-stat tying. Keeps one rule so
/// lookups can never disagree about whether two strings name the same skill.
pub fn normalize_skill_id(id: &str, name: &str) -> String {
    let base = if id.is_empty() { name } else { id };
    base.trim_start_matches('.').to_lowercase()
}

/// Comma-joined agent ids for modal summaries (empty => `(none)`).
pub fn agents_label(agents: &[Agent]) -> String {
    if agents.is_empty() {
        "(none)".into()
    } else {
        agents
            .iter()
            .map(|a| a.as_str())
            .collect::<Vec<_>>()
            .join(",")
    }
}

/// GitHub owner parsed from a repo URL (used for author attribution).
pub fn github_owner(url: &str) -> Option<String> {
    let url = url.trim_end_matches('/');
    let rest = url
        .strip_prefix("https://github.com/")
        .or_else(|| url.strip_prefix("http://github.com/"))?;
    let rest = rest.strip_suffix(".git").unwrap_or(rest);
    rest.split('/')
        .next()
        .filter(|s| !s.is_empty())
        .map(|s| s.to_string())
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SortKey {
    Name,
    Rate,
    Score,
    LastHit,
    Author,
    Source,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SortDir {
    Asc,
    Desc,
}

impl SortDir {
    pub fn toggle(self) -> Self {
        match self {
            SortDir::Asc => SortDir::Desc,
            SortDir::Desc => SortDir::Asc,
        }
    }

    pub fn as_str(self) -> &'static str {
        match self {
            SortDir::Asc => "asc",
            SortDir::Desc => "desc",
        }
    }

    pub fn marker(self) -> &'static str {
        match self {
            SortDir::Asc => "↑",
            SortDir::Desc => "↓",
        }
    }
}

impl SortKey {
    pub fn next(self) -> Self {
        match self {
            SortKey::Name => SortKey::Rate,
            SortKey::Rate => SortKey::Score,
            SortKey::Score => SortKey::LastHit,
            SortKey::LastHit => SortKey::Author,
            SortKey::Author => SortKey::Source,
            SortKey::Source => SortKey::Name,
        }
    }

    pub fn default_dir(self) -> SortDir {
        match self {
            SortKey::Name | SortKey::Author | SortKey::Source => SortDir::Asc,
            SortKey::Rate | SortKey::Score | SortKey::LastHit => SortDir::Desc,
        }
    }

    pub fn as_str(self) -> &'static str {
        match self {
            SortKey::Name => "name",
            SortKey::Rate => "rate",
            SortKey::Score => "delete_score",
            SortKey::LastHit => "last_hit",
            SortKey::Author => "author",
            SortKey::Source => "source",
        }
    }
}

#[derive(Debug, Clone, Default)]
pub struct SkillFilters {
    pub scope: Option<Scope>,
    pub agents: Vec<Agent>,
    pub query: String,
}

impl SkillFilters {
    pub fn matches(&self, skill: &SkillRecord) -> bool {
        if let Some(scope) = self.scope
            && skill.scope != scope
        {
            return false;
        }
        if !self.agents.is_empty() && !skill.agents.iter().any(|a| self.agents.contains(a)) {
            return false;
        }
        if !self.query.is_empty() {
            let q = self.query.to_lowercase();
            let hay = format!(
                "{} {} {}",
                skill.name.to_lowercase(),
                skill.description.to_lowercase(),
                skill.id.to_lowercase()
            );
            if !hay.contains(&q) {
                return false;
            }
        }
        true
    }
}

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

    #[test]
    fn parses_gh_agent_host_aliases() {
        assert_eq!(Agent::parse("github-copilot"), Some(Agent::GitHubCopilot));
        assert_eq!(Agent::parse("copilot"), Some(Agent::GitHubCopilot));
        assert_eq!(Agent::parse("qwen-code"), Some(Agent::QwenCode));
        assert_eq!(Agent::parse("droid"), Some(Agent::Droid));
        assert_eq!(Agent::parse("factory"), Some(Agent::Droid));
        assert_eq!(Agent::parse("antigravity2.0"), Some(Agent::Antigravity2));
        assert_eq!(Agent::parse("kilo"), Some(Agent::Kilo));
        assert_eq!(Agent::parse("universal"), Some(Agent::Universal));
    }

    #[test]
    fn all_agents_have_unique_ids() {
        let mut ids: Vec<_> = Agent::all().iter().map(|a| a.as_str()).collect();
        ids.sort_unstable();
        ids.dedup();
        assert_eq!(ids.len(), Agent::all().len());
    }

    #[test]
    fn agent_tables_are_consistent() {
        let all = Agent::all();
        for (i, agent) in all.iter().enumerate() {
            assert_eq!(
                AGENT_DEFS[i].agent, *agent,
                "AGENT_DEFS order must match enum order at index {i}"
            );
            assert_eq!(agent.as_str(), AGENT_DEFS[i].host);
            assert_eq!(
                Agent::parse(agent.as_str()),
                Some(*agent),
                "host round-trips"
            );
        }
        for def in AGENT_DEFS {
            for alias in def.aliases {
                assert_eq!(Agent::parse(alias), Some(def.agent), "alias {alias}");
            }
        }
    }

    #[test]
    fn normalize_skill_id_strips_dots_and_lowercases() {
        assert_eq!(normalize_skill_id(".FooBar", ".FooBar"), "foobar");
        assert_eq!(normalize_skill_id("", "fallback"), "fallback");
    }

    #[test]
    fn skill_key_includes_project_for_project_scope() {
        let proj = PathBuf::from("/tmp/repo");
        let rec = SkillRecord {
            id: "tdd".into(),
            name: "TDD".into(),
            description: String::new(),
            scope: Scope::Project,
            project: Some(proj.clone()),
            agents: vec![],
            locations: vec![],
            install_kind: InstallKind::Copy,
            source: InstallSource::Manual,
            source_url: None,
            author: None,
            version: None,
            pinned: false,
            stats: SkillStats::default(),
        };
        assert_eq!(rec.key(), (String::from("tdd"), Scope::Project, Some(proj)));
    }

    #[test]
    fn skill_key_user_has_no_project() {
        let rec = SkillRecord {
            id: "tdd".into(),
            name: "TDD".into(),
            description: String::new(),
            scope: Scope::User,
            project: None,
            agents: vec![],
            locations: vec![],
            install_kind: InstallKind::Copy,
            source: InstallSource::Manual,
            source_url: None,
            author: None,
            version: None,
            pinned: false,
            stats: SkillStats::default(),
        };
        assert_eq!(rec.key(), (String::from("tdd"), Scope::User, None));
    }

    #[test]
    fn github_owner_parses_repo_urls() {
        assert_eq!(
            github_owner("https://github.com/mattpocock/skills"),
            Some("mattpocock".into())
        );
        assert_eq!(
            github_owner("https://github.com/vercel-labs/agent-browser.git"),
            Some("vercel-labs".into())
        );
        assert_eq!(github_owner("https://example.com/x"), None);
        assert_eq!(github_owner(""), None);
    }

    #[test]
    fn install_source_labels_distinguish_backends() {
        assert_eq!(InstallSource::Gh.label(), "gh skill");
        assert_eq!(InstallSource::Npx.label(), "npx skills");
        assert_eq!(InstallSource::Plugin.label(), "plugin");
        assert_eq!(InstallSource::Manual.label(), "manual");
        assert_eq!(InstallSource::Gh.as_str(), "gh");
        assert_eq!(InstallSource::Npx.as_str(), "npx");
    }

    #[test]
    fn filters_match_scope_agents_and_query() {
        let rec = SkillRecord {
            id: "find-skills".into(),
            name: "find-skills".into(),
            description: "Discover agent skills".into(),
            scope: Scope::User,
            project: None,
            agents: vec![Agent::Cursor, Agent::ClaudeCode],
            locations: vec![],
            install_kind: InstallKind::Copy,
            source: InstallSource::Npx,
            source_url: None,
            author: None,
            version: None,
            pinned: false,
            stats: SkillStats::default(),
        };
        let all = SkillFilters::default();
        assert!(all.matches(&rec));

        let project = SkillFilters {
            scope: Some(Scope::Project),
            ..Default::default()
        };
        assert!(!project.matches(&rec));

        let agent = SkillFilters {
            agents: vec![Agent::Codex],
            ..Default::default()
        };
        assert!(!agent.matches(&rec));

        let agent2 = SkillFilters {
            agents: vec![Agent::Cursor, Agent::Codex],
            ..Default::default()
        };
        assert!(agent2.matches(&rec));

        let query = SkillFilters {
            query: "DISCOVER".into(),
            ..Default::default()
        };
        assert!(query.matches(&rec));
        let miss = SkillFilters {
            query: "zzz".into(),
            ..Default::default()
        };
        assert!(!miss.matches(&rec));
    }
}