Skip to content

Commit 6cff713

Browse files
committed
Create default gooseignore file when missing
Signed-off-by: Matt Joyce <matt.joyce@gmail.com>
1 parent d923b32 commit 6cff713

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

crates/goose-mcp/src/developer/rmcp_developer.rs

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ pub struct PromptArgumentTemplate {
121121
// Embeds the prompts directory to the build
122122
static PROMPTS_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/src/developer/prompts");
123123

124+
const DEFAULT_GOOSEIGNORE_CONTENT: &str = "**/.env\n**/.env.*\n**/secrets.*\n";
125+
124126
/// Loads prompt files from the embedded PROMPTS_DIR and returns a HashMap of prompts.
125127
/// Ensures that each prompt name is unique.
126128
fn load_prompt_files() -> HashMap<String, Prompt> {
@@ -1295,12 +1297,34 @@ impl DeveloperServer {
12951297
.map(|strategy| strategy.config_dir().join(".gooseignore"))
12961298
.ok();
12971299

1298-
let has_local_ignore = local_ignore_path.is_file();
1300+
let mut has_local_ignore = local_ignore_path.is_file();
12991301
let has_global_ignore = global_ignore_path
13001302
.as_ref()
13011303
.map(|p| p.is_file())
13021304
.unwrap_or(false);
13031305

1306+
if !has_local_ignore && !has_global_ignore {
1307+
match std::fs::write(&local_ignore_path, DEFAULT_GOOSEIGNORE_CONTENT) {
1308+
Ok(_) => {
1309+
has_local_ignore = true;
1310+
}
1311+
Err(err) => {
1312+
tracing::warn!(
1313+
"Failed to create default .gooseignore at {}: {}",
1314+
local_ignore_path.display(),
1315+
err
1316+
);
1317+
1318+
for pattern in DEFAULT_GOOSEIGNORE_CONTENT.lines() {
1319+
if pattern.is_empty() {
1320+
continue;
1321+
}
1322+
let _ = builder.add_line(None, pattern);
1323+
}
1324+
}
1325+
}
1326+
}
1327+
13041328
if has_global_ignore {
13051329
let _ = builder.add(global_ignore_path.as_ref().unwrap());
13061330
}
@@ -1309,12 +1333,6 @@ impl DeveloperServer {
13091333
let _ = builder.add(&local_ignore_path);
13101334
}
13111335

1312-
if !has_local_ignore && !has_global_ignore {
1313-
let _ = builder.add_line(None, "**/.env");
1314-
let _ = builder.add_line(None, "**/.env.*");
1315-
let _ = builder.add_line(None, "**/secrets.*");
1316-
}
1317-
13181336
builder.build().expect("Failed to build ignore patterns")
13191337
}
13201338

@@ -3236,6 +3254,14 @@ mod tests {
32363254
// Don't create any ignore files
32373255
let server = create_test_server();
32383256

3257+
let gooseignore_path = temp_dir.path().join(".gooseignore");
3258+
assert!(
3259+
gooseignore_path.exists(),
3260+
".gooseignore should be created by default"
3261+
);
3262+
let default_contents = fs::read_to_string(gooseignore_path).unwrap();
3263+
assert_eq!(default_contents, DEFAULT_GOOSEIGNORE_CONTENT);
3264+
32393265
// Default patterns should be used
32403266
assert!(
32413267
server.is_ignored(Path::new(".env")),

0 commit comments

Comments
 (0)