Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 44 additions & 11 deletions crates/agent_skills/agent_skills.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,17 +242,7 @@ pub fn parse_skill_frontmatter(
content: &str,
source: SkillSource,
) -> Result<Skill> {
if content.len() > MAX_SKILL_FILE_SIZE {
anyhow::bail!(
"SKILL.md file exceeds maximum size of {}KB",
MAX_SKILL_FILE_SIZE / 1024
);
}

let (metadata, _body) = extract_frontmatter(content)?;

validate_name(&metadata.name).map_err(anyhow::Error::msg)?;
validate_description(&metadata.description).map_err(anyhow::Error::msg)?;
let (metadata, _body) = parse_skill_file_content(content)?;

let directory_path = skill_file_path
.parent()
Expand All @@ -270,6 +260,29 @@ pub fn parse_skill_frontmatter(
})
}

/// Extract the YAML frontmatter and body from a SKILL.md file without
/// validating the metadata fields.
pub fn extract_skill_frontmatter(content: &str) -> Result<(SkillMetadata, &str)> {
if content.len() > MAX_SKILL_FILE_SIZE {
anyhow::bail!(
"SKILL.md file exceeds maximum size of {}KB",
MAX_SKILL_FILE_SIZE / 1024
);
}

extract_frontmatter(content)
}

/// Parse and validate the YAML frontmatter and body from a SKILL.md file.
pub fn parse_skill_file_content(content: &str) -> Result<(SkillMetadata, &str)> {
let (metadata, body) = extract_skill_frontmatter(content)?;

validate_name(&metadata.name).map_err(anyhow::Error::msg)?;
validate_description(&metadata.description).map_err(anyhow::Error::msg)?;

Ok((metadata, body))
}

fn extract_frontmatter(content: &str) -> Result<(SkillMetadata, &str)> {
let content = content.trim_start();

Expand Down Expand Up @@ -849,6 +862,26 @@ Do the thing.
assert!(!skill.disable_model_invocation);
}

#[test]
fn test_parse_skill_file_content_returns_body() {
let content = r#"---
name: my-skill
description: A test skill for testing purposes
---

# My Skill

Do the thing.
"#;

let (metadata, body) = parse_skill_file_content(content)
.expect("valid skill content should parse successfully");

assert_eq!(metadata.name, "my-skill");
assert_eq!(metadata.description, "A test skill for testing purposes");
assert_eq!(body.trim(), "# My Skill\n\nDo the thing.");
}

#[test]
fn test_parse_disable_model_invocation_true() {
let content = r#"---
Expand Down
38 changes: 34 additions & 4 deletions crates/agent_ui/src/agent_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ use zed_actions::{
ResetAgentZoom, ResetOnboarding, ResolveConflictedFilesWithAgent,
ResolveConflictsWithAgent, ReviewBranchDiff,
},
assistant::{FocusAgent, OpenRulesLibrary, OpenSkillCreator, Toggle, ToggleFocus},
assistant::{
CreateSkillFromUrl, FocusAgent, OpenRulesLibrary, OpenSkillCreator, Toggle, ToggleFocus,
},
};

use crate::ExpandMessageEditor;
Expand Down Expand Up @@ -75,7 +77,7 @@ use project::{Project, ProjectPath, Worktree};
use prompt_store::PromptStore;
use settings::TerminalDockPosition;
use settings::{NotifyWhenAgentWaiting, Settings, update_settings_file};
use skill_creator::open_skill_creator;
use skill_creator::{SkillCreatorOpenMode, is_supported_skill_url, open_skill_creator};
use terminal::{Event as TerminalEvent, terminal_settings::TerminalSettings};
use terminal_view::{TerminalView, terminal_panel::TerminalPanel};
use theme_settings::ThemeSettings;
Expand Down Expand Up @@ -321,6 +323,14 @@ pub fn init(cx: &mut App) {
});
}
})
.register_action(|workspace, action: &CreateSkillFromUrl, window, cx| {
if let Some(panel) = workspace.panel::<AgentPanel>(cx) {
workspace.focus_panel::<AgentPanel>(window, cx);
panel.update(cx, |panel, cx| {
panel.deploy_skill_creator_from_url(action, window, cx)
});
}
})
.register_action(|workspace, _: &Follow, window, cx| {
workspace.follow(CollaboratorId::Agent, window, cx);
})
Expand Down Expand Up @@ -3080,8 +3090,27 @@ impl AgentPanel {
_window: &mut Window,
cx: &mut Context<Self>,
) {
self.open_skill_creator(SkillCreatorOpenMode::Form, cx);
}

fn deploy_skill_creator_from_url(
&mut self,
_action: &CreateSkillFromUrl,
_window: &mut Window,
cx: &mut Context<Self>,
) {
let initial_url = cx
.read_from_clipboard()
.and_then(|clipboard| clipboard.text())
.map(|text| text.trim().to_string())
.filter(|text| is_supported_skill_url(text));

self.open_skill_creator(SkillCreatorOpenMode::Url { initial_url }, cx);
}

fn open_skill_creator(&mut self, open_mode: SkillCreatorOpenMode, cx: &mut Context<Self>) {
let this = cx.weak_entity();
let on_saved = Rc::new(move |cx: &mut App| {
let on_saved: Rc<dyn Fn(&mut App)> = Rc::new(move |cx: &mut App| {
this.update(cx, |this, cx| {
if !this.has_open_project(cx) {
return;
Expand All @@ -3108,13 +3137,14 @@ impl AgentPanel {
})
.detach_and_log_err(cx);
})
.ok();
.log_err();
});

open_skill_creator(
Some(self.workspace.clone()),
self.language_registry.clone(),
self.fs.clone(),
open_mode,
Some(on_saved),
cx,
)
Expand Down
17 changes: 14 additions & 3 deletions crates/agent_ui/src/agent_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,10 @@ fn update_command_palette_filter(cx: &mut App) {
];

let open_rules_library_action = [TypeId::of::<zed_actions::assistant::OpenRulesLibrary>()];
let open_skill_creator_action = [TypeId::of::<zed_actions::assistant::OpenSkillCreator>()];
let skill_creator_actions = [
TypeId::of::<zed_actions::assistant::OpenSkillCreator>(),
TypeId::of::<zed_actions::assistant::CreateSkillFromUrl>(),
];

if disable_ai {
filter.hide_namespace("agent");
Expand Down Expand Up @@ -711,10 +714,10 @@ fn update_command_palette_filter(cx: &mut App) {
// rest of that namespace's actions.
if !disable_ai {
filter.hide_action_types(&open_rules_library_action);
filter.show_action_types(open_skill_creator_action.iter());
filter.show_action_types(skill_creator_actions.iter());
} else {
filter.show_action_types(open_rules_library_action.iter());
filter.hide_action_types(&open_skill_creator_action);
filter.hide_action_types(&skill_creator_actions);
}
});
}
Expand Down Expand Up @@ -856,6 +859,14 @@ mod tests {
!filter.is_hidden(&NewTerminalThread),
"NewTerminalThread should be visible by default"
);
assert!(
!filter.is_hidden(&zed_actions::assistant::OpenSkillCreator),
"OpenSkillCreator should be visible by default"
);
assert!(
!filter.is_hidden(&zed_actions::assistant::CreateSkillFromUrl),
"CreateSkillFromUrl should be visible by default"
);
});

// Disable agent
Expand Down
2 changes: 2 additions & 0 deletions crates/skill_creator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ agent_skills.workspace = true
anyhow.workspace = true
editor.workspace = true
fs.workspace = true
futures.workspace = true
gpui.workspace = true
http_client.workspace = true
language.workspace = true
menu.workspace = true
platform_title_bar.workspace = true
Expand Down
Loading
Loading