cosh_tools/skills/
types.rs1use std::path::PathBuf;
4
5use schemars::JsonSchema;
6use serde::{Deserialize, Serialize};
7use thiserror::Error;
8
9#[derive(Debug, Clone, Deserialize, JsonSchema)]
13pub struct SkillsReadInput {
14 pub name: String,
16}
17
18#[derive(Debug, Clone, Deserialize, JsonSchema)]
20pub struct SkillsReadAssetInput {
21 pub name: String,
23 pub asset_path: String,
25}
26
27#[derive(Debug, Clone, Deserialize, JsonSchema)]
29pub struct SkillsMatchInput {
30 pub match_paths: Vec<String>,
32}
33
34#[derive(Debug, Clone, Serialize)]
36pub struct SkillInfo {
37 pub name: String,
38 pub description: String,
39}
40
41#[derive(Debug, Clone, Serialize)]
43pub struct SkillContent {
44 pub info: SkillInfo,
45 pub body: String,
47}
48
49#[derive(Debug, Clone)]
51pub enum SkillSource {
52 Directory { path: String },
54 Embedded { skill: EmbeddedSkill },
56}
57
58#[derive(Debug, Clone)]
60pub struct EmbeddedSkill {
61 pub name: String,
62 pub description: String,
63 pub content: String,
65 pub globs: Vec<String>,
66 pub always_apply: bool,
67}
68
69#[derive(Debug, Clone, Copy, PartialEq, Eq)]
71pub enum SkillAction {
72 List,
73 Read,
74 ReadAsset,
75 Match,
76}
77
78#[derive(Debug, Clone)]
82pub struct SkillSchema {
83 pub action: SkillAction,
84 pub sources: Vec<SkillSource>,
86 pub skill_name: Option<String>,
88 pub asset_path: Option<String>,
90 pub match_paths: Vec<String>,
92 pub recursive: bool,
94 pub ignore: Vec<String>,
96 pub include: Vec<String>,
99}
100
101#[derive(Debug, Clone, Serialize)]
103pub enum SkillOutput {
104 List { skills: Vec<SkillInfo> },
105 Read { skill: SkillContent },
106 ReadAsset { content: String },
107 Match { matched: Vec<SkillInfo> },
108}
109
110#[derive(Debug, Error)]
112pub enum SkillError {
113 #[error("skill not found: {0}")]
114 NotFound(String),
115 #[error("path traversal detected: {0}")]
116 PathTraversal(String),
117 #[error("invalid action: {0}")]
118 InvalidAction(String),
119 #[error("invalid source: {0}")]
120 InvalidSource(String),
121}
122
123#[derive(Debug, Default)]
127pub struct Frontmatter {
128 pub name: Option<String>,
129 pub description: Option<String>,
130 pub globs: Vec<String>,
131 pub always_apply: bool,
132}
133
134#[derive(Debug, Clone)]
136pub struct RawSkill {
137 pub source_key: String,
138 pub name: String,
139 pub description: String,
140 pub base_dir: PathBuf,
142 pub body: String,
144 pub globs: Vec<String>,
145 pub always_apply: bool,
146}