artifactize_harness/
verdict.rs1use std::sync::LazyLock;
2
3use serde_json::Value;
4
5mod candidate;
6pub use candidate::Candidate;
7mod issues;
8pub(crate) use issues::Issues;
9pub use issues::verdict;
10
11pub(crate) fn review_system(mut system: String) -> String {
14 system.push_str("\nPrioritize each finding by your judgment and explain what is wrong and where.\n\
15 For the review, return only the structured answer matching the supplied schema.\n\
16 If a person later asks a follow-up question about this review, answer that question in plain text instead, not JSON; the issues stay as recorded.");
17 system
18}
19
20pub const FOLLOW_UP: &str = "Follow-up question from a person about the review above. This is not a new review: the issues stay as recorded, and the instruction to return one JSON object applied only to the review. Answer in plain text, not JSON. You may use the tools again.";
22
23pub const MAX_RESPONSE_BYTES: usize = 1024 * 1024;
25const MAX_RESULT_CHARS: usize = 256_000;
27static RESULT_TOO_LARGE: LazyLock<String> =
28 LazyLock::new(|| format!("over_size: normalized result exceeds {MAX_RESULT_CHARS} characters"));
29const MAX_DIAGNOSTIC_CHARS: usize = 200;
31
32fn bounded_result(value: &Value) -> Result<(), &'static str> {
34 if serde_json::to_string(value)
35 .expect("result is JSON")
36 .encode_utf16()
37 .count()
38 > MAX_RESULT_CHARS
39 {
40 return Err(&RESULT_TOO_LARGE);
41 }
42 Ok(())
43}
44
45fn bounded(text: String) -> String {
46 if text.chars().count() > MAX_DIAGNOSTIC_CHARS {
47 text.chars().take(MAX_DIAGNOSTIC_CHARS).collect::<String>() + "… (truncated)"
48 } else {
49 text
50 }
51}
52
53#[derive(
56 Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Serialize, serde::Deserialize,
57)]
58pub enum Priority {
59 P0,
60 P1,
61 P2,
62 P3,
63}
64
65impl Priority {
66 pub const ALL: [Self; 4] = [Self::P0, Self::P1, Self::P2, Self::P3];
67
68 pub fn as_str(self) -> &'static str {
69 match self {
70 Self::P0 => "P0",
71 Self::P1 => "P1",
72 Self::P2 => "P2",
73 Self::P3 => "P3",
74 }
75 }
76}
77
78impl std::fmt::Display for Priority {
79 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
80 f.write_str(self.as_str())
81 }
82}
83
84#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
86#[serde(deny_unknown_fields)]
87pub struct AgentIssue {
88 pub priority: Priority,
89 pub reason: String,
90}
91
92#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
93#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
94pub enum Verdict {
95 Green,
96 Red,
97}
98
99impl Verdict {
100 pub fn as_str(self) -> &'static str {
101 match self {
102 Self::Green => "GREEN",
103 Self::Red => "RED",
104 }
105 }
106}
107
108#[derive(Debug, Clone, PartialEq, serde::Serialize)]
110pub struct Judgment {
111 pub verdict: Verdict,
112 pub issues: Vec<AgentIssue>,
113}