diff --git a/src/agent_prompts.rs b/src/agent_prompts.rs new file mode 100644 index 00000000..6f1f0950 --- /dev/null +++ b/src/agent_prompts.rs @@ -0,0 +1,47 @@ +use std::path::PathBuf; + +const AGENTS_DIR: &str = "agents"; + +fn get_agents_dir() -> PathBuf { + let hcom_dir = crate::config::Config::get().hcom_dir; + hcom_dir.join(AGENTS_DIR) +} + +pub fn get_agent_prompt_path(instance_name: &str) -> PathBuf { + get_agents_dir().join(format!("{}.md", instance_name)) +} + +pub fn load_agent_prompt(instance_name: &str) -> Option { + let path = get_agent_prompt_path(instance_name); + if path.exists() { + std::fs::read_to_string(&path).ok().filter(|s| !s.trim().is_empty()) + } else { + None + } +} + +pub fn ensure_agents_dir() -> std::io::Result<()> { + std::fs::create_dir_all(get_agents_dir()) +} + +#[cfg(test)] +mod tests { + use super::*; + use tempfile::TempDir; + + #[test] + fn test_load_nonexistent_returns_none() { + let tmp = TempDir::new().unwrap(); + let path = tmp.path().join("nonexistent.md"); + assert!(!path.exists()); + } + + #[test] + fn test_ensure_agents_dir_creates() { + let tmp = TempDir::new().unwrap(); + let dir = tmp.path().join("agents"); + assert!(!dir.exists()); + std::fs::create_dir_all(&dir).unwrap(); + assert!(dir.exists()); + } +} diff --git a/src/bootstrap.rs b/src/bootstrap.rs index 520823dd..7f8f6d1b 100644 --- a/src/bootstrap.rs +++ b/src/bootstrap.rs @@ -62,9 +62,12 @@ You MUST use `hcom --name {instance_name}` for all hcom commands: - View events: events [--last N] [--all] [--sql EXPR] [filters] Filters (same flag=OR, different=AND): --agent NAME | --type message|status|life | --status listening|active|blocked | --cmd PATTERN (contains, ^prefix, =exact) | --file PATH (*.py for glob, file.py for contains) Event-based notifications, watch agents, subscribe, react: events sub [filters] | --help +- Per-agent system prompts: create `~/.hcom/agents/.md` with the role prompt for any agent (self or spawned) + Then `hcom list -v` confirms if file loaded. Re-injected on every session compaction. - Handoff context: bundle prepare -- Spawn agents: [num] [--tag labelOrGroup] [--terminal tmux|kitty|wezterm|etc] +- Spawn agents: [num] [--tag labelOrGroup] [--agent-name customName] [--terminal tmux|kitty|wezterm|etc] Example: `hcom 1 claude --tag cool` -> automatic msg when ready -> send it task via hcom send + Example: `hcom 1 claude --agent-name mybot` -> named agent, load ~/.hcom/agents/mybot.md as system prompt Resume: hcom r [args] | Fork: hcom f [args] | Kill: hcom kill background, set prompt, system, forward args: --help - Run workflows: run