zeph-skills 0.18.0

SKILL.md parser, registry, embedding matcher, and hot-reload for Zeph
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
// SPDX-FileCopyrightText: 2026 Andrei G <bug-ops>
// SPDX-License-Identifier: MIT OR Apache-2.0

//! Self-learning skill evolution types and prompt templates.

/// Structured failure classification for tool execution errors.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FailureKind {
    ExitNonzero,
    Timeout,
    PermissionDenied,
    WrongApproach,
    Partial,
    SyntaxError,
    Unknown,
}

impl FailureKind {
    #[must_use]
    pub fn as_str(&self) -> &'static str {
        match self {
            Self::ExitNonzero => "exit_nonzero",
            Self::Timeout => "timeout",
            Self::PermissionDenied => "permission_denied",
            Self::WrongApproach => "wrong_approach",
            Self::Partial => "partial",
            Self::SyntaxError => "syntax_error",
            Self::Unknown => "unknown",
        }
    }

    /// Classify a failure kind from an error string heuristic.
    #[must_use]
    pub fn from_error(error: &str) -> Self {
        let lower = error.to_lowercase();
        if lower.contains("timed out") || lower.contains("timeout") {
            Self::Timeout
        } else if lower.contains("permission denied") {
            Self::PermissionDenied
        } else if lower.contains("exit code") {
            Self::ExitNonzero
        } else {
            Self::Unknown
        }
    }
}

impl From<zeph_tools::error_taxonomy::ToolErrorCategory> for FailureKind {
    fn from(cat: zeph_tools::error_taxonomy::ToolErrorCategory) -> Self {
        use zeph_tools::error_taxonomy::ToolErrorCategory as C;
        match cat {
            C::Timeout => Self::Timeout,
            // Quality-attributable: skill chose the wrong approach or wrong tool.
            C::PolicyBlocked | C::ConfirmationRequired | C::ToolNotFound => Self::WrongApproach,
            // LLM-supplied parameters were invalid or mistyped.
            C::InvalidParameters | C::TypeMismatch => Self::SyntaxError,
            // Infrastructure failures and non-quality outcomes are not attributable to the skill.
            C::RateLimited
            | C::ServerError
            | C::NetworkError
            | C::PermanentFailure
            | C::Cancelled => Self::Unknown,
        }
    }
}

/// Outcome classification for skill-attributed events.
#[derive(Debug, Clone)]
pub enum SkillOutcome {
    Success,
    ToolFailure {
        skill_name: String,
        error_context: String,
        tool_output: String,
        kind: FailureKind,
    },
    EmptyResponse {
        skill_name: String,
    },
    UserRejection {
        skill_name: String,
        feedback: String,
    },
}

impl SkillOutcome {
    /// Returns a stable string tag for DB storage.
    #[must_use]
    pub fn outcome_str(&self) -> &str {
        match self {
            Self::Success => "success",
            Self::ToolFailure { .. } => "tool_failure",
            Self::EmptyResponse { .. } => "empty_response",
            Self::UserRejection { .. } => "user_rejection",
        }
    }

    /// Extract the skill name from any non-success variant.
    #[must_use]
    pub fn skill_name(&self) -> Option<&str> {
        match self {
            Self::Success => None,
            Self::ToolFailure { skill_name, .. }
            | Self::EmptyResponse { skill_name }
            | Self::UserRejection { skill_name, .. } => Some(skill_name),
        }
    }
}

/// Aggregated metrics for a skill version.
#[derive(Debug, Clone)]
pub struct SkillMetrics {
    pub skill_name: String,
    pub version: i64,
    pub total: i64,
    pub successes: i64,
    pub failures: i64,
}

impl SkillMetrics {
    #[must_use]
    #[allow(clippy::cast_precision_loss)]
    pub fn success_rate(&self) -> f64 {
        if self.total == 0 {
            0.0
        } else {
            self.successes as f64 / self.total as f64
        }
    }
}

pub const REFLECTION_PROMPT_TEMPLATE: &str = "\
You attempted to help the user with their request using the following skill instructions:

<skill name=\"{name}\">
{body}
</skill>

The attempt failed with this error:
{error_context}

Tool output:
{tool_output}

Analyze what went wrong and suggest an improved approach. \
Then attempt to fulfill the original user request using the improved approach.";

/// Build a reflection prompt by substituting template placeholders.
#[must_use]
pub fn build_reflection_prompt(
    name: &str,
    body: &str,
    error_context: &str,
    tool_output: &str,
) -> String {
    REFLECTION_PROMPT_TEMPLATE
        .replace("{name}", name)
        .replace("{body}", body)
        .replace("{error_context}", error_context)
        .replace("{tool_output}", tool_output)
}

pub const IMPROVEMENT_PROMPT_TEMPLATE: &str = "\
The original skill instructions failed, but an alternative approach succeeded.

Original skill:
<skill name=\"{name}\">
{original_body}
</skill>

Failed approach error: {error_context}
Successful approach: {successful_response}
{user_feedback_section}
Generate an improved version of the skill instructions that incorporates the lesson \
learned. Keep the same format (markdown with bash code blocks). Be concise.
The improved skill body must contain at most 3 top-level sections (## headers). \
Keep it focused and concise.
Only output the improved skill body (no frontmatter, no explanation).";

/// Build an improvement prompt by substituting template placeholders.
#[must_use]
pub fn build_improvement_prompt(
    name: &str,
    original_body: &str,
    error_context: &str,
    successful_response: &str,
    user_feedback: Option<&str>,
) -> String {
    let feedback_section = user_feedback.map_or_else(String::new, |fb| {
        format!("\nUser feedback on the current skill:\n{fb}\n")
    });
    IMPROVEMENT_PROMPT_TEMPLATE
        .replace("{name}", name)
        .replace("{original_body}", original_body)
        .replace("{error_context}", error_context)
        .replace("{successful_response}", successful_response)
        .replace("{user_feedback_section}", &feedback_section)
}

#[derive(Debug, Clone, serde::Deserialize, schemars::JsonSchema)]
pub struct SkillEvaluation {
    pub should_improve: bool,
    pub issues: Vec<String>,
    pub severity: String,
}

pub const EVALUATION_PROMPT_TEMPLATE: &str = "\
Evaluate whether the following skill needs improvement based on the error context.

<skill name=\"{name}\">
{body}
</skill>

Error context: {error_context}
Tool output: {tool_output}
Current success rate: {success_rate}%

Determine if this is a systematic skill problem (should_improve: true) \
or a transient issue like network timeout, rate limit, etc. (should_improve: false).

Respond in JSON with fields: should_improve (bool), issues (list of strings), severity (\"low\", \"medium\", or \"high\").";

#[must_use]
#[allow(clippy::cast_precision_loss)]
pub fn build_evaluation_prompt(
    name: &str,
    body: &str,
    error_context: &str,
    tool_output: &str,
    metrics: &SkillMetrics,
) -> String {
    let rate = format!("{:.0}", metrics.success_rate() * 100.0);
    EVALUATION_PROMPT_TEMPLATE
        .replace("{name}", name)
        .replace("{body}", body)
        .replace("{error_context}", error_context)
        .replace("{tool_output}", tool_output)
        .replace("{success_rate}", &rate)
}

/// Domain gate prompt template for evaluating whether an auto-generated skill body stays
/// within the domain of the original skill.
///
/// Placeholders: `{description}`, `{name}`, `{body}` — substituted via
/// [`build_domain_gate_prompt`] using `str::replace` (not `format!()`).
///
/// The JSON example in the template uses literal curly braces, which is safe here
/// because the string is never passed through `format!()`.
pub const DOMAIN_GATE_PROMPT_TEMPLATE: &str = "\
Evaluate whether the following auto-generated skill version stays within \
the domain of the original skill.

Original skill description: {description}
Original skill name: {name}

Generated skill body:
<skill>
{body}
</skill>

Respond in JSON: {\"domain_relevant\": bool, \"reasoning\": string}
Return domain_relevant=true only if the generated body is focused on the \
same domain as the original skill description. Return false if it drifts \
into unrelated topics or adds capabilities beyond the original scope.";

/// LLM response for the domain evaluation gate.
#[derive(Debug, Clone, serde::Deserialize, schemars::JsonSchema)]
pub struct DomainGateResult {
    pub domain_relevant: bool,
    pub reasoning: String,
}

/// Build a domain gate prompt by substituting template placeholders.
///
/// Uses [`str::replace`] rather than `format!()` to avoid interpreting the JSON
/// example braces in the template as format arguments.
#[must_use]
pub fn build_domain_gate_prompt(name: &str, description: &str, body: &str) -> String {
    DOMAIN_GATE_PROMPT_TEMPLATE
        .replace("{description}", description)
        .replace("{name}", name)
        .replace("{body}", body)
}

/// Absolute maximum body size to prevent exponential growth across generations.
pub const MAX_BODY_BYTES: usize = 65_536;

/// Validate that the generated body does not exceed 2x the original size
/// and stays within the absolute cap.
#[must_use]
pub fn validate_body_size(original: &str, generated: &str) -> bool {
    generated.len() <= original.len() * 2 && generated.len() <= MAX_BODY_BYTES
}

/// Validate that the generated body contains at most `max_sections` top-level
/// markdown sections (lines starting with `"## "`).
///
/// Only H2 headers are counted; H1 (`# `) and H3+ (`### `) are ignored.
///
/// # Known limitation
///
/// Lines starting with `"## "` inside fenced code blocks (` ``` `) are also counted.
/// For MVP this is acceptable — SKILL.md bodies rarely contain code blocks with headers.
#[must_use]
pub fn validate_body_sections(body: &str, max_sections: u32) -> bool {
    let count = body.lines().filter(|l| l.starts_with("## ")).count();
    count <= max_sections as usize
}

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

    #[test]
    fn outcome_str_variants() {
        assert_eq!(SkillOutcome::Success.outcome_str(), "success");
        assert_eq!(
            SkillOutcome::ToolFailure {
                skill_name: "git".into(),
                error_context: "err".into(),
                tool_output: "out".into(),
                kind: FailureKind::Unknown,
            }
            .outcome_str(),
            "tool_failure"
        );
        assert_eq!(
            SkillOutcome::EmptyResponse {
                skill_name: "git".into(),
            }
            .outcome_str(),
            "empty_response"
        );
        assert_eq!(
            SkillOutcome::UserRejection {
                skill_name: "git".into(),
                feedback: "bad".into(),
            }
            .outcome_str(),
            "user_rejection"
        );
    }

    #[test]
    fn skill_name_extraction() {
        assert!(SkillOutcome::Success.skill_name().is_none());
        assert_eq!(
            SkillOutcome::ToolFailure {
                skill_name: "docker".into(),
                error_context: String::new(),
                tool_output: String::new(),
                kind: FailureKind::Unknown,
            }
            .skill_name(),
            Some("docker")
        );
        assert_eq!(
            SkillOutcome::EmptyResponse {
                skill_name: "git".into(),
            }
            .skill_name(),
            Some("git")
        );
        assert_eq!(
            SkillOutcome::UserRejection {
                skill_name: "sql".into(),
                feedback: String::new(),
            }
            .skill_name(),
            Some("sql")
        );
    }

    #[test]
    fn success_rate_zero_total() {
        let m = SkillMetrics {
            skill_name: "x".into(),
            version: 1,
            total: 0,
            successes: 0,
            failures: 0,
        };
        assert!((m.success_rate() - 0.0).abs() < f64::EPSILON);
    }

    #[test]
    fn success_rate_all_success() {
        let m = SkillMetrics {
            skill_name: "x".into(),
            version: 1,
            total: 10,
            successes: 10,
            failures: 0,
        };
        assert!((m.success_rate() - 1.0).abs() < f64::EPSILON);
    }

    #[test]
    fn success_rate_all_failures() {
        let m = SkillMetrics {
            skill_name: "x".into(),
            version: 1,
            total: 5,
            successes: 0,
            failures: 5,
        };
        assert!((m.success_rate() - 0.0).abs() < f64::EPSILON);
    }

    #[test]
    fn success_rate_mixed() {
        let m = SkillMetrics {
            skill_name: "x".into(),
            version: 1,
            total: 4,
            successes: 3,
            failures: 1,
        };
        assert!((m.success_rate() - 0.75).abs() < f64::EPSILON);
    }

    #[test]
    fn build_reflection_prompt_substitutes() {
        let result = build_reflection_prompt("git", "do git stuff", "exit code 1", "fatal: error");
        assert!(result.contains("<skill name=\"git\">"));
        assert!(result.contains("do git stuff"));
        assert!(result.contains("exit code 1"));
        assert!(result.contains("fatal: error"));
    }

    #[test]
    fn build_improvement_prompt_without_feedback() {
        let result = build_improvement_prompt("git", "original body", "the error", "the fix", None);
        assert!(result.contains("<skill name=\"git\">"));
        assert!(result.contains("original body"));
        assert!(result.contains("the error"));
        assert!(result.contains("the fix"));
        assert!(!result.contains("User feedback"));
    }

    #[test]
    fn build_improvement_prompt_with_feedback() {
        let result = build_improvement_prompt(
            "git",
            "original body",
            "the error",
            "the fix",
            Some("please fix the commit flow"),
        );
        assert!(result.contains("User feedback on the current skill:"));
        assert!(result.contains("please fix the commit flow"));
    }

    #[test]
    fn validate_body_size_within_limit() {
        assert!(validate_body_size("12345", "1234567890"));
    }

    #[test]
    fn validate_body_size_exceeds_limit() {
        assert!(!validate_body_size("12345", "12345678901"));
    }

    #[test]
    fn validate_body_size_empty_original() {
        assert!(validate_body_size("", ""));
        assert!(!validate_body_size("", "x"));
    }

    #[test]
    fn build_evaluation_prompt_substitutes() {
        let metrics = SkillMetrics {
            skill_name: "git".into(),
            version: 1,
            total: 10,
            successes: 7,
            failures: 3,
        };
        let result =
            build_evaluation_prompt("git", "do git stuff", "exit code 1", "fatal", &metrics);
        assert!(result.contains("<skill name=\"git\">"));
        assert!(result.contains("do git stuff"));
        assert!(result.contains("exit code 1"));
        assert!(result.contains("fatal"));
        assert!(result.contains("70%"));
    }

    #[test]
    fn skill_evaluation_deserialize() {
        let json = r#"{"should_improve": true, "issues": ["bad pattern"], "severity": "high"}"#;
        let eval: SkillEvaluation = serde_json::from_str(json).unwrap();
        assert!(eval.should_improve);
        assert_eq!(eval.issues.len(), 1);
        assert_eq!(eval.severity, "high");
    }

    #[test]
    fn skill_evaluation_skip() {
        let json = r#"{"should_improve": false, "issues": [], "severity": "low"}"#;
        let eval: SkillEvaluation = serde_json::from_str(json).unwrap();
        assert!(!eval.should_improve);
        assert!(eval.issues.is_empty());
    }

    #[test]
    fn validate_body_size_absolute_cap() {
        let large_original = "x".repeat(40_000);
        let large_generated = "x".repeat(70_000);
        // Within 2x but exceeds MAX_BODY_BYTES (65536)
        assert!(!validate_body_size(&large_original, &large_generated));
    }

    #[test]
    fn validate_body_sections_within_limit() {
        let body = "## Setup\ndo stuff\n## Usage\nmore stuff\n";
        assert!(validate_body_sections(body, 3));
    }

    #[test]
    fn validate_body_sections_at_limit() {
        let body = "## Setup\n## Usage\n## Tips\n";
        assert!(validate_body_sections(body, 3));
    }

    #[test]
    fn validate_body_sections_exceeds_limit() {
        let body = "## A\n## B\n## C\n## D\n";
        assert!(!validate_body_sections(body, 3));
    }

    #[test]
    fn validate_body_sections_no_sections() {
        let body = "Just some text without any headers.\n";
        assert!(validate_body_sections(body, 3));
    }

    #[test]
    fn validate_body_sections_h1_not_counted() {
        let body = "# Title\n## Section\n### Subsection\n";
        // Only "## Section" is counted; H1 and H3+ are not.
        assert!(validate_body_sections(body, 1));
    }

    #[test]
    fn domain_gate_result_deserialize() {
        let json = r#"{"domain_relevant": true, "reasoning": "matches original domain"}"#;
        let result: DomainGateResult = serde_json::from_str(json).unwrap();
        assert!(result.domain_relevant);
        assert_eq!(result.reasoning, "matches original domain");
    }

    #[test]
    fn domain_gate_result_false() {
        let json = r#"{"domain_relevant": false, "reasoning": "drifted to unrelated topic"}"#;
        let result: DomainGateResult = serde_json::from_str(json).unwrap();
        assert!(!result.domain_relevant);
    }

    #[test]
    fn build_domain_gate_prompt_substitutes() {
        let result = build_domain_gate_prompt(
            "git-helper",
            "Git workflow assistant",
            "## Usage\nRun git commands",
        );
        assert!(result.contains("git-helper"));
        assert!(result.contains("Git workflow assistant"));
        assert!(result.contains("## Usage\nRun git commands"));
        // Ensure the JSON example braces are preserved literally.
        assert!(result.contains("{\"domain_relevant\""));
    }

    #[test]
    fn improvement_prompt_includes_section_limit() {
        assert!(
            IMPROVEMENT_PROMPT_TEMPLATE.contains("at most 3 top-level sections"),
            "IMPROVEMENT_PROMPT_TEMPLATE must mention the section limit"
        );
    }

    // Priority 2: SkillEvaluation deserialization edge cases

    #[test]
    fn skill_evaluation_missing_severity_fails() {
        let json = r#"{"should_improve": true, "issues": ["bad pattern"]}"#;
        let result: Result<SkillEvaluation, _> = serde_json::from_str(json);
        assert!(
            result.is_err(),
            "expected error when severity field is missing"
        );
    }

    #[test]
    fn skill_evaluation_should_improve_as_string_fails() {
        let json = r#"{"should_improve": "true", "issues": [], "severity": "low"}"#;
        let result: Result<SkillEvaluation, _> = serde_json::from_str(json);
        assert!(
            result.is_err(),
            "expected error when should_improve is a string"
        );
    }

    #[test]
    fn skill_evaluation_extra_unknown_fields_succeeds() {
        let json =
            r#"{"should_improve": false, "issues": [], "severity": "low", "extra_field": 42}"#;
        let result: SkillEvaluation = serde_json::from_str(json).unwrap();
        assert!(!result.should_improve);
        assert_eq!(result.severity, "low");
    }

    // Priority 3: Proptest

    use proptest::prelude::*;

    #[test]
    fn failure_kind_from_error_timeout() {
        assert_eq!(
            FailureKind::from_error("operation timed out"),
            FailureKind::Timeout
        );
        assert_eq!(
            FailureKind::from_error("timeout after 30s"),
            FailureKind::Timeout
        );
    }

    #[test]
    fn failure_kind_from_error_permission_denied() {
        assert_eq!(
            FailureKind::from_error("error: permission denied"),
            FailureKind::PermissionDenied
        );
    }

    #[test]
    fn failure_kind_from_error_exit_nonzero() {
        assert_eq!(
            FailureKind::from_error("command failed [exit code 1]"),
            FailureKind::ExitNonzero
        );
        assert_eq!(
            FailureKind::from_error("exit code 128"),
            FailureKind::ExitNonzero
        );
    }

    #[test]
    fn failure_kind_from_error_unknown() {
        assert_eq!(
            FailureKind::from_error("something went wrong"),
            FailureKind::Unknown
        );
        assert_eq!(FailureKind::from_error(""), FailureKind::Unknown);
    }

    #[test]
    fn failure_kind_as_str_roundtrip() {
        assert_eq!(FailureKind::ExitNonzero.as_str(), "exit_nonzero");
        assert_eq!(FailureKind::Timeout.as_str(), "timeout");
        assert_eq!(FailureKind::PermissionDenied.as_str(), "permission_denied");
        assert_eq!(FailureKind::WrongApproach.as_str(), "wrong_approach");
        assert_eq!(FailureKind::Partial.as_str(), "partial");
        assert_eq!(FailureKind::SyntaxError.as_str(), "syntax_error");
        assert_eq!(FailureKind::Unknown.as_str(), "unknown");
    }

    #[test]
    fn failure_kind_from_tool_error_category_key_mappings() {
        use zeph_tools::error_taxonomy::ToolErrorCategory as C;
        assert_eq!(FailureKind::from(C::Timeout), FailureKind::Timeout);
        assert_eq!(
            FailureKind::from(C::PolicyBlocked),
            FailureKind::WrongApproach
        );
        assert_eq!(
            FailureKind::from(C::ToolNotFound),
            FailureKind::WrongApproach
        );
        assert_eq!(
            FailureKind::from(C::InvalidParameters),
            FailureKind::SyntaxError
        );
        assert_eq!(FailureKind::from(C::TypeMismatch), FailureKind::SyntaxError);
        assert_eq!(FailureKind::from(C::RateLimited), FailureKind::Unknown);
        assert_eq!(FailureKind::from(C::ServerError), FailureKind::Unknown);
        assert_eq!(FailureKind::from(C::NetworkError), FailureKind::Unknown);
        assert_eq!(FailureKind::from(C::PermanentFailure), FailureKind::Unknown);
        assert_eq!(
            FailureKind::from(C::ConfirmationRequired),
            FailureKind::WrongApproach
        );
        assert_eq!(FailureKind::from(C::Cancelled), FailureKind::Unknown);
    }

    proptest! {
        #[test]
        fn build_evaluation_prompt_never_panics(
            name in ".*",
            body in ".*",
            desc in ".*",
            total in 0i64..=1000,
            successes in 0i64..=1000,
        ) {
            let failures = total - successes.min(total);
            let metrics = SkillMetrics {
                skill_name: name.clone(),
                version: 1,
                total,
                successes: successes.min(total),
                failures,
            };
            let _ = build_evaluation_prompt(&name, &body, &desc, "", &metrics);
        }
    }
}