Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/goose/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ gethostname = "1.1.0"
[target.'cfg(target_os = "windows")'.dependencies]
winapi = { workspace = true, features = ["accctrl", "aclapi", "fileapi", "handleapi", "minwinbase", "sddl", "securitybaseapi", "winbase", "winerror"] }
keyring = { workspace = true, features = ["windows-native"], optional = true }
ntapi = { version = "0.4.3", default-features = false }

# Platform-specific GPU acceleration for Whisper and local inference
[target.'cfg(target_os = "macos")'.dependencies]
Expand Down
4 changes: 2 additions & 2 deletions crates/goose/src/agents/large_response_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::io::Write;

const DEFAULT_LARGE_TEXT_THRESHOLD: usize = 200_000;

fn large_text_threshold() -> usize {
pub(crate) fn max_tool_response_size() -> usize {
Config::global()
.get_param::<usize>("GOOSE_MAX_TOOL_RESPONSE_SIZE")
.unwrap_or(DEFAULT_LARGE_TEXT_THRESHOLD)
Expand All @@ -14,7 +14,7 @@ fn large_text_threshold() -> usize {
pub fn process_tool_response(
response: Result<CallToolResult, ErrorData>,
) -> Result<CallToolResult, ErrorData> {
let threshold = large_text_threshold();
let threshold = max_tool_response_size();
match response {
Ok(mut result) => {
let mut processed_contents = Vec::new();
Expand Down
1 change: 1 addition & 0 deletions crates/goose/src/agents/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub use execute_commands::{context_management_unsupported_message, COMPACT_TRIGG
pub use extension::{ExtensionConfig, ExtensionError};
pub use extension_manager::ExtensionManager;
pub use goose_agent::events::AgentEvent;
pub(crate) use large_response_handler::max_tool_response_size;
pub use prompt_manager::PromptManager;
pub use schedule_tool::ScheduleTool;
pub use subagent_handler::SUBAGENT_TOOL_REQUEST_TYPE;
Expand Down
54 changes: 37 additions & 17 deletions crates/goose/src/agents/state_machine/ops_skills.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ fn load_supporting_file(
relative_path: &str,
) -> CallToolResult {
let skill_dir = PathBuf::from(&skill.path);
let canonical_skill_dir = skill_dir
.canonicalize()
.unwrap_or_else(|_| skill_dir.clone());
for file_path in &skill.supporting_files {
let file_path = Path::new(file_path);
let Ok(relative) = file_path.strip_prefix(&skill_dir) else {
Expand All @@ -157,22 +154,12 @@ fn load_supporting_file(
if relative.to_string_lossy().replace('\\', "/") != relative_path {
continue;
}
return match file_path.canonicalize() {
Ok(canonical) if canonical.starts_with(&canonical_skill_dir) => {
match std::fs::read_to_string(&canonical) {
Ok(content) => CallToolResult::success(vec![ContentBlock::text(format!(
"# Loaded: {skill_name}\n\n{content}\n\n---\nFile loaded into context."
))]),
Err(error) => CallToolResult::error(vec![ContentBlock::text(format!(
"Failed to read '{skill_name}': {error}"
))]),
}
}
Ok(_) => CallToolResult::error(vec![ContentBlock::text(format!(
"Refusing to load '{skill_name}': resolves outside the skill directory"
return match crate::skills::read_supporting_file(&skill_dir, relative) {
Ok(content) => CallToolResult::success(vec![ContentBlock::text(format!(
"# Loaded: {skill_name}\n\n{content}\n\n---\nFile loaded into context."
))]),
Err(error) => CallToolResult::error(vec![ContentBlock::text(format!(
"Failed to resolve '{skill_name}': {error}"
"Failed to read '{skill_name}': {error}"
))]),
};
}
Expand Down Expand Up @@ -360,3 +347,36 @@ impl Operation<Session, GooseEffect> for SkillOperation {
applied([response.into()])
}
}

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

#[test]
fn supporting_file_loader_reads_nested_regular_file() {
let root = tempfile::tempdir().unwrap();
let skill_dir = std::fs::canonicalize(root.path()).unwrap();
let nested = skill_dir.join("nested");
std::fs::create_dir(&nested).unwrap();
let file = nested.join("guide.md");
std::fs::write(&file, "Nested guidance.").unwrap();
let skill = SourceEntry {
source_type: SourceType::Skill,
name: "test-skill".to_string(),
description: String::new(),
content: String::new(),
path: skill_dir.to_string_lossy().into_owned(),
global: false,
writable: true,
supporting_files: vec![file.to_string_lossy().into_owned()],
properties: HashMap::new(),
};

let result = load_supporting_file(&skill, "test-skill/nested/guide.md", "nested/guide.md");

assert_eq!(result.is_error, Some(false));
let text = result.content[0].as_text().expect("expected text");
assert!(text.text.contains("Nested guidance."));
}
}
44 changes: 22 additions & 22 deletions crates/goose/src/skills/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@ impl McpClientTrait for SkillsClient {
&& matches!(s.source_type, SourceType::Skill | SourceType::BuiltinSkill)
}) {
let skill_dir = PathBuf::from(&skill.path);
let canonical_skill_dir = skill_dir
.canonicalize()
.unwrap_or_else(|_| skill_dir.clone());

for file_path in &skill.supporting_files {
let file_path_buf = Path::new(file_path);
Expand All @@ -162,27 +159,13 @@ impl McpClientTrait for SkillsClient {
continue;
}

return Ok(match file_path_buf.canonicalize() {
Ok(canonical) if canonical.starts_with(&canonical_skill_dir) => {
match std::fs::read_to_string(&canonical) {
Ok(content) => {
CallToolResult::success(vec![ContentBlock::text(format!(
"# Loaded: {}\n\n{}\n\n---\nFile loaded into context.",
skill_name, content
))])
}
Err(e) => CallToolResult::error(vec![ContentBlock::text(format!(
"Failed to read '{}': {}",
skill_name, e
))]),
}
}
Ok(_) => CallToolResult::error(vec![ContentBlock::text(format!(
"Refusing to load '{}': resolves outside the skill directory",
skill_name
return Ok(match super::read_supporting_file(&skill_dir, rel) {
Ok(content) => CallToolResult::success(vec![ContentBlock::text(format!(
"# Loaded: {}\n\n{}\n\n---\nFile loaded into context.",
skill_name, content
))]),
Err(e) => CallToolResult::error(vec![ContentBlock::text(format!(
"Failed to resolve '{}': {}",
"Failed to read '{}': {}",
skill_name, e
))]),
});
Expand Down Expand Up @@ -289,6 +272,8 @@ mod tests {
"---\nname: my-skill\ndescription: A test skill\n---\nDo the thing.",
)
.unwrap();
fs::create_dir(skill_dir.join("nested")).unwrap();
fs::write(skill_dir.join("nested/guide.md"), "Nested guidance.").unwrap();

let session = std::sync::Arc::new(crate::session::Session {
working_dir: temp_dir.path().to_path_buf(),
Expand Down Expand Up @@ -324,6 +309,21 @@ mod tests {
};
assert!(text.contains("my-skill"));
assert!(text.contains("Do the thing"));

let args: JsonObject =
serde_json::from_value(serde_json::json!({"name": "my-skill/nested/guide.md"}))
.unwrap();
let result = client
.call_tool(&ctx, "load_skill", Some(args), CancellationToken::new())
.await
.unwrap();

assert!(!result.is_error.unwrap_or(false));
let text = match &result.content[0] {
rmcp::model::ContentBlock::Text(t) => &t.text,
_ => panic!("expected text"),
};
assert!(text.contains("Nested guidance."));
}

#[tokio::test]
Expand Down
16 changes: 14 additions & 2 deletions crates/goose/src/skills/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
mod arguments;
mod builtin;
pub mod client;
mod supporting_files;

pub use client::{SkillsClient, EXTENSION_NAME};
pub(crate) use supporting_files::read_supporting_file;

use crate::config::{paths::Paths, Config};
use crate::plugins::installed_plugin_skill_dirs;
Expand Down Expand Up @@ -442,6 +444,9 @@ fn scan_skills_from_dir(dir: &Path, global: bool, seen: &mut HashSet<String>) ->
let Some(skill_dir) = skill_file.parent() else {
continue;
};
let Ok(registered_skill_dir) = skill_dir.canonicalize() else {
continue;
};
let content = match std::fs::read_to_string(&skill_file) {
Ok(c) => c,
Err(e) => {
Expand All @@ -450,7 +455,7 @@ fn scan_skills_from_dir(dir: &Path, global: bool, seen: &mut HashSet<String>) ->
}
};

if let Some(mut source) = parse_skill_content(&content, skill_dir, global) {
if let Some(mut source) = parse_skill_content(&content, &registered_skill_dir, global) {
if !seen.contains(&source.name) {
let mut files = Vec::new();
let mut visited_support_dirs = HashSet::new();
Expand All @@ -460,7 +465,14 @@ fn scan_skills_from_dir(dir: &Path, global: bool, seen: &mut HashSet<String>) ->
&mut |path| !should_skip_dir(path) && !path.join("SKILL.md").is_file(),
&mut |path| {
if path.file_name().and_then(|n| n.to_str()) != Some("SKILL.md") {
files.push(path.to_string_lossy().into_owned());
if let Ok(relative) = path.strip_prefix(skill_dir) {
files.push(
registered_skill_dir
.join(relative)
.to_string_lossy()
.into_owned(),
);
}
}
},
);
Expand Down
Loading
Loading