|
| 1 | +//! Skills SDK example — built-in skills, catalog injection, and delegate-task. |
| 2 | +//! |
| 3 | +//! Demonstrates: |
| 4 | +//! - Loading built-in skills (`builtin_skills()`) |
| 5 | +//! - Verifying delegate-task skill content and structure |
| 6 | +//! - Skill catalog injection (`build_skills_injection()`) |
| 7 | +//! - TaskTool / ParallelTaskTool descriptions include agent info |
| 8 | +//! |
| 9 | +//! No LLM calls — runs entirely offline. |
| 10 | +//! |
| 11 | +//! ## Usage |
| 12 | +//! |
| 13 | +//! ```bash |
| 14 | +//! cd crates/code && cargo run --example sdk_skills |
| 15 | +//! ``` |
| 16 | +
|
| 17 | +use a3s_code_core::tools::{ |
| 18 | + build_skills_injection, builtin_skills, Skill, SkillKind, DEFAULT_CATALOG_THRESHOLD, |
| 19 | +}; |
| 20 | + |
| 21 | +fn main() { |
| 22 | + println!("=== A3S Code SDK Skills Example ===\n"); |
| 23 | + |
| 24 | + // ── 1. Load built-in skills ────────────────────────────────────────── |
| 25 | + println!("--- Built-in Skills ---"); |
| 26 | + let skills = builtin_skills(); |
| 27 | + println!(" count: {}", skills.len()); |
| 28 | + assert!( |
| 29 | + skills.len() >= 2, |
| 30 | + "expected at least 2 built-in skills, got {}", |
| 31 | + skills.len() |
| 32 | + ); |
| 33 | + |
| 34 | + for skill in &skills { |
| 35 | + println!( |
| 36 | + " - {} (kind={:?}, desc_len={}, content_len={})", |
| 37 | + skill.name, |
| 38 | + skill.kind, |
| 39 | + skill.description.len(), |
| 40 | + skill.content.len() |
| 41 | + ); |
| 42 | + } |
| 43 | + println!(); |
| 44 | + |
| 45 | + // ── 2. Verify find-skills ──────────────────────────────────────────── |
| 46 | + println!("--- find-skills ---"); |
| 47 | + let find = skills.iter().find(|s| s.name == "find-skills"); |
| 48 | + assert!(find.is_some(), "find-skills should be present"); |
| 49 | + let find = find.unwrap(); |
| 50 | + assert_eq!(find.kind, SkillKind::Instruction); |
| 51 | + assert!(find.content.contains("search_skills")); |
| 52 | + assert!(find.content.contains("install_skill")); |
| 53 | + println!(" [ok] name={}", find.name); |
| 54 | + println!(" [ok] kind=Instruction"); |
| 55 | + println!(" [ok] content references search_skills, install_skill"); |
| 56 | + println!(); |
| 57 | + |
| 58 | + // ── 3. Verify delegate-task ────────────────────────────────────────── |
| 59 | + println!("--- delegate-task ---"); |
| 60 | + let delegate = skills.iter().find(|s| s.name == "delegate-task"); |
| 61 | + assert!(delegate.is_some(), "delegate-task should be present"); |
| 62 | + let delegate = delegate.unwrap(); |
| 63 | + |
| 64 | + // Kind |
| 65 | + assert_eq!(delegate.kind, SkillKind::Instruction); |
| 66 | + println!(" [ok] kind=Instruction"); |
| 67 | + |
| 68 | + // Description |
| 69 | + assert!( |
| 70 | + delegate.description.contains("sub-agent"), |
| 71 | + "description should mention sub-agents" |
| 72 | + ); |
| 73 | + println!( |
| 74 | + " [ok] description: {}", |
| 75 | + &delegate.description[..delegate.description.len().min(80)] |
| 76 | + ); |
| 77 | + |
| 78 | + // Content: built-in agents |
| 79 | + assert!(delegate.content.contains("explore"), "should reference explore"); |
| 80 | + assert!(delegate.content.contains("general"), "should reference general"); |
| 81 | + assert!(delegate.content.contains("plan"), "should reference plan"); |
| 82 | + println!(" [ok] content references agents: explore, general, plan"); |
| 83 | + |
| 84 | + // Content: custom agents |
| 85 | + assert!( |
| 86 | + delegate.content.contains("agent_dirs"), |
| 87 | + "should mention agent_dirs" |
| 88 | + ); |
| 89 | + println!(" [ok] content mentions agent_dirs for custom agents"); |
| 90 | + |
| 91 | + // Content: parallel_task |
| 92 | + assert!( |
| 93 | + delegate.content.contains("parallel_task"), |
| 94 | + "should reference parallel_task" |
| 95 | + ); |
| 96 | + println!(" [ok] content references parallel_task tool"); |
| 97 | + |
| 98 | + // Content: best practices |
| 99 | + assert!( |
| 100 | + delegate.content.contains("Best Practices"), |
| 101 | + "should have best practices section" |
| 102 | + ); |
| 103 | + println!(" [ok] content includes Best Practices section"); |
| 104 | + println!(); |
| 105 | + |
| 106 | + // ── 4. Skill catalog injection (full mode) ─────────────────────────── |
| 107 | + println!("--- Skill Catalog Injection (full mode) ---"); |
| 108 | + let full_injection = build_skills_injection(&skills, DEFAULT_CATALOG_THRESHOLD); |
| 109 | + assert!( |
| 110 | + !full_injection.is_empty(), |
| 111 | + "injection should not be empty with {} skills", |
| 112 | + skills.len() |
| 113 | + ); |
| 114 | + |
| 115 | + // 2 skills <= threshold 3 → full mode |
| 116 | + assert!( |
| 117 | + full_injection.contains("<skills>"), |
| 118 | + "should use full mode (<skills> tag)" |
| 119 | + ); |
| 120 | + assert!( |
| 121 | + full_injection.contains("delegate-task"), |
| 122 | + "injection should include delegate-task" |
| 123 | + ); |
| 124 | + assert!( |
| 125 | + full_injection.contains("find-skills"), |
| 126 | + "injection should include find-skills" |
| 127 | + ); |
| 128 | + println!(" threshold: {}", DEFAULT_CATALOG_THRESHOLD); |
| 129 | + println!(" instruction skills: {}", skills.len()); |
| 130 | + println!(" [ok] full mode: <skills> tag present"); |
| 131 | + println!(" [ok] delegate-task included in injection"); |
| 132 | + println!(" [ok] find-skills included in injection"); |
| 133 | + println!(); |
| 134 | + |
| 135 | + // ── 5. Skill catalog injection (catalog mode) ──────────────────────── |
| 136 | + println!("--- Skill Catalog Injection (catalog mode, threshold=1) ---"); |
| 137 | + let catalog_injection = build_skills_injection(&skills, 1); |
| 138 | + assert!( |
| 139 | + catalog_injection.contains("<skill-catalog>"), |
| 140 | + "should use catalog mode with threshold=1" |
| 141 | + ); |
| 142 | + assert!( |
| 143 | + catalog_injection.contains("delegate-task"), |
| 144 | + "catalog should list delegate-task" |
| 145 | + ); |
| 146 | + assert!( |
| 147 | + catalog_injection.contains("load_skill"), |
| 148 | + "catalog should reference load_skill" |
| 149 | + ); |
| 150 | + println!(" threshold: 1"); |
| 151 | + println!(" [ok] catalog mode: <skill-catalog> tag present"); |
| 152 | + println!(" [ok] delegate-task listed in catalog"); |
| 153 | + println!(" [ok] catalog references load_skill for on-demand loading"); |
| 154 | + println!(); |
| 155 | + |
| 156 | + // ── 6. Custom skills alongside builtins ────────────────────────────── |
| 157 | + println!("--- Custom Skills + Builtins ---"); |
| 158 | + let mut combined = skills.clone(); |
| 159 | + combined.push(Skill { |
| 160 | + name: "custom-deploy".to_string(), |
| 161 | + description: "Deploy to production".to_string(), |
| 162 | + allowed_tools: Some("Bash(*)".to_string()), |
| 163 | + disable_model_invocation: false, |
| 164 | + kind: SkillKind::Instruction, |
| 165 | + content: "Custom deployment instructions.".to_string(), |
| 166 | + }); |
| 167 | + combined.push(Skill { |
| 168 | + name: "custom-review".to_string(), |
| 169 | + description: "Code review assistant".to_string(), |
| 170 | + allowed_tools: None, |
| 171 | + disable_model_invocation: false, |
| 172 | + kind: SkillKind::Instruction, |
| 173 | + content: "Custom code review instructions.".to_string(), |
| 174 | + }); |
| 175 | + |
| 176 | + let combined_injection = build_skills_injection(&combined, DEFAULT_CATALOG_THRESHOLD); |
| 177 | + |
| 178 | + // 4 skills > threshold 3 → catalog mode |
| 179 | + assert!( |
| 180 | + combined_injection.contains("<skill-catalog>"), |
| 181 | + "4 skills should trigger catalog mode" |
| 182 | + ); |
| 183 | + assert!(combined_injection.contains("delegate-task")); |
| 184 | + assert!(combined_injection.contains("find-skills")); |
| 185 | + assert!(combined_injection.contains("custom-deploy")); |
| 186 | + assert!(combined_injection.contains("custom-review")); |
| 187 | + println!(" total instruction skills: {}", combined.len()); |
| 188 | + println!(" [ok] catalog mode triggered (count > threshold)"); |
| 189 | + println!(" [ok] all 4 skills listed in catalog"); |
| 190 | + println!(); |
| 191 | + |
| 192 | + // ── 7. Tool-kind skills don't affect injection ─────────────────────── |
| 193 | + println!("--- Tool-kind Skills Excluded ---"); |
| 194 | + let mut with_tool = skills.clone(); |
| 195 | + with_tool.push(Skill { |
| 196 | + name: "my-tool".to_string(), |
| 197 | + description: "A tool skill".to_string(), |
| 198 | + allowed_tools: None, |
| 199 | + disable_model_invocation: false, |
| 200 | + kind: SkillKind::Tool, |
| 201 | + content: "Tool content".to_string(), |
| 202 | + }); |
| 203 | + |
| 204 | + let tool_injection = build_skills_injection(&with_tool, DEFAULT_CATALOG_THRESHOLD); |
| 205 | + // 2 instruction + 1 tool → still 2 instruction → full mode |
| 206 | + assert!( |
| 207 | + tool_injection.contains("<skills>"), |
| 208 | + "tool-kind should not count toward threshold" |
| 209 | + ); |
| 210 | + assert!( |
| 211 | + !tool_injection.contains("my-tool"), |
| 212 | + "tool-kind should not appear in injection" |
| 213 | + ); |
| 214 | + println!(" [ok] Tool-kind skills excluded from injection"); |
| 215 | + println!(" [ok] Tool-kind does not affect threshold count"); |
| 216 | + println!(); |
| 217 | + |
| 218 | + // ── Done ───────────────────────────────────────────────────────────── |
| 219 | + println!("=== All checks passed ==="); |
| 220 | +} |
0 commit comments