1- use anyhow:: Result ;
2- use async_trait:: async_trait;
31use crate :: generator:: compose:: memory:: MemoryScope ;
42use crate :: generator:: compose:: types:: AgentType ;
53use crate :: generator:: context:: GeneratorContext ;
64use crate :: generator:: research:: memory:: MemoryRetriever ;
7- use crate :: generator:: research:: types:: { AgentType as ResearchAgentType , BoundaryAnalysisReport , CLIBoundary , APIBoundary , IntegrationSuggestion } ;
5+ use crate :: generator:: research:: types:: {
6+ APIBoundary , AgentType as ResearchAgentType , BoundaryAnalysisReport , CLIBoundary ,
7+ IntegrationSuggestion , RouterBoundary ,
8+ } ;
89use crate :: generator:: step_forward_agent:: {
910 AgentDataConfig , DataSource , PromptTemplate , StepForwardAgent ,
1011} ;
12+ use anyhow:: Result ;
13+ use async_trait:: async_trait;
1114
1215/// 边界接口文档编辑器 - 将边界分析结果编排为标准化文档
1316#[ derive( Default ) ]
@@ -25,6 +28,10 @@ impl StepForwardAgent for BoundaryEditor {
2528 MemoryScope :: DOCUMENTATION . to_string ( )
2629 }
2730
31+ fn should_include_timestamp ( & self ) -> bool {
32+ true
33+ }
34+
2835 fn data_config ( & self ) -> AgentDataConfig {
2936 AgentDataConfig {
3037 required_sources : vec ! [ ] ,
@@ -98,26 +105,38 @@ impl BoundaryEditor {
98105 fn generate_boundary_documentation ( & self , report : & BoundaryAnalysisReport ) -> String {
99106 let mut content = String :: new ( ) ;
100107 content. push_str ( "# 系统边界接口文档\n \n " ) ;
101- content. push_str ( "本文档描述了系统的外部调用接口,包括CLI命令、API端点、配置参数等边界机制。\n \n " ) ;
102-
108+ content. push_str (
109+ "本文档描述了系统的外部调用接口,包括CLI命令、API端点、配置参数等边界机制。\n \n " ,
110+ ) ;
111+
103112 // 生成CLI接口文档
104113 if !report. cli_boundaries . is_empty ( ) {
105114 content. push_str ( & self . generate_cli_documentation ( & report. cli_boundaries ) ) ;
106115 }
107-
116+
108117 // 生成API接口文档
109118 if !report. api_boundaries . is_empty ( ) {
110119 content. push_str ( & self . generate_api_documentation ( & report. api_boundaries ) ) ;
111120 }
112-
121+
122+ // 生成Router路由文档
123+ if !report. router_boundaries . is_empty ( ) {
124+ content. push_str ( & self . generate_router_documentation ( & report. router_boundaries ) ) ;
125+ }
126+
113127 // 生成集成建议
114128 if !report. integration_suggestions . is_empty ( ) {
115- content. push_str ( & self . generate_integration_documentation ( & report. integration_suggestions ) ) ;
129+ content. push_str (
130+ & self . generate_integration_documentation ( & report. integration_suggestions ) ,
131+ ) ;
116132 }
117133
118134 // 添加分析置信度
119- content. push_str ( & format ! ( "\n ---\n \n **分析置信度**: {:.1}/10\n " , report. confidence_score) ) ;
120-
135+ content. push_str ( & format ! (
136+ "\n ---\n \n **分析置信度**: {:.1}/10\n " ,
137+ report. confidence_score
138+ ) ) ;
139+
121140 content
122141 }
123142
@@ -128,102 +147,143 @@ impl BoundaryEditor {
128147
129148 let mut content = String :: new ( ) ;
130149 content. push_str ( "## 命令行接口 (CLI)\n \n " ) ;
131-
150+
132151 for cli in cli_boundaries {
133152 content. push_str ( & format ! ( "### {}\n \n " , cli. command) ) ;
134153 content. push_str ( & format ! ( "**描述**: {}\n \n " , cli. description) ) ;
135154 content. push_str ( & format ! ( "**源文件**: `{}`\n \n " , cli. source_location) ) ;
136-
155+
137156 if !cli. arguments . is_empty ( ) {
138157 content. push_str ( "**参数**:\n \n " ) ;
139158 for arg in & cli. arguments {
140159 let required_text = if arg. required { "必需" } else { "可选" } ;
141- let default_text = arg. default_value . as_ref ( )
160+ let default_text = arg
161+ . default_value
162+ . as_ref ( )
142163 . map ( |v| format ! ( " (默认: `{}`)" , v) )
143164 . unwrap_or_default ( ) ;
144165 content. push_str ( & format ! (
145- "- `{}` ({}): {} - {}{}\n " ,
166+ "- `{}` ({}): {} - {}{}\n " ,
146167 arg. name, arg. value_type, required_text, arg. description, default_text
147168 ) ) ;
148169 }
149170 content. push_str ( "\n " ) ;
150171 }
151-
172+
152173 if !cli. options . is_empty ( ) {
153174 content. push_str ( "**选项**:\n \n " ) ;
154175 for option in & cli. options {
155- let short_text = option. short_name . as_ref ( )
176+ let short_text = option
177+ . short_name
178+ . as_ref ( )
156179 . map ( |s| format ! ( ", {}" , s) )
157180 . unwrap_or_default ( ) ;
158181 let required_text = if option. required { "必需" } else { "可选" } ;
159- let default_text = option. default_value . as_ref ( )
182+ let default_text = option
183+ . default_value
184+ . as_ref ( )
160185 . map ( |v| format ! ( " (默认: `{}`)" , v) )
161186 . unwrap_or_default ( ) ;
162187 content. push_str ( & format ! (
163- "- `{}{}`({}): {} - {}{}\n " ,
164- option. name, short_text, option. value_type, required_text, option. description, default_text
188+ "- `{}{}`({}): {} - {}{}\n " ,
189+ option. name,
190+ short_text,
191+ option. value_type,
192+ required_text,
193+ option. description,
194+ default_text
165195 ) ) ;
166196 }
167197 content. push_str ( "\n " ) ;
168198 }
169-
199+
170200 if !cli. examples . is_empty ( ) {
171201 content. push_str ( "**使用示例**:\n \n " ) ;
172202 for example in & cli. examples {
173203 content. push_str ( & format ! ( "```bash\n {}\n ```\n \n " , example) ) ;
174204 }
175205 }
176206 }
177-
207+
178208 content
179209 }
180-
210+
181211 fn generate_api_documentation ( & self , api_boundaries : & [ APIBoundary ] ) -> String {
182212 if api_boundaries. len ( ) == 0 {
183213 return String :: new ( ) ;
184214 }
185215
186216 let mut content = String :: new ( ) ;
187217 content. push_str ( "## API接口\n \n " ) ;
188-
218+
189219 for api in api_boundaries {
190220 content. push_str ( & format ! ( "### {} {}\n \n " , api. method, api. endpoint) ) ;
191221 content. push_str ( & format ! ( "**描述**: {}\n \n " , api. description) ) ;
192222 content. push_str ( & format ! ( "**源文件**: `{}`\n \n " , api. source_location) ) ;
193-
223+
194224 if let Some ( request_format) = & api. request_format {
195225 content. push_str ( & format ! ( "**请求格式**: {}\n \n " , request_format) ) ;
196226 }
197-
227+
198228 if let Some ( response_format) = & api. response_format {
199229 content. push_str ( & format ! ( "**响应格式**: {}\n \n " , response_format) ) ;
200230 }
201-
231+
202232 if let Some ( auth) = & api. authentication {
203233 content. push_str ( & format ! ( "**认证方式**: {}\n \n " , auth) ) ;
204234 }
205235 }
206-
236+
237+ content
238+ }
239+
240+ fn generate_router_documentation ( & self , router_boundaries : & [ RouterBoundary ] ) -> String {
241+ if router_boundaries. len ( ) == 0 {
242+ return String :: new ( ) ;
243+ }
244+
245+ let mut content = String :: new ( ) ;
246+ content. push_str ( "## Router路由\n \n " ) ;
247+
248+ for router in router_boundaries {
249+ content. push_str ( & format ! ( "### {}\n \n " , router. path) ) ;
250+ content. push_str ( & format ! ( "**描述**: {}\n \n " , router. description) ) ;
251+ content. push_str ( & format ! ( "**源文件**: `{}`\n \n " , router. source_location) ) ;
252+
253+ if !router. params . is_empty ( ) {
254+ content. push_str ( "**参数**:\n \n " ) ;
255+ for param in & router. params {
256+ content. push_str ( & format ! (
257+ "- `{}` ({}): {}\n " ,
258+ param. key, param. value_type, param. description
259+ ) ) ;
260+ }
261+ }
262+ }
263+
207264 content
208265 }
209266
210- fn generate_integration_documentation ( & self , integration_suggestions : & [ IntegrationSuggestion ] ) -> String {
267+ fn generate_integration_documentation (
268+ & self ,
269+ integration_suggestions : & [ IntegrationSuggestion ] ,
270+ ) -> String {
211271 if integration_suggestions. len ( ) == 0 {
212272 return String :: new ( ) ;
213273 }
214274
215275 let mut content = String :: new ( ) ;
216276 content. push_str ( "## 集成建议\n \n " ) ;
217-
277+
218278 for suggestion in integration_suggestions {
219279 content. push_str ( & format ! ( "### {}\n \n " , suggestion. integration_type) ) ;
220280 content. push_str ( & format ! ( "{}\n \n " , suggestion. description) ) ;
221-
281+
222282 if !suggestion. example_code . is_empty ( ) {
223283 content. push_str ( "**示例代码**:\n \n " ) ;
224284 content. push_str ( & format ! ( "```\n {}\n ```\n \n " , suggestion. example_code) ) ;
225285 }
226-
286+
227287 if !suggestion. best_practices . is_empty ( ) {
228288 content. push_str ( "**最佳实践**:\n \n " ) ;
229289 for practice in & suggestion. best_practices {
@@ -232,7 +292,7 @@ impl BoundaryEditor {
232292 content. push_str ( "\n " ) ;
233293 }
234294 }
235-
295+
236296 content
237297 }
238- }
298+ }
0 commit comments