use crate::generator::research::memory::MemoryScope;
use crate::generator::research::types::{AgentType, SystemContextReport};
use crate::generator::step_forward_agent::{
AgentDataConfig, DataSource, FormatterConfig, LLMCallMode, PromptTemplate, StepForwardAgent,
};
#[derive(Default)]
pub struct SystemContextResearcher;
impl StepForwardAgent for SystemContextResearcher {
type Output = SystemContextReport;
fn agent_type(&self) -> String {
AgentType::SystemContextResearcher.to_string()
}
fn agent_type_enum(&self) -> Option<AgentType> {
Some(AgentType::SystemContextResearcher)
}
fn memory_scope_key(&self) -> String {
MemoryScope::STUDIES_RESEARCH.to_string()
}
fn data_config(&self) -> AgentDataConfig {
AgentDataConfig {
required_sources: vec![DataSource::PROJECT_STRUCTURE, DataSource::CODE_INSIGHTS],
optional_sources: vec![
DataSource::README_CONTENT,
DataSource::knowledge_categories(vec!["architecture", "adr"]),
],
}
}
fn prompt_template(&self) -> PromptTemplate {
PromptTemplate {
system_prompt: r#"You are a professional software architecture analyst, specializing in project objective and system boundary analysis.
Analyze the project to determine:
1. Core objectives and business value
2. Project type and tech stack
3. Target users and use cases
4. External system dependencies
5. System boundaries (what's in/out of scope)
When external documentation is provided:
- Cross-reference code against documented architecture
- Flag gaps between docs and implementation
- Use established business terminology
Rrequired output style (extremely important):
- Plain English, short sentences
- No filler phrases ("it is important to note", "in order to")
- No repetition - state each point once
- Concrete specifics over vague generalities
- If uncertain, say so briefly rather than padding
You MUST output strict JSON only (no markdown, no code fences, no prose outside JSON).
The output must be valid, parseable JSON with these exact fields:
Required JSON fields:
- project_name: string
- project_description: string
- project_type: one of FrontendApp|BackendService|FullStackApp|ComponentLibrary|Framework|CLITool|MobileApp|DesktopApp|Other
- business_value: string
- target_users: array of {name: string, description: string, needs: array of string}
- external_systems: array of {name: string, description: string, interaction_type: string}
- system_boundary: OBJECT with {scope: string, included_components: array of string, excluded_components: array of string}
- confidence_score: number between 0.0 and 10.0
CRITICAL RULES:
- system_boundary must be a JSON OBJECT, NOT a string
- Do NOT stringify or escape nested objects
- Do NOT use code fences or markdown formatting around JSON
- Always output all fields, use empty arrays/strings if unknown
- confidence_score must be a number, not a string
Generate Output as JSON per existing schema."#
.to_string(),
opening_instruction: "Based on the following research materials, analyze the project's core objectives and system positioning:".to_string(),
closing_instruction: r#"
## Analysis Requirements:
- Accurately identify project type and technical characteristics
- Clearly define target users and usage scenarios
- Clearly delineate system boundaries
- If external documentation is provided, validate code structure against it
- Identify any gaps between documented architecture and actual implementation
- Ensure analysis results conform to the C4 architecture model's system context level"#
.to_string(),
llm_call_mode: LLMCallMode::Extract,
formatter_config: FormatterConfig::default(),
}
}
}