MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / derive_name_from_path

Function derive_name_from_path

crates/opencode-config/src/loader.rs:1118–1143  ·  view source on GitHub ↗

Derive a name from a file path relative to the base directory.

(path: &Path, base_dir: &Path, strip_prefixes: &[&str])

Source from the content-addressed store, hash-verified

1116
1117/// Derive a name from a file path relative to the base directory.
1118fn derive_name_from_path(path: &Path, base_dir: &Path, strip_prefixes: &[&str]) -> String {
1119 let rel = path
1120 .strip_prefix(base_dir)
1121 .unwrap_or(path)
1122 .to_string_lossy()
1123 .to_string();
1124
1125 // Strip known directory prefixes
1126 let mut name = rel.as_str();
1127 for prefix in strip_prefixes {
1128 let with_sep = format!("{}/", prefix);
1129 if let Some(stripped) = name.strip_prefix(&with_sep) {
1130 name = stripped;
1131 break;
1132 }
1133 // Also try .opencode/ prefix
1134 let with_opencode = format!(".opencode/{}/", prefix);
1135 if let Some(stripped) = name.strip_prefix(&with_opencode) {
1136 name = stripped;
1137 break;
1138 }
1139 }
1140
1141 // Remove .md extension
1142 name.strip_suffix(".md").unwrap_or(name).to_string()
1143}
1144
1145/// Merge one AgentConfig into another (simple field-level merge).
1146fn merge_agent_config(target: &mut AgentConfig, source: AgentConfig) {

Callers 2

parse_markdown_commandFunction · 0.85
parse_markdown_agentFunction · 0.85

Calls 1

as_strMethod · 0.45

Tested by

no test coverage detected