kodegen_tools_prompt 0.6.0

KODEGEN.ᴀɪ: Memory-efficient, Blazing-Fast, MCP tools for code generation agents.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
use super::manager::PromptManager;
use super::template::parse_template;
use kodegen_mcp_tool::{Tool, ToolExecutionContext, ToolResponse};
use kodegen_mcp_tool::error::McpError;
use kodegen_mcp_schema::prompt::{AddPromptArgs, AddPromptPromptArgs, PromptAddOutput, PROMPT_ADD};
use rmcp::model::{PromptArgument, PromptMessage, PromptMessageContent, PromptMessageRole};

#[derive(Clone)]
pub struct AddPromptTool {
    manager: PromptManager,
}

impl AddPromptTool {
    /// Create with a pre-initialized PromptManager (for HTTP server)
    pub fn with_manager(manager: PromptManager) -> Self {
        Self { manager }
    }

    /// Create with default manager (for standalone use)
    pub async fn new() -> Result<Self, McpError> {
        let manager = PromptManager::new();
        manager.init().await?;
        Ok(Self { manager })
    }
}

impl Tool for AddPromptTool {
    type Args = AddPromptArgs;
    type PromptArgs = AddPromptPromptArgs;

    fn name() -> &'static str {
        PROMPT_ADD
    }

    fn description() -> &'static str {
        "Create a new prompt template. The content must include YAML frontmatter with metadata \
         (title, description, categories, author) followed by the template body. Template syntax \
         is validated before saving. Environment variables are accessible via {{ env.VAR }}. \
         Parameters can be defined in frontmatter and used via {{ param_name }}."
    }

    fn read_only() -> bool {
        false
    }

    fn destructive() -> bool {
        false // Creates new file, doesn't modify existing
    }

    fn idempotent() -> bool {
        false // Will fail if prompt already exists
    }

    async fn execute(&self, args: Self::Args, _ctx: ToolExecutionContext) -> Result<ToolResponse<<Self::Args as kodegen_mcp_tool::ToolArgs>::Output>, McpError> {
        // Parse template to extract metadata (for output formatting)
        let template = parse_template(&args.name, &args.content)
            .map_err(McpError::Other)?;

        // Extract statistics
        let param_count = template.metadata.parameters.len();
        let template_length = template.content.len();

        // Add prompt (validates syntax automatically, async)
        self.manager
            .add_prompt(&args.name, &args.content)
            .await
            .map_err(McpError::Other)?;

        let path = format!("~/.kodegen/prompts/{}.j2.md", args.name);

        // Terminal summary
        let summary = format!(
            "\x1b[32m Prompt Added: {}\x1b[0m\n\
              Template length: {} · Parameters: {}",
            args.name,
            template_length,
            param_count
        );

        // Typed output
        let output = PromptAddOutput {
            success: true,
            name: args.name.clone(),
            message: format!("Prompt '{}' created successfully", args.name),
            path: Some(path),
            template_length: Some(template_length),
            parameter_count: Some(param_count),
        };

        Ok(ToolResponse::new(summary, output))
    }

    fn prompt_arguments() -> Vec<PromptArgument> {
        vec![
            PromptArgument {
                name: "template_scope".to_string(),
                title: Some("Template Purpose".to_string()),
                description: Some(
                    "Type of template to focus examples on: 'code' (for code generation), \
                     'analysis' (for document analysis), 'workflow' (for multi-step processes), \
                     'documentation' (for doc generation), or 'custom' (general guidance)".to_string(),
                ),
                required: Some(false),
            },
            PromptArgument {
                name: "detail_level".to_string(),
                title: Some("Example Depth".to_string()),
                description: Some(
                    "How detailed the teaching should be: 'basic' (overview only), \
                     'intermediate' (practical examples), or 'advanced' (complex patterns and optimization)"
                        .to_string(),
                ),
                required: Some(false),
            },
        ]
    }

    async fn prompt(&self, args: Self::PromptArgs) -> Result<Vec<PromptMessage>, McpError> {
        // Extract arguments with defaults
        let template_scope = args.template_scope.as_deref().unwrap_or("custom");
        let detail_level = args.detail_level.as_deref().unwrap_or("intermediate");

        // Build conversation based on scope and detail level
        let (question, answer) = match (template_scope, detail_level) {
            // CODE SCOPE
            ("code", "basic") => (
                "How do I create prompt templates for code generation?",
                "Use prompt_add to create code generation templates with basic parameters:\n\n\
                 Example:\n\
                 ```\n\
                 prompt_add({\n\
                   \"name\": \"code_gen\",\n\
                   \"content\": \"---\\n\
                 title: \\\"Code Generator\\\"\\n\
                 description: \\\"Generate code in specified language\\\"\\n\
                 categories: [\\\"code\\\"]\\n\
                 author: \\\"your-name\\\"\\n\
                 parameters:\\n\
                   - name: \\\"language\\\"\\n\
                     description: \\\"Programming language\\\"\\n\
                     required: true\\n\
                   - name: \\\"style\\\"\\n\
                     description: \\\"Code style\\\"\\n\
                     required: false\\n\
                     default: \\\"standard\\\"\\n\
                 ---\\n\
                 \\n\
                 Generate {{ language }} code following {{ style }} style.\\n\
                 \\\"\n\
                 })\n\
                 ```\n\n\
                 Template features:\n\
                 - {{ variable }} - Variable substitution for parameters",
            ),
            ("code", "advanced") => (
                "How do I create advanced code generation templates?",
                "Create sophisticated code generation templates with conditionals, environment variables, and filters:\n\n\
                 Basic example:\n\
                 ```\n\
                 prompt_add({\n\
                   \"name\": \"simple_code\",\n\
                   \"content\": \"---\\n\
                 title: \\\"Simple Code Gen\\\"\\n\
                 parameters:\\n\
                   - name: \\\"language\\\"\\n\
                 ---\\n\
                 Generate {{ language }} code.\\n\
                 \\\"\n\
                 })\n\
                 ```\n\n\
                 Advanced example with all features:\n\
                 ```\n\
                 prompt_add({\n\
                   \"name\": \"advanced_code\",\n\
                   \"content\": \"---\\n\
                 title: \\\"Advanced Code Generator\\\"\\n\
                 description: \\\"Context-aware code generation\\\"\\n\
                 categories: [\\\"code\\\", \\\"generation\\\"]\\n\
                 author: \\\"your-name\\\"\\n\
                 parameters:\\n\
                   - name: \\\"language\\\"\\n\
                     description: \\\"Target language\\\"\\n\
                     required: true\\n\
                   - name: \\\"style\\\"\\n\
                     description: \\\"Code style (functional/oop)\\\"\\n\
                     default: \\\"functional\\\"\\n\
                   - name: \\\"framework\\\"\\n\
                     description: \\\"Framework to use\\\"\\n\
                     required: false\\n\
                   - name: \\\"features\\\"\\n\
                     description: \\\"List of features\\\"\\n\
                     required: false\\n\
                 ---\\n\
                 \\n\
                 # Code Generation Request\\n\
                 \\n\
                 Language: {{ language | upper }}\\n\
                 Style: {{ style }}\\n\
                 \\n\
                 {% if framework %}\\n\
                 Framework: {{ framework }}\\n\
                 Use {{ framework }}-specific patterns and conventions.\\n\
                 {% endif %}\\n\
                 \\n\
                 {% if features %}\\n\
                 Required features:\\n\
                 {% for feature in features %}\\n\
                 - {{ feature }}\\n\
                 {% endfor %}\\n\
                 {% endif %}\\n\
                 \\n\
                 Compiler: {{ env.COMPILER }}\\n\
                 \\n\
                 {% if style == 'functional' %}\\n\
                 Focus on pure functions, immutability, and composition.\\n\
                 {% else %}\\n\
                 Use object-oriented design with classes and inheritance.\\n\
                 {% endif %}\\n\
                 \\\"\n\
                 })\n\
                 ```\n\n\
                 Best practices:\n\
                 - **Parameter design**: Use required for essential params, defaults for optional\n\
                 - **Conditionals**: Adapt output based on context ({% if framework %}...{% endif %})\n\
                 - **Filters**: Transform variables ({{ language | upper }}, {{ style | lower }})\n\
                 - **Environment**: Access system info via {{ env.VAR }}\n\
                 - **Lists**: Iterate with {% for item in items %}...{% endfor %}\n\n\
                 Common patterns:\n\
                 - Language-specific conventions: Use conditionals to adapt style\n\
                 - Tool path configuration: {{ env.COMPILER }}, {{ env.LINTER }}\n\
                 - Feature toggles: {% if feature_name %} implementation {% endif %}\n\n\
                 Performance: Large templates with many conditionals parse efficiently. \
                 Template compilation is cached after first use.",
            ),
            ("code", _) => ( // intermediate or default
                "How do I create prompt templates for code generation?",
                "Use prompt_add to create code generation templates:\n\n\
                 Example:\n\
                 ```\n\
                 prompt_add({\n\
                   \"name\": \"code_generator\",\n\
                   \"content\": \"---\\n\
                 title: \\\"Code Generator\\\"\\n\
                 description: \\\"Generate code with specific parameters\\\"\\n\
                 categories: [\\\"code\\\"]\\n\
                 author: \\\"your-name\\\"\\n\
                 parameters:\\n\
                   - name: \\\"language\\\"\\n\
                     description: \\\"Programming language\\\"\\n\
                     required: true\\n\
                   - name: \\\"style\\\"\\n\
                     description: \\\"Code style (functional/oop)\\\"\\n\
                     required: false\\n\
                     default: \\\"functional\\\"\\n\
                   - name: \\\"framework\\\"\\n\
                     description: \\\"Framework to use\\\"\\n\
                     required: false\\n\
                 ---\\n\
                 \\n\
                 # Code Generation\\n\
                 \\n\
                 Generate {{ language }} code following {{ style }} style.\\n\
                 \\n\
                 {% if framework %}\\n\
                 Use {{ framework }} framework patterns.\\n\
                 {% endif %}\\n\
                 \\n\
                 Compiler path: {{ env.COMPILER }}\\n\
                 \\\"\n\
                 })\n\
                 ```\n\n\
                 Template features:\n\
                 - {{ variable }} - Variable substitution (language, style, framework)\n\
                 - {% if condition %} - Conditionals for optional features\n\
                 - {{ env.VAR }} - Environment variables for tool paths\n\
                 - {{ param | filter }} - Filters for text transformation\n\n\
                 The content is validated for syntax errors before saving.",
            ),

            // ANALYSIS SCOPE
            ("analysis", "basic") => (
                "How do I create templates for analyzing documents or code?",
                "Use prompt_add for analysis workflows:\n\n\
                 Example:\n\
                 ```\n\
                 prompt_add({\n\
                   \"name\": \"analyze\",\n\
                   \"content\": \"---\\n\
                 title: \\\"Analyzer\\\"\\n\
                 description: \\\"Analyze content\\\"\\n\
                 categories: [\\\"analysis\\\"]\\n\
                 author: \\\"your-name\\\"\\n\
                 parameters:\\n\
                   - name: \\\"depth\\\"\\n\
                     description: \\\"Analysis depth\\\"\\n\
                     default: \\\"standard\\\"\\n\
                 ---\\n\
                 \\n\
                 Perform {{ depth }} analysis.\\n\
                 \\\"\n\
                 })\n\
                 ```\n\n\
                 Template features:\n\
                 - {{ variable }} - Parameter substitution",
            ),
            ("analysis", "advanced") => (
                "How do I create advanced analysis templates?",
                "Create comprehensive analysis templates with depth control and focus areas:\n\n\
                 Basic example:\n\
                 ```\n\
                 prompt_add({\n\
                   \"name\": \"basic_analysis\",\n\
                   \"content\": \"---\\n\
                 title: \\\"Basic Analysis\\\"\\n\
                 parameters:\\n\
                   - name: \\\"depth\\\"\\n\
                 ---\\n\
                 Analyze with {{ depth }} depth.\\n\
                 \\\"\n\
                 })\n\
                 ```\n\n\
                 Advanced example:\n\
                 ```\n\
                 prompt_add({\n\
                   \"name\": \"advanced_analysis\",\n\
                   \"content\": \"---\\n\
                 title: \\\"Advanced Code Analysis\\\"\\n\
                 description: \\\"Multi-level code and document analysis\\\"\\n\
                 categories: [\\\"analysis\\\", \\\"code\\\"]\\n\
                 author: \\\"your-name\\\"\\n\
                 parameters:\\n\
                   - name: \\\"depth\\\"\\n\
                     description: \\\"Analysis depth (surface/standard/deep)\\\"\\n\
                     default: \\\"standard\\\"\\n\
                   - name: \\\"focus_areas\\\"\\n\
                     description: \\\"Specific areas to focus on\\\"\\n\
                     required: false\\n\
                   - name: \\\"output_format\\\"\\n\
                     description: \\\"Report format\\\"\\n\
                     default: \\\"markdown\\\"\\n\
                 ---\\n\
                 \\n\
                 # Analysis Request\\n\
                 \\n\
                 Analysis depth: {{ depth }}\\n\
                 \\n\
                 {% if depth == 'deep' %}\\n\
                 ## Deep Analysis Steps\\n\
                 1. Static code analysis\\n\
                 2. Dependency review\\n\
                 3. Security audit\\n\
                 4. Performance profiling\\n\
                 5. Best practices compliance\\n\
                 {% elif depth == 'standard' %}\\n\
                 ## Standard Analysis\\n\
                 - Code structure review\\n\
                 - Basic security checks\\n\
                 - Style compliance\\n\
                 {% else %}\\n\
                 ## Surface Analysis\\n\
                 - Quick overview\\n\
                 - Basic metrics\\n\
                 {% endif %}\\n\
                 \\n\
                 {% if focus_areas %}\\n\
                 Focus areas:\\n\
                 {% for area in focus_areas %}\\n\
                 - {{ area | capitalize }}\\n\
                 {% endfor %}\\n\
                 {% endif %}\\n\
                 \\n\
                 Output: {{ output_format | upper }}\\n\
                 Tool: {{ env.ANALYZER_PATH }}\\n\
                 \\\"\n\
                 })\n\
                 ```\n\n\
                 Best practices:\n\
                 - **Depth levels**: Use conditionals to vary analysis thoroughness\n\
                 - **Focus areas**: Allow targeting specific aspects via lists\n\
                 - **Output formats**: Support multiple report formats\n\
                 - **Tool integration**: Reference analysis tools via environment variables\n\n\
                 Patterns:\n\
                 - Conditional analysis steps based on depth parameter\n\
                 - Iteration over focus areas for targeted analysis\n\
                 - Filter usage for formatting (capitalize, upper)\n\
                 - Environment variables for tool paths",
            ),
            ("analysis", _) => ( // intermediate or default
                "How do I create templates for analyzing documents or code?",
                "Use prompt_add for analysis workflows:\n\n\
                 Example:\n\
                 ```\n\
                 prompt_add({\n\
                   \"name\": \"code_analysis\",\n\
                   \"content\": \"---\\n\
                 title: \\\"Code Analysis\\\"\\n\
                 description: \\\"Analyze code with configurable depth\\\"\\n\
                 categories: [\\\"analysis\\\"]\\n\
                 author: \\\"your-name\\\"\\n\
                 parameters:\\n\
                   - name: \\\"depth\\\"\\n\
                     description: \\\"Analysis depth (surface/standard/deep)\\\"\\n\
                     required: false\\n\
                     default: \\\"standard\\\"\\n\
                   - name: \\\"focus_areas\\\"\\n\
                     description: \\\"Areas to focus on\\\"\\n\
                     required: false\\n\
                 ---\\n\
                 \\n\
                 # Code Analysis\\n\
                 \\n\
                 Depth: {{ depth }}\\n\
                 \\n\
                 {% if depth == 'deep' %}\\n\
                 Perform comprehensive analysis including:\\n\
                 - Static analysis\\n\
                 - Security review\\n\
                 - Performance check\\n\
                 {% else %}\\n\
                 Perform {{ depth }} analysis.\\n\
                 {% endif %}\\n\
                 \\n\
                 {% if focus_areas %}\\n\
                 Focus on: {% for area in focus_areas %}{{ area }}{% if not loop.last %}, {% endif %}{% endfor %}\\n\
                 {% endif %}\\n\
                 \\\"\n\
                 })\n\
                 ```\n\n\
                 Template features:\n\
                 - {{ variable }} - Variable substitution (depth, focus_areas)\n\
                 - {% if condition %} - Conditional analysis steps\n\
                 - {% for item in items %} - Iterate over focus areas\n\
                 - {{ env.VAR }} - Environment variables for tool paths\n\n\
                 The content is validated for syntax errors before saving.",
            ),

            // WORKFLOW SCOPE
            ("workflow", "basic") => (
                "How do I create multi-step workflow templates?",
                "Use prompt_add for simple workflows:\n\n\
                 Example:\n\
                 ```\n\
                 prompt_add({\n\
                   \"name\": \"workflow\",\n\
                   \"content\": \"---\\n\
                 title: \\\"Simple Workflow\\\"\\n\
                 description: \\\"Execute steps\\\"\\n\
                 categories: [\\\"workflow\\\"]\\n\
                 author: \\\"your-name\\\"\\n\
                 parameters:\\n\
                   - name: \\\"steps\\\"\\n\
                     description: \\\"Steps to execute\\\"\\n\
                 ---\\n\
                 \\n\
                 Execute workflow steps.\\n\
                 \\\"\n\
                 })\n\
                 ```\n\n\
                 Template features:\n\
                 - {{ variable }} - Parameter substitution",
            ),
            ("workflow", "advanced") => (
                "How do I create complex multi-step workflow templates?",
                "Create sophisticated workflows with loops, conditionals, and step management:\n\n\
                 Basic example:\n\
                 ```\n\
                 prompt_add({\n\
                   \"name\": \"simple_workflow\",\n\
                   \"content\": \"---\\n\
                 title: \\\"Simple Workflow\\\"\\n\
                 parameters:\\n\
                   - name: \\\"steps\\\"\\n\
                 ---\\n\
                 Execute steps.\\n\
                 \\\"\n\
                 })\n\
                 ```\n\n\
                 Advanced example:\n\
                 ```\n\
                 prompt_add({\n\
                   \"name\": \"complex_workflow\",\n\
                   \"content\": \"---\\n\
                 title: \\\"Complex Workflow Engine\\\"\\n\
                 description: \\\"Multi-step workflow with conditionals and error handling\\\"\\n\
                 categories: [\\\"workflow\\\", \\\"automation\\\"]\\n\
                 author: \\\"your-name\\\"\\n\
                 parameters:\\n\
                   - name: \\\"steps\\\"\\n\
                     description: \\\"List of workflow steps\\\"\\n\
                     required: true\\n\
                   - name: \\\"parallel\\\"\\n\
                     description: \\\"Execute steps in parallel\\\"\\n\
                     default: false\\n\
                   - name: \\\"error_handling\\\"\\n\
                     description: \\\"Error handling strategy (abort/continue/retry)\\\"\\n\
                     default: \\\"abort\\\"\\n\
                   - name: \\\"conditions\\\"\\n\
                     description: \\\"Conditional step execution\\\"\\n\
                     required: false\\n\
                 ---\\n\
                 \\n\
                 # Workflow Execution Plan\\n\
                 \\n\
                 {% if parallel %}\\n\
                 Execution mode: PARALLEL\\n\
                 {% else %}\\n\
                 Execution mode: SEQUENTIAL\\n\
                 {% endif %}\\n\
                 \\n\
                 Error handling: {{ error_handling | upper }}\\n\
                 \\n\
                 ## Steps\\n\
                 {% for step in steps %}\\n\
                 ### Step {{ loop.index }}: {{ step }}\\n\
                 \\n\
                 {% if conditions and conditions[loop.index0] %}\\n\
                 Condition: {{ conditions[loop.index0] }}\\n\
                 {% endif %}\\n\
                 \\n\
                 {% if parallel %}\\n\
                 - Execute in parallel thread\\n\
                 {% else %}\\n\
                 - Wait for previous step completion\\n\
                 {% endif %}\\n\
                 \\n\
                 {% if error_handling == 'retry' %}\\n\
                 - Retry on failure (max 3 attempts)\\n\
                 {% elif error_handling == 'continue' %}\\n\
                 - Continue on failure\\n\
                 {% else %}\\n\
                 - Abort workflow on failure\\n\
                 {% endif %}\\n\
                 \\n\
                 {% endfor %}\\n\
                 \\n\
                 Workflow runner: {{ env.WORKFLOW_ENGINE }}\\n\
                 \\\"\n\
                 })\n\
                 ```\n\n\
                 Best practices:\n\
                 - **Step iteration**: Use {% for step in steps %} with loop.index for numbering\n\
                 - **Conditional execution**: Check conditions array for step-specific rules\n\
                 - **Branching logic**: Use {% if %} {% elif %} {% else %} for complex decisions\n\
                 - **Loop context**: Access loop.index (1-based) and loop.index0 (0-based)\n\n\
                 Common patterns:\n\
                 - Sequential vs parallel execution modes\n\
                 - Error handling strategies per step\n\
                 - Parameter passing between workflow steps\n\
                 - Conditional step execution based on previous results\n\n\
                 Template composition:\n\
                 - Break large workflows into reusable sub-templates\n\
                 - Use consistent parameter naming across workflow templates\n\
                 - Document step dependencies in template description",
            ),
            ("workflow", _) => ( // intermediate or default
                "How do I create multi-step workflow templates?",
                "Use prompt_add for multi-step workflows with loops and conditionals:\n\n\
                 Example:\n\
                 ```\n\
                 prompt_add({\n\
                   \"name\": \"workflow_template\",\n\
                   \"content\": \"---\\n\
                 title: \\\"Multi-Step Workflow\\\"\\n\
                 description: \\\"Execute workflow with conditional steps\\\"\\n\
                 categories: [\\\"workflow\\\"]\\n\
                 author: \\\"your-name\\\"\\n\
                 parameters:\\n\
                   - name: \\\"steps\\\"\\n\
                     description: \\\"List of steps to execute\\\"\\n\
                     required: true\\n\
                   - name: \\\"parallel\\\"\\n\
                     description: \\\"Run steps in parallel\\\"\\n\
                     required: false\\n\
                     default: false\\n\
                 ---\\n\
                 \\n\
                 # Workflow Execution\\n\
                 \\n\
                 {% if parallel %}\\n\
                 Mode: Parallel execution\\n\
                 {% else %}\\n\
                 Mode: Sequential execution\\n\
                 {% endif %}\\n\
                 \\n\
                 Steps:\\n\
                 {% for step in steps %}\\n\
                 {{ loop.index }}. {{ step }}\\n\
                 {% endfor %}\\n\
                 \\\"\n\
                 })\n\
                 ```\n\n\
                 Template features:\n\
                 - {{ variable }} - Variable substitution (steps, parallel)\n\
                 - {% if condition %} - Conditional branching for execution modes\n\
                 - {% for item in items %} - Loop over workflow steps\n\
                 - loop.index - Access step number in loops\n\
                 - {{ env.VAR }} - Environment variables\n\n\
                 The content is validated for syntax errors before saving.",
            ),

            // DOCUMENTATION SCOPE
            ("documentation", "basic") => (
                "How do I create documentation generation templates?",
                "Use prompt_add for simple documentation:\n\n\
                 Example:\n\
                 ```\n\
                 prompt_add({\n\
                   \"name\": \"doc_gen\",\n\
                   \"content\": \"---\\n\
                 title: \\\"Doc Generator\\\"\\n\
                 description: \\\"Generate docs\\\"\\n\
                 categories: [\\\"documentation\\\"]\\n\
                 author: \\\"your-name\\\"\\n\
                 parameters:\\n\
                   - name: \\\"title\\\"\\n\
                     description: \\\"Document title\\\"\\n\
                 ---\\n\
                 \\n\
                 # {{ title }}\\n\
                 \\\"\n\
                 })\n\
                 ```\n\n\
                 Template features:\n\
                 - {{ variable }} - Parameter substitution",
            ),
            ("documentation", "advanced") => (
                "How do I create advanced documentation templates?",
                "Create comprehensive documentation templates with structure and formatting:\n\n\
                 Basic example:\n\
                 ```\n\
                 prompt_add({\n\
                   \"name\": \"simple_doc\",\n\
                   \"content\": \"---\\n\
                 title: \\\"Simple Doc\\\"\\n\
                 parameters:\\n\
                   - name: \\\"title\\\"\\n\
                 ---\\n\
                 # {{ title }}\\n\
                 \\\"\n\
                 })\n\
                 ```\n\n\
                 Advanced example:\n\
                 ```\n\
                 prompt_add({\n\
                   \"name\": \"advanced_documentation\",\n\
                   \"content\": \"---\\n\
                 title: \\\"Advanced Documentation Generator\\\"\\n\
                 description: \\\"Generate structured documentation with optional sections\\\"\\n\
                 categories: [\\\"documentation\\\", \\\"markdown\\\"]\\n\
                 author: \\\"your-name\\\"\\n\
                 parameters:\\n\
                   - name: \\\"title\\\"\\n\
                     description: \\\"Document title\\\"\\n\
                     required: true\\n\
                   - name: \\\"language\\\"\\n\
                     description: \\\"Programming language\\\"\\n\
                     required: false\\n\
                   - name: \\\"audience\\\"\\n\
                     description: \\\"Target audience (beginner/intermediate/expert)\\\"\\n\
                     default: \\\"intermediate\\\"\\n\
                   - name: \\\"sections\\\"\\n\
                     description: \\\"Sections to include\\\"\\n\
                     required: false\\n\
                   - name: \\\"style\\\"\\n\
                     description: \\\"Documentation style\\\"\\n\
                     default: \\\"technical\\\"\\n\
                 ---\\n\
                 \\n\
                 # {{ title }}\\n\
                 \\n\
                 {% if language %}\\n\
                 **Language**: {{ language | upper }}\\n\
                 {% endif %}\\n\
                 \\n\
                 **Audience**: {{ audience | capitalize }}\\n\
                 \\n\
                 ---\\n\
                 \\n\
                 ## Overview\\n\
                 \\n\
                 {% if audience == 'beginner' %}\\n\
                 This documentation provides a gentle introduction with step-by-step examples.\\n\
                 {% elif audience == 'expert' %}\\n\
                 This documentation focuses on advanced usage and optimization techniques.\\n\
                 {% else %}\\n\
                 This documentation covers practical usage with real-world examples.\\n\
                 {% endif %}\\n\
                 \\n\
                 {% if sections %}\\n\
                 ## Table of Contents\\n\
                 {% for section in sections %}\\n\
                 {{ loop.index }}. {{ section | title }}\\n\
                 {% endfor %}\\n\
                 \\n\
                 {% for section in sections %}\\n\
                 ## {{ section | title }}\\n\
                 \\n\
                 {% if style == 'tutorial' %}\\n\
                 ### Step-by-step guide for {{ section }}\\n\
                 {% else %}\\n\
                 ### Technical reference for {{ section }}\\n\
                 {% endif %}\\n\
                 \\n\
                 {% endfor %}\\n\
                 {% endif %}\\n\
                 \\n\
                 ---\\n\
                 Generated by: {{ env.USER }}\\n\
                 \\\"\n\
                 })\n\
                 ```\n\n\
                 Best practices:\n\
                 - **Section organization**: Use loops to generate consistent section structure\n\
                 - **Audience targeting**: Adapt content depth via conditionals\n\
                 - **Text formatting**: Apply filters (title, capitalize, upper) for consistency\n\
                 - **Optional content**: Use conditionals for sections that may not always be needed\n\n\
                 Common patterns:\n\
                 - Table of contents generation from sections array\n\
                 - Audience-specific explanations (beginner vs expert)\n\
                 - Style variations (tutorial vs reference)\n\
                 - Metadata inclusion (author, date via env.USER)\n\n\
                 Documentation structure:\n\
                 - Start with overview and audience statement\n\
                 - Generate TOC from sections parameter\n\
                 - Iterate through sections with consistent formatting\n\
                 - Use filters for title casing and capitalization",
            ),
            ("documentation", _) => ( // intermediate or default
                "How do I create documentation generation templates?",
                "Use prompt_add for documentation generation with structured output:\n\n\
                 Example:\n\
                 ```\n\
                 prompt_add({\n\
                   \"name\": \"doc_template\",\n\
                   \"content\": \"---\\n\
                 title: \\\"Documentation Generator\\\"\\n\
                 description: \\\"Generate markdown documentation\\\"\\n\
                 categories: [\\\"documentation\\\"]\\n\
                 author: \\\"your-name\\\"\\n\
                 parameters:\\n\
                   - name: \\\"title\\\"\\n\
                     description: \\\"Document title\\\"\\n\
                     required: true\\n\
                   - name: \\\"language\\\"\\n\
                     description: \\\"Programming language\\\"\\n\
                     required: false\\n\
                   - name: \\\"audience\\\"\\n\
                     description: \\\"Target audience\\\"\\n\
                     default: \\\"general\\\"\\n\
                 ---\\n\
                 \\n\
                 # {{ title }}\\n\
                 \\n\
                 {% if language %}\\n\
                 Language: {{ language | upper }}\\n\
                 {% endif %}\\n\
                 \\n\
                 Audience: {{ audience | capitalize }}\\n\
                 \\n\
                 {% if audience == 'beginner' %}\\n\
                 This guide includes detailed explanations and examples.\\n\
                 {% else %}\\n\
                 This guide assumes familiarity with core concepts.\\n\
                 {% endif %}\\n\
                 \\\"\n\
                 })\n\
                 ```\n\n\
                 Template features:\n\
                 - {{ variable }} - Variable substitution (title, language, audience)\n\
                 - {% if condition %} - Conditionals for optional sections\n\
                 - {{ param | filter }} - Filters (upper, capitalize, title) for formatting\n\
                 - {{ env.VAR }} - Environment variables for metadata\n\n\
                 The content is validated for syntax errors before saving.",
            ),

            // CUSTOM/DEFAULT SCOPE
            _ => (
                "How do I create a custom prompt?",
                "Use prompt_add to create custom prompt templates:\n\n\
                 Example:\n\
                 ```\n\
                 prompt_add({\n\
                   \"name\": \"my_workflow\",\n\
                   \"content\": \"---\\n\
                 title: \\\"My Custom Workflow\\\"\\n\
                 description: \\\"Description here\\\"\\n\
                 categories: [\\\"custom\\\"]\\n\
                 author: \\\"your-name\\\"\\n\
                 parameters:\\n\
                   - name: \\\"project_path\\\"\\n\
                     description: \\\"Project to analyze\\\"\\n\
                     required: false\\n\
                     default: \\\".\\\"\\n\
                 ---\\n\
                 \\n\
                 # My Workflow\\n\
                 \\n\
                 Project: {{ project_path }}\\n\
                 User: {{ env.USER }}\\n\
                 \\\"\n\
                 })\n\
                 ```\n\n\
                 Template features:\n\
                 - {{ variable }} - Variable substitution\n\
                 - {% if condition %} - Conditionals\n\
                 - {% for item in items %} - Loops\n\
                 - {{ env.VAR }} - Environment variables\n\
                 - {{ param | filter }} - Filters\n\n\
                 The content is validated for syntax errors before saving.",
            ),
        };

        Ok(vec![
            PromptMessage {
                role: PromptMessageRole::User,
                content: PromptMessageContent::text(question),
            },
            PromptMessage {
                role: PromptMessageRole::Assistant,
                content: PromptMessageContent::text(answer),
            },
        ])
    }
}