ralph-workflow 0.7.18

PROMPT-driven multi-agent orchestrator for git repos
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
//! Prompt template management module.
//!
//! This module provides a collection of PROMPT.md templates for different
//! task types (feature specifications, bug fixes, refactoring, etc.).
//!
//! Templates are embedded at compile time using `include_str!` and can be
//! accessed via the `get_template_content()` function.

use std::fmt;

/// Available prompt template types.
///
/// Each variant represents a different template for a specific use case.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PromptTemplate {
    /// Comprehensive product specification template
    FeatureSpec,
    /// Concise bug fix template
    BugFix,
    /// Code refactoring template
    Refactor,
    /// Test writing template
    Test,
    /// Documentation update template
    Docs,
    /// Quick/small change template
    Quick,
    /// Performance optimization template
    PerformanceOptimization,
    /// Security audit template
    SecurityAudit,
    /// API integration template
    ApiIntegration,
    /// Database migration template
    DatabaseMigration,
    /// Dependency update template
    DependencyUpdate,
    /// CLI tool development template
    CliTool,
    /// Web API development template
    WebApi,
    /// Data pipeline template
    DataPipeline,
    /// UI component template
    UiComponent,
    /// Code review template
    CodeReview,
    /// Debug triage template
    DebugTriage,
    /// Release preparation template
    Release,
    /// Technical debt refactoring template
    TechDebt,
    /// Onboarding template
    Onboarding,
}

impl PromptTemplate {
    /// Returns the name/key for this template (used for CLI arguments).
    #[must_use]
    pub const fn name(self) -> &'static str {
        match self {
            Self::FeatureSpec => "feature-spec",
            Self::BugFix => "bug-fix",
            Self::Refactor => "refactor",
            Self::Test => "test",
            Self::Docs => "docs",
            Self::Quick => "quick",
            Self::PerformanceOptimization => "performance-optimization",
            Self::SecurityAudit => "security-audit",
            Self::ApiIntegration => "api-integration",
            Self::DatabaseMigration => "database-migration",
            Self::DependencyUpdate => "dependency-update",
            Self::CliTool => "cli-tool",
            Self::WebApi => "web-api",
            Self::DataPipeline => "data-pipeline",
            Self::UiComponent => "ui-component",
            Self::CodeReview => "code-review",
            Self::DebugTriage => "debug-triage",
            Self::Release => "release",
            Self::TechDebt => "tech-debt",
            Self::Onboarding => "onboarding",
        }
    }

    /// Returns a short description of this template.
    #[must_use]
    pub const fn description(self) -> &'static str {
        match self {
            Self::FeatureSpec => "Comprehensive product specification with questions to consider and code quality standards",
            Self::BugFix => "Bug fix template with investigation guidance and testing requirements",
            Self::Refactor => "Code refactoring template with behavior preservation emphasis",
            Self::Test => "Test writing template with edge case considerations",
            Self::Docs => "Documentation update template with completeness checklist",
            Self::Quick => "Quick/small change template (minimal)",
            Self::PerformanceOptimization => "Performance optimization template with benchmarking and profiling guidance",
            Self::SecurityAudit => "Security audit template covering OWASP Top 10 and vulnerability remediation",
            Self::ApiIntegration => "API integration template with error handling, retry logic, and resilience patterns",
            Self::DatabaseMigration => "Database migration template with zero-downtime strategies and rollback plans",
            Self::DependencyUpdate => "Dependency update template with migration guides and breaking change handling",
            Self::CliTool => "CLI tool development template with argument parsing, completion, and error handling",
            Self::WebApi => "Web API development template with REST design, error handling, and security considerations",
            Self::DataPipeline => "Data pipeline template with ETL processing, reliability, and monitoring guidance",
            Self::UiComponent => "UI component template with accessibility, responsive design, and user experience",
            Self::CodeReview => "Code review template for structured pull request feedback",
            Self::DebugTriage => "Debug triage template for systematic issue investigation and diagnosis",
            Self::Release => "Release preparation template with versioning, changelog, and deployment checklist",
            Self::TechDebt => "Technical debt refactoring template with prioritization and planning guidance",
            Self::Onboarding => "Onboarding template for learning new codebases efficiently",
        }
    }

    /// Returns the embedded template content.
    #[must_use]
    pub const fn content(self) -> &'static str {
        match self {
            Self::FeatureSpec => {
                include_str!("../../templates/prompts/feature-spec.md")
            }
            Self::BugFix => {
                include_str!("../../templates/prompts/bug-fix.md")
            }
            Self::Refactor => {
                include_str!("../../templates/prompts/refactor.md")
            }
            Self::Test => {
                include_str!("../../templates/prompts/test.md")
            }
            Self::Docs => {
                include_str!("../../templates/prompts/docs.md")
            }
            Self::Quick => {
                include_str!("../../templates/prompts/quick.md")
            }
            Self::PerformanceOptimization => {
                include_str!("../../templates/prompts/performance-optimization.md")
            }
            Self::SecurityAudit => {
                include_str!("../../templates/prompts/security-audit.md")
            }
            Self::ApiIntegration => {
                include_str!("../../templates/prompts/api-integration.md")
            }
            Self::DatabaseMigration => {
                include_str!("../../templates/prompts/database-migration.md")
            }
            Self::DependencyUpdate => {
                include_str!("../../templates/prompts/dependency-update.md")
            }
            Self::CliTool => {
                include_str!("../../templates/prompts/cli-tool.md")
            }
            Self::WebApi => {
                include_str!("../../templates/prompts/web-api.md")
            }
            Self::DataPipeline => {
                include_str!("../../templates/prompts/data-pipeline.md")
            }
            Self::UiComponent => {
                include_str!("../../templates/prompts/ui-component.md")
            }
            Self::CodeReview => {
                include_str!("../../templates/prompts/code-review.md")
            }
            Self::DebugTriage => {
                include_str!("../../templates/prompts/debug-triage.md")
            }
            Self::Release => {
                include_str!("../../templates/prompts/release.md")
            }
            Self::TechDebt => {
                include_str!("../../templates/prompts/tech-debt.md")
            }
            Self::Onboarding => {
                include_str!("../../templates/prompts/onboarding.md")
            }
        }
    }
}

impl fmt::Display for PromptTemplate {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", self.name())
    }
}

/// All available prompt templates.
pub const ALL_TEMPLATES: [PromptTemplate; 20] = [
    PromptTemplate::FeatureSpec,
    PromptTemplate::BugFix,
    PromptTemplate::Refactor,
    PromptTemplate::Test,
    PromptTemplate::Docs,
    PromptTemplate::Quick,
    PromptTemplate::PerformanceOptimization,
    PromptTemplate::SecurityAudit,
    PromptTemplate::ApiIntegration,
    PromptTemplate::DatabaseMigration,
    PromptTemplate::DependencyUpdate,
    PromptTemplate::CliTool,
    PromptTemplate::WebApi,
    PromptTemplate::DataPipeline,
    PromptTemplate::UiComponent,
    PromptTemplate::CodeReview,
    PromptTemplate::DebugTriage,
    PromptTemplate::Release,
    PromptTemplate::TechDebt,
    PromptTemplate::Onboarding,
];

/// Get a template by name.
///
/// # Arguments
///
/// * `name` - The template name (e.g., "feature-spec", "bug-fix")
///
/// # Returns
///
/// * `Some(PromptTemplate)` - The template if found
/// * `None` - If no template matches the name
#[must_use]
pub fn get_template(name: &str) -> Option<PromptTemplate> {
    match name {
        "feature-spec" => Some(PromptTemplate::FeatureSpec),
        "bug-fix" => Some(PromptTemplate::BugFix),
        "refactor" => Some(PromptTemplate::Refactor),
        "test" => Some(PromptTemplate::Test),
        "docs" => Some(PromptTemplate::Docs),
        "quick" => Some(PromptTemplate::Quick),
        "performance-optimization" => Some(PromptTemplate::PerformanceOptimization),
        "security-audit" => Some(PromptTemplate::SecurityAudit),
        "api-integration" => Some(PromptTemplate::ApiIntegration),
        "database-migration" => Some(PromptTemplate::DatabaseMigration),
        "dependency-update" => Some(PromptTemplate::DependencyUpdate),
        "cli-tool" => Some(PromptTemplate::CliTool),
        "web-api" => Some(PromptTemplate::WebApi),
        "data-pipeline" => Some(PromptTemplate::DataPipeline),
        "ui-component" => Some(PromptTemplate::UiComponent),
        "code-review" => Some(PromptTemplate::CodeReview),
        "debug-triage" => Some(PromptTemplate::DebugTriage),
        "release" => Some(PromptTemplate::Release),
        "tech-debt" => Some(PromptTemplate::TechDebt),
        "onboarding" => Some(PromptTemplate::Onboarding),
        _ => None,
    }
}

/// List all available templates with their descriptions.
///
/// Returns a vector of (name, description) tuples.
#[must_use]
pub fn list_templates() -> Vec<(&'static str, &'static str)> {
    vec![
        (
            PromptTemplate::FeatureSpec.name(),
            PromptTemplate::FeatureSpec.description(),
        ),
        (
            PromptTemplate::BugFix.name(),
            PromptTemplate::BugFix.description(),
        ),
        (
            PromptTemplate::Refactor.name(),
            PromptTemplate::Refactor.description(),
        ),
        (
            PromptTemplate::Test.name(),
            PromptTemplate::Test.description(),
        ),
        (
            PromptTemplate::Docs.name(),
            PromptTemplate::Docs.description(),
        ),
        (
            PromptTemplate::Quick.name(),
            PromptTemplate::Quick.description(),
        ),
        (
            PromptTemplate::PerformanceOptimization.name(),
            PromptTemplate::PerformanceOptimization.description(),
        ),
        (
            PromptTemplate::SecurityAudit.name(),
            PromptTemplate::SecurityAudit.description(),
        ),
        (
            PromptTemplate::ApiIntegration.name(),
            PromptTemplate::ApiIntegration.description(),
        ),
        (
            PromptTemplate::DatabaseMigration.name(),
            PromptTemplate::DatabaseMigration.description(),
        ),
        (
            PromptTemplate::DependencyUpdate.name(),
            PromptTemplate::DependencyUpdate.description(),
        ),
        (
            PromptTemplate::CliTool.name(),
            PromptTemplate::CliTool.description(),
        ),
        (
            PromptTemplate::WebApi.name(),
            PromptTemplate::WebApi.description(),
        ),
        (
            PromptTemplate::DataPipeline.name(),
            PromptTemplate::DataPipeline.description(),
        ),
        (
            PromptTemplate::UiComponent.name(),
            PromptTemplate::UiComponent.description(),
        ),
        (
            PromptTemplate::CodeReview.name(),
            PromptTemplate::CodeReview.description(),
        ),
        (
            PromptTemplate::DebugTriage.name(),
            PromptTemplate::DebugTriage.description(),
        ),
        (
            PromptTemplate::Release.name(),
            PromptTemplate::Release.description(),
        ),
        (
            PromptTemplate::TechDebt.name(),
            PromptTemplate::TechDebt.description(),
        ),
        (
            PromptTemplate::Onboarding.name(),
            PromptTemplate::Onboarding.description(),
        ),
    ]
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_template_names() {
        assert_eq!(PromptTemplate::FeatureSpec.name(), "feature-spec");
        assert_eq!(PromptTemplate::BugFix.name(), "bug-fix");
        assert_eq!(PromptTemplate::Refactor.name(), "refactor");
        assert_eq!(PromptTemplate::Test.name(), "test");
        assert_eq!(PromptTemplate::Docs.name(), "docs");
        assert_eq!(PromptTemplate::Quick.name(), "quick");
        assert_eq!(
            PromptTemplate::PerformanceOptimization.name(),
            "performance-optimization"
        );
        assert_eq!(PromptTemplate::SecurityAudit.name(), "security-audit");
        assert_eq!(PromptTemplate::ApiIntegration.name(), "api-integration");
        assert_eq!(
            PromptTemplate::DatabaseMigration.name(),
            "database-migration"
        );
        assert_eq!(PromptTemplate::DependencyUpdate.name(), "dependency-update");
        assert_eq!(PromptTemplate::CliTool.name(), "cli-tool");
        assert_eq!(PromptTemplate::WebApi.name(), "web-api");
        assert_eq!(PromptTemplate::DataPipeline.name(), "data-pipeline");
        assert_eq!(PromptTemplate::UiComponent.name(), "ui-component");
        assert_eq!(PromptTemplate::CodeReview.name(), "code-review");
        assert_eq!(PromptTemplate::DebugTriage.name(), "debug-triage");
        assert_eq!(PromptTemplate::Release.name(), "release");
        assert_eq!(PromptTemplate::TechDebt.name(), "tech-debt");
        assert_eq!(PromptTemplate::Onboarding.name(), "onboarding");
    }

    #[test]
    fn test_template_descriptions() {
        assert!(!PromptTemplate::FeatureSpec.description().is_empty());
        assert!(!PromptTemplate::BugFix.description().is_empty());
        assert!(!PromptTemplate::Refactor.description().is_empty());
        assert!(!PromptTemplate::Test.description().is_empty());
        assert!(!PromptTemplate::Docs.description().is_empty());
        assert!(!PromptTemplate::Quick.description().is_empty());
        assert!(!PromptTemplate::PerformanceOptimization
            .description()
            .is_empty());
        assert!(!PromptTemplate::SecurityAudit.description().is_empty());
        assert!(!PromptTemplate::ApiIntegration.description().is_empty());
        assert!(!PromptTemplate::DatabaseMigration.description().is_empty());
        assert!(!PromptTemplate::DependencyUpdate.description().is_empty());
        assert!(!PromptTemplate::CliTool.description().is_empty());
        assert!(!PromptTemplate::WebApi.description().is_empty());
        assert!(!PromptTemplate::DataPipeline.description().is_empty());
        assert!(!PromptTemplate::UiComponent.description().is_empty());
        assert!(!PromptTemplate::CodeReview.description().is_empty());
        assert!(!PromptTemplate::DebugTriage.description().is_empty());
        assert!(!PromptTemplate::Release.description().is_empty());
        assert!(!PromptTemplate::TechDebt.description().is_empty());
        assert!(!PromptTemplate::Onboarding.description().is_empty());
    }

    #[test]
    fn test_get_template() {
        assert_eq!(
            get_template("feature-spec"),
            Some(PromptTemplate::FeatureSpec)
        );
        assert_eq!(get_template("bug-fix"), Some(PromptTemplate::BugFix));
        assert_eq!(
            get_template("performance-optimization"),
            Some(PromptTemplate::PerformanceOptimization)
        );
        assert_eq!(
            get_template("security-audit"),
            Some(PromptTemplate::SecurityAudit)
        );
        assert_eq!(
            get_template("api-integration"),
            Some(PromptTemplate::ApiIntegration)
        );
        assert_eq!(
            get_template("database-migration"),
            Some(PromptTemplate::DatabaseMigration)
        );
        assert_eq!(
            get_template("dependency-update"),
            Some(PromptTemplate::DependencyUpdate)
        );
        assert_eq!(get_template("cli-tool"), Some(PromptTemplate::CliTool));
        assert_eq!(get_template("web-api"), Some(PromptTemplate::WebApi));
        assert_eq!(
            get_template("data-pipeline"),
            Some(PromptTemplate::DataPipeline)
        );
        assert_eq!(
            get_template("ui-component"),
            Some(PromptTemplate::UiComponent)
        );
        assert_eq!(
            get_template("code-review"),
            Some(PromptTemplate::CodeReview)
        );
        assert_eq!(
            get_template("debug-triage"),
            Some(PromptTemplate::DebugTriage)
        );
        assert_eq!(get_template("release"), Some(PromptTemplate::Release));
        assert_eq!(get_template("tech-debt"), Some(PromptTemplate::TechDebt));
        assert_eq!(get_template("onboarding"), Some(PromptTemplate::Onboarding));
        assert_eq!(get_template("nonexistent"), None);
    }

    #[test]
    fn test_list_templates() {
        let templates = list_templates();
        assert_eq!(templates.len(), 20);
        assert!(templates.iter().any(|(name, _)| name == &"feature-spec"));
        assert!(templates.iter().any(|(name, _)| name == &"bug-fix"));
        assert!(templates
            .iter()
            .any(|(name, _)| name == &"performance-optimization"));
        assert!(templates.iter().any(|(name, _)| name == &"security-audit"));
        assert!(templates.iter().any(|(name, _)| name == &"api-integration"));
        assert!(templates
            .iter()
            .any(|(name, _)| name == &"database-migration"));
        assert!(templates
            .iter()
            .any(|(name, _)| name == &"dependency-update"));
        assert!(templates.iter().any(|(name, _)| name == &"cli-tool"));
        assert!(templates.iter().any(|(name, _)| name == &"web-api"));
        assert!(templates.iter().any(|(name, _)| name == &"data-pipeline"));
        assert!(templates.iter().any(|(name, _)| name == &"ui-component"));
        assert!(templates.iter().any(|(name, _)| name == &"code-review"));
        assert!(templates.iter().any(|(name, _)| name == &"debug-triage"));
        assert!(templates.iter().any(|(name, _)| name == &"release"));
        assert!(templates.iter().any(|(name, _)| name == &"tech-debt"));
        assert!(templates.iter().any(|(name, _)| name == &"onboarding"));
    }

    #[test]
    fn test_template_content_has_goal() {
        ALL_TEMPLATES.iter().for_each(|template| {
            let content = template.content();
            assert!(
                content.contains("## Goal"),
                "Template {} missing Goal section",
                template.name()
            );
        });
    }

    #[test]
    fn test_template_content_has_acceptance() {
        ALL_TEMPLATES.iter().for_each(|template| {
            let content = template.content();
            assert!(
                content.contains("## Acceptance") || content.contains("## Acceptance Checks"),
                "Template {} missing Acceptance section",
                template.name()
            );
        });
    }
}