mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-08-04 03:32:25 +08:00
8383076791
* fix(hermes): use SOUL.md instead of AGENTS.md for Hermes prompt filename * test(hermes): add regression test for SOUL.md prompt filename --------- Co-authored-by: mmm-05610 <maoqh@users.noreply.github.com> Co-authored-by: Jason <farion1231@gmail.com>
75 lines
2.5 KiB
Rust
75 lines
2.5 KiB
Rust
use std::path::PathBuf;
|
|
|
|
use crate::app_config::AppType;
|
|
use crate::codex_config::get_codex_auth_path;
|
|
use crate::config::get_claude_settings_path;
|
|
use crate::error::AppError;
|
|
use crate::gemini_config::get_gemini_dir;
|
|
use crate::openclaw_config::get_openclaw_dir;
|
|
use crate::opencode_config::get_opencode_dir;
|
|
|
|
/// 返回指定应用所使用的提示词文件路径。
|
|
pub fn prompt_file_path(app: &AppType) -> Result<PathBuf, AppError> {
|
|
if matches!(app, AppType::ClaudeDesktop) {
|
|
return Err(AppError::localized(
|
|
"app.prompts_unsupported",
|
|
"当前应用暂不支持 Prompts",
|
|
"This app does not support Prompts",
|
|
));
|
|
}
|
|
|
|
let base_dir: PathBuf = match app {
|
|
AppType::Claude => get_base_dir_with_fallback(get_claude_settings_path(), ".claude")?,
|
|
AppType::Codex => get_base_dir_with_fallback(get_codex_auth_path(), ".codex")?,
|
|
AppType::Gemini => get_gemini_dir(),
|
|
AppType::GrokBuild => crate::grok_config::get_grok_config_dir(),
|
|
AppType::OpenCode => get_opencode_dir(),
|
|
AppType::OpenClaw => get_openclaw_dir(),
|
|
AppType::Hermes => crate::hermes_config::get_hermes_dir(),
|
|
AppType::ClaudeDesktop => unreachable!("handled above"),
|
|
};
|
|
|
|
let filename = match app {
|
|
AppType::Claude => "CLAUDE.md",
|
|
AppType::Codex => "AGENTS.md",
|
|
AppType::Gemini => "GEMINI.md",
|
|
AppType::GrokBuild | AppType::OpenCode | AppType::OpenClaw => "AGENTS.md",
|
|
AppType::Hermes => "SOUL.md",
|
|
AppType::ClaudeDesktop => unreachable!("handled above"),
|
|
};
|
|
|
|
Ok(base_dir.join(filename))
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn hermes_prompt_file_uses_soul_md() {
|
|
let path = prompt_file_path(&AppType::Hermes).expect("Hermes prompt path");
|
|
|
|
assert_eq!(
|
|
path.file_name().and_then(|name| name.to_str()),
|
|
Some("SOUL.md")
|
|
);
|
|
}
|
|
}
|
|
|
|
fn get_base_dir_with_fallback(
|
|
primary_path: PathBuf,
|
|
fallback_dir: &str,
|
|
) -> Result<PathBuf, AppError> {
|
|
primary_path
|
|
.parent()
|
|
.map(|p| p.to_path_buf())
|
|
.or_else(|| dirs::home_dir().map(|h| h.join(fallback_dir)))
|
|
.ok_or_else(|| {
|
|
AppError::localized(
|
|
"home_dir_not_found",
|
|
format!("无法确定 {fallback_dir} 配置目录:用户主目录不存在"),
|
|
format!("Cannot determine {fallback_dir} config directory: user home not found"),
|
|
)
|
|
})
|
|
}
|