@@ -113,7 +113,10 @@ pub fn extract_cue(response: &str) -> String {
113113 for marker in & [ "```cue" , "```CUE" , "```" ] {
114114 if let Some ( start) = response. find ( marker) {
115115 let s = start + marker. len ( ) ;
116- let e = response[ s..] . find ( "```" ) . map ( |i| s + i) . unwrap_or ( response. len ( ) ) ;
116+ let e = response[ s..]
117+ . find ( "```" )
118+ . map ( |i| s + i)
119+ . unwrap_or ( response. len ( ) ) ;
117120 let code = response[ s..e] . trim ( ) ;
118121 if code. contains ( "package" ) || code. contains ( "#Blueprint" ) {
119122 return code. to_string ( ) ;
@@ -285,7 +288,8 @@ mod tests {
285288
286289 #[ test]
287290 fn test_extract_cue_from_markdown_block ( ) {
288- let response = "Here is the CUE:\n ```cue\n package blueprints\n x: {name: \" test\" }\n ```\n Done." ;
291+ let response =
292+ "Here is the CUE:\n ```cue\n package blueprints\n x: {name: \" test\" }\n ```\n Done." ;
289293 let cue = extract_cue ( response) ;
290294 assert ! ( cue. contains( "package blueprints" ) ) ;
291295 assert ! ( !cue. contains( "```" ) ) ;
@@ -309,15 +313,33 @@ mod tests {
309313
310314 #[ test]
311315 fn test_render_html_contains_name ( ) {
312- let html = render_html ( "test" , None , "draft" , "2026-01-01" , "2026-01-01" , "in" , "out" , & [ ] ) ;
316+ let html = render_html (
317+ "test" ,
318+ None ,
319+ "draft" ,
320+ "2026-01-01" ,
321+ "2026-01-01" ,
322+ "in" ,
323+ "out" ,
324+ & [ ] ,
325+ ) ;
313326 assert ! ( html. contains( "<title>test — Blueprint</title>" ) ) ;
314327 assert ! ( html. contains( "<h1>test</h1>" ) ) ;
315328 }
316329
317330 #[ test]
318331 fn test_render_html_with_steps ( ) {
319332 let steps = [ ( "s1" , "a" , "b" , "do it" ) , ( "s2" , "b" , "c" , "then this" ) ] ;
320- let html = render_html ( "bp" , Some ( "desc" ) , "confirmed" , "t1" , "t2" , "in" , "out" , & steps) ;
333+ let html = render_html (
334+ "bp" ,
335+ Some ( "desc" ) ,
336+ "confirmed" ,
337+ "t1" ,
338+ "t2" ,
339+ "in" ,
340+ "out" ,
341+ & steps,
342+ ) ;
321343 assert ! ( html. contains( "s1" ) ) ;
322344 assert ! ( html. contains( "s2" ) ) ;
323345 assert ! ( html. contains( "do it" ) ) ;
@@ -344,7 +366,11 @@ mod tests {
344366 let tmp = std:: env:: temp_dir ( ) . join ( "bp-test-resolve" ) ;
345367 let _ = std:: fs:: remove_dir_all ( & tmp) ;
346368 std:: fs:: create_dir_all ( & tmp) . unwrap ( ) ;
347- std:: fs:: write ( tmp. join ( "my-bp.cue" ) , "package blueprints\n {name: \" test\" }" ) . unwrap ( ) ;
369+ std:: fs:: write (
370+ tmp. join ( "my-bp.cue" ) ,
371+ "package blueprints\n {name: \" test\" }" ,
372+ )
373+ . unwrap ( ) ;
348374
349375 let result = resolve_cue_path ( "my-bp" , tmp. to_str ( ) . unwrap ( ) ) ;
350376 assert ! ( result. is_some( ) ) ;
@@ -482,7 +508,9 @@ pub fn contract_tables_to_yaml(md_tables: &str) -> (String, String) {
482508 let output_fields = parse_md_table ( md_tables, "输出契约" ) ;
483509
484510 if !input_fields. is_empty ( ) && input_fields == output_fields {
485- eprintln ! ( "错误: 输入契约和输出契约解析到相同字段。LLM 可能跳过了 section 标题,请在 prompt 中要求 LLM 输出 ## 输入契约 和 ## 输出契约 标题。" ) ;
511+ eprintln ! (
512+ "错误: 输入契约和输出契约解析到相同字段。LLM 可能跳过了 section 标题,请在 prompt 中要求 LLM 输出 ## 输入契约 和 ## 输出契约 标题。"
513+ ) ;
486514 std:: process:: exit ( 1 ) ;
487515 }
488516
@@ -519,8 +547,10 @@ fn parse_md_table(text: &str, section: &str) -> Vec<Vec<String>> {
519547 found_section = true ;
520548 continue ;
521549 }
522- if in_section && line. starts_with ( '|' ) && !line. contains ( "---" ) && !line. contains ( "字段名" ) {
523- let cells: Vec < String > = line. split ( '|' )
550+ if in_section && line. starts_with ( '|' ) && !line. contains ( "---" ) && !line. contains ( "字段名" )
551+ {
552+ let cells: Vec < String > = line
553+ . split ( '|' )
524554 . map ( |c| c. trim ( ) . to_string ( ) )
525555 . filter ( |c| !c. is_empty ( ) )
526556 . collect ( ) ;
@@ -536,7 +566,8 @@ fn parse_md_table(text: &str, section: &str) -> Vec<Vec<String>> {
536566 if !found_section {
537567 for line in text. lines ( ) {
538568 if line. starts_with ( '|' ) && !line. contains ( "---" ) && !line. contains ( "字段名" ) {
539- let cells: Vec < String > = line. split ( '|' )
569+ let cells: Vec < String > = line
570+ . split ( '|' )
540571 . map ( |c| c. trim ( ) . to_string ( ) )
541572 . filter ( |c| !c. is_empty ( ) )
542573 . collect ( ) ;
@@ -550,15 +581,23 @@ fn parse_md_table(text: &str, section: &str) -> Vec<Vec<String>> {
550581}
551582
552583fn fields_to_schema_desc ( fields : & [ Vec < String > ] ) -> String {
553- if fields. is_empty ( ) { return "待定义" . into ( ) ; }
554- let items: Vec < String > = fields. iter ( )
555- . filter_map ( |f| f. first ( ) . map ( |name| format ! ( "{name}: {}" , f. get( 1 ) . unwrap_or( & "string" . into( ) ) ) ) )
584+ if fields. is_empty ( ) {
585+ return "待定义" . into ( ) ;
586+ }
587+ let items: Vec < String > = fields
588+ . iter ( )
589+ . filter_map ( |f| {
590+ f. first ( )
591+ . map ( |name| format ! ( "{name}: {}" , f. get( 1 ) . unwrap_or( & "string" . into( ) ) ) )
592+ } )
556593 . collect ( ) ;
557594 format ! ( "{{\n {}\n }}" , items. join( ",\n " ) )
558595}
559596
560597fn render_contract_md ( input : & [ Vec < String > ] , output : & [ Vec < String > ] ) -> String {
561- let mut md = String :: from ( "## 输入契约\n \n | 字段名 | 类型 | 业务含义 | 约束条件 |\n |--------|------|----------|----------|\n " ) ;
598+ let mut md = String :: from (
599+ "## 输入契约\n \n | 字段名 | 类型 | 业务含义 | 约束条件 |\n |--------|------|----------|----------|\n " ,
600+ ) ;
562601 for row in input {
563602 let cells: Vec < & str > = row. iter ( ) . map ( |c| c. as_str ( ) ) . collect ( ) ;
564603 if cells. len ( ) >= 4 {
@@ -613,7 +652,10 @@ pub fn blueprint_table_to_yaml(md_table: &str, project_name: &str) -> (String, S
613652 let deps_yaml = if deps. is_empty ( ) || deps == "-" {
614653 String :: new ( )
615654 } else {
616- let dep_list: String = deps. split ( ',' ) . map ( |d| format ! ( "\n - {}" , d. trim( ) ) ) . collect ( ) ;
655+ let dep_list: String = deps
656+ . split ( ',' )
657+ . map ( |d| format ! ( "\n - {}" , d. trim( ) ) )
658+ . collect ( ) ;
617659 format ! ( "\n depends:{}" , dep_list)
618660 } ;
619661
@@ -657,10 +699,14 @@ updated_at: "2026-07-24T00:00:00+00:00"
657699}
658700
659701fn render_blueprint_md ( name : & str , steps : & [ Vec < String > ] ) -> String {
660- let mut md = format ! ( "# {name}\n \n ## 处理步骤\n \n | 步骤名 | 输入 | 输出 | 处理逻辑 | 依赖 |\n |--------|------|------|----------|------|\n " ) ;
702+ let mut md = format ! (
703+ "# {name}\n \n ## 处理步骤\n \n | 步骤名 | 输入 | 输出 | 处理逻辑 | 依赖 |\n |--------|------|------|----------|------|\n "
704+ ) ;
661705 for row in steps {
662706 let cells: Vec < & str > = row. iter ( ) . map ( |c| c. as_str ( ) ) . collect ( ) ;
663- let padded: Vec < String > = ( 0 ..5 ) . map ( |i| cells. get ( i) . unwrap_or ( & "" ) . to_string ( ) ) . collect ( ) ;
707+ let padded: Vec < String > = ( 0 ..5 )
708+ . map ( |i| cells. get ( i) . unwrap_or ( & "" ) . to_string ( ) )
709+ . collect ( ) ;
664710 md. push_str ( & format ! ( "| {} |\n " , padded. join( " | " ) ) ) ;
665711 }
666712 md
@@ -702,7 +748,11 @@ pub fn implement_step_prompt(
702748 from_desc = from_desc,
703749 to_desc = to_desc,
704750 step_desc = step_desc,
705- prev_section = if prev_functions. is_empty( ) { "无(这是第一步)" } else { prev_functions } ,
751+ prev_section = if prev_functions. is_empty( ) {
752+ "无(这是第一步)"
753+ } else {
754+ prev_functions
755+ } ,
706756 func_name = to_snake( step_name) ,
707757 )
708758}
0 commit comments