Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 19 additions & 0 deletions src/crates/assembly/core/src/agentic/agents/registry/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,25 @@ impl AgentRegistry {
None
}

pub async fn get_subagent_is_review_for_workspace(
&self,
id: &str,
workspace_root: Option<&Path>,
) -> Option<bool> {
self.ensure_user_custom_agents_loaded().await;
if let Some(workspace_root) = workspace_root {
let is_project_cache_loaded =
self.read_project_subagents().contains_key(workspace_root);
if !is_project_cache_loaded {
self.load_custom_agents(Some(workspace_root)).await;
}
}

self.find_agent_entry(id, workspace_root)
.filter(|entry| entry.category == AgentCategory::SubAgent)
.map(|entry| is_review_agent_entry(&entry))
}

fn entry_is_visible_for_query(
entry: &AgentEntry,
query: &SubagentQueryContext<'_>,
Expand Down
104 changes: 104 additions & 0 deletions src/crates/assembly/core/src/agentic/agents/registry/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,30 @@ fn test_project_entry(id: &str, model: &str) -> AgentEntry {
}
}

fn test_project_custom_entry(id: &str, review: bool) -> AgentEntry {
let mut agent = CustomSubagent::new(
id.to_string(),
"Project custom subagent".to_string(),
vec!["Read".to_string()],
"prompt".to_string(),
review,
format!("{id}.md"),
CustomSubagentKind::Project,
);
agent.data.review = review;

AgentEntry {
category: AgentCategory::SubAgent,
source: AgentSource::Project,
subagent_source: Some(SubAgentSource::Project),
agent: Arc::new(agent),
visibility_policy: SubagentVisibilityPolicy::public(),
custom_config: Some(CustomSubagentConfig {
model: "fast".to_string(),
}),
}
}

fn insert_project_subagent(registry: &AgentRegistry, workspace: &Path, id: &str, model: &str) {
let mut entries = HashMap::new();
entries.insert(id.to_string(), test_project_entry(id, model));
Expand All @@ -77,6 +101,67 @@ fn insert_project_subagent(registry: &AgentRegistry, workspace: &Path, id: &str,
.insert(workspace.to_path_buf(), entries);
}

#[tokio::test]
async fn review_lookup_is_scoped_to_the_requested_workspace() {
let registry = AgentRegistry::new();
let review_workspace = PathBuf::from("review-workspace");
let ordinary_workspace = PathBuf::from("ordinary-workspace");
let agent_id = "SharedProjectAgent";

registry.write_project_subagents().insert(
review_workspace.clone(),
HashMap::from([(
agent_id.to_string(),
test_project_custom_entry(agent_id, true),
)]),
);
registry.write_project_subagents().insert(
ordinary_workspace.clone(),
HashMap::from([(
agent_id.to_string(),
test_project_custom_entry(agent_id, false),
)]),
);

assert_eq!(
registry
.get_subagent_is_review_for_workspace(agent_id, Some(&review_workspace))
.await,
Some(true)
);
assert_eq!(
registry
.get_subagent_is_review_for_workspace(agent_id, Some(&ordinary_workspace))
.await,
Some(false)
);
assert_eq!(
registry
.get_subagent_is_review_for_workspace(agent_id, None)
.await,
None,
"a project agent must not leak into an unrelated workspace lookup"
);
}

#[tokio::test]
async fn review_lookup_cold_loads_the_requested_project_registry() {
let env = CustomAgentTestEnv::new("bitfun-project-review-lookup");
let registry = AgentRegistry::new();
let agent_id = "ProjectReviewer";
write_project_custom_review_subagent(
&env.workspace_agents_dir.join("project-reviewer.md"),
agent_id,
);

assert_eq!(
registry
.get_subagent_is_review_for_workspace(agent_id, Some(&env.workspace_root))
.await,
Some(true)
);
}

#[test]
fn top_level_modes_default_to_auto() {
for agent_type in [
Expand Down Expand Up @@ -942,6 +1027,25 @@ fn write_project_custom_subagent(path: &Path, id: &str) {
.expect("project subagent markdown should save");
}

fn write_project_custom_review_subagent(path: &Path, id: &str) {
let mut subagent = CustomSubagent::new_with_id(
id.to_string(),
id.to_string(),
"Project review subagent".to_string(),
vec!["Read".to_string()],
"Review the relevant files.".to_string(),
true,
path.to_string_lossy().to_string(),
CustomSubagentKind::Project,
"fast".to_string(),
UserContextPolicy::empty().with_workspace_instructions(),
);
subagent.data.review = true;
subagent
.save_to_file(None)
.expect("project review subagent markdown should save");
}

fn unique_suffix() -> String {
use std::time::{SystemTime, UNIX_EPOCH};

Expand Down
Loading
Loading