1#[derive(Debug, Clone)]
15pub struct StdlibPersona {
16 pub name: &'static str,
17 pub description: &'static str,
18 pub tone: &'static str,
19 pub domain: &'static [&'static str],
20 pub confidence_threshold: f64,
21 pub cite_sources: bool,
22 pub category: &'static str,
23 pub version: &'static str,
24}
25
26#[derive(Debug, Clone)]
27pub struct StdlibAnchor {
28 pub name: &'static str,
29 pub description: &'static str,
30 pub severity: &'static str,
31 pub require: &'static [&'static str],
32 pub reject: &'static [&'static str],
33 pub confidence_floor: Option<f64>,
34 pub version: &'static str,
35}
36
37#[derive(Debug, Clone)]
38pub struct StdlibFlow {
39 pub name: &'static str,
40 pub description: &'static str,
41 pub parameters: &'static [(&'static str, &'static str)],
42 pub return_type: &'static str,
43 pub category: &'static str,
44 pub version: &'static str,
45}
46
47#[derive(Debug, Clone)]
48pub struct StdlibTool {
49 pub name: &'static str,
50 pub description: &'static str,
51 pub provider: &'static str,
52 pub timeout: u32,
53 pub requires_api_key: bool,
54 pub sandbox: bool,
55 pub version: &'static str,
56}
57
58#[derive(Debug, Clone)]
59pub enum StdlibEntry {
60 Persona(StdlibPersona),
61 Anchor(StdlibAnchor),
62 Flow(StdlibFlow),
63 Tool(StdlibTool),
64}
65
66impl StdlibEntry {
67 pub fn name(&self) -> &str {
68 match self {
69 StdlibEntry::Persona(p) => p.name,
70 StdlibEntry::Anchor(a) => a.name,
71 StdlibEntry::Flow(f) => f.name,
72 StdlibEntry::Tool(t) => t.name,
73 }
74 }
75
76 pub fn description(&self) -> &str {
77 match self {
78 StdlibEntry::Persona(p) => p.description,
79 StdlibEntry::Anchor(a) => a.description,
80 StdlibEntry::Flow(f) => f.description,
81 StdlibEntry::Tool(t) => t.description,
82 }
83 }
84
85 pub fn version(&self) -> &str {
86 match self {
87 StdlibEntry::Persona(p) => p.version,
88 StdlibEntry::Anchor(a) => a.version,
89 StdlibEntry::Flow(f) => f.version,
90 StdlibEntry::Tool(t) => t.version,
91 }
92 }
93}
94
95pub const PERSONAS: &[StdlibPersona] = &[
98 StdlibPersona {
99 name: "Analyst",
100 description: "Expert data analyst with deep pattern recognition skills.",
101 tone: "precise",
102 domain: &["data analysis", "pattern recognition", "statistics"],
103 confidence_threshold: 0.85,
104 cite_sources: true,
105 category: "analysis",
106 version: "0.1.0",
107 },
108 StdlibPersona {
109 name: "LegalExpert",
110 description: "A precise legal analyst for contract review, compliance checking, and regulatory analysis. Does not provide legal advice.",
111 tone: "precise",
112 domain: &["contract law", "compliance", "regulation"],
113 confidence_threshold: 0.90,
114 cite_sources: true,
115 category: "legal",
116 version: "0.1.0",
117 },
118 StdlibPersona {
119 name: "Coder",
120 description: "A technical coding expert for software development, debugging, code review, and architectural decisions.",
121 tone: "technical",
122 domain: &["software engineering", "debugging", "architecture"],
123 confidence_threshold: 0.80,
124 cite_sources: false,
125 category: "engineering",
126 version: "0.1.0",
127 },
128 StdlibPersona {
129 name: "Researcher",
130 description: "A rigorous academic researcher specializing in literature review, source verification, and methodological analysis.",
131 tone: "technical",
132 domain: &["academic research", "citation", "methodology"],
133 confidence_threshold: 0.82,
134 cite_sources: true,
135 category: "research",
136 version: "0.1.0",
137 },
138 StdlibPersona {
139 name: "Writer",
140 description: "A creative writer for content generation, editing, copywriting, and narrative crafting.",
141 tone: "creative",
142 domain: &["content creation", "editing", "copywriting"],
143 confidence_threshold: 0.75,
144 cite_sources: false,
145 category: "creative",
146 version: "0.1.0",
147 },
148 StdlibPersona {
149 name: "Summarizer",
150 description: "A condensation specialist that distills complex information into clear, concise summaries.",
151 tone: "friendly",
152 domain: &["condensation", "abstraction", "synthesis"],
153 confidence_threshold: 0.80,
154 cite_sources: false,
155 category: "analysis",
156 version: "0.1.0",
157 },
158 StdlibPersona {
159 name: "Critic",
160 description: "A formal evaluator specializing in critical assessment, risk analysis, and quality review.",
161 tone: "formal",
162 domain: &["evaluation", "risk assessment", "review"],
163 confidence_threshold: 0.85,
164 cite_sources: true,
165 category: "analysis",
166 version: "0.1.0",
167 },
168 StdlibPersona {
169 name: "Translator",
170 description: "A multilingual translator with deep understanding of cultural nuances and idiomatic expressions.",
171 tone: "conversational",
172 domain: &["cross-language translation", "cross-cultural adaptation"],
173 confidence_threshold: 0.80,
174 cite_sources: false,
175 category: "translation",
176 version: "0.1.0",
177 },
178];
179
180pub const ANCHORS: &[StdlibAnchor] = &[
183 StdlibAnchor {
185 name: "NoHallucination",
186 description: "Requires cited sources for all claims. Rejects speculation and unverifiable assertions.",
187 severity: "error",
188 require: &["source_citation"],
189 reject: &["speculation", "unverifiable_claim"],
190 confidence_floor: Some(0.80),
191 version: "0.1.0",
192 },
193 StdlibAnchor {
194 name: "FactualOnly",
195 description: "Restricts output to factual claims only. No opinions, unless explicitly declared as Opinion type.",
196 severity: "error",
197 require: &["factual_grounding"],
198 reject: &["opinion", "speculation"],
199 confidence_floor: Some(0.85),
200 version: "0.1.0",
201 },
202 StdlibAnchor {
203 name: "SafeOutput",
204 description: "Rejects harmful content, violence, and hate speech.",
205 severity: "error",
206 require: &[],
207 reject: &["harmful_content", "violence", "hate_speech"],
208 confidence_floor: None,
209 version: "0.1.0",
210 },
211 StdlibAnchor {
212 name: "PrivacyGuard",
213 description: "Prevents exposure of PII (SSNs, credit cards, emails, phone numbers).",
214 severity: "error",
215 require: &[],
216 reject: &["pii", "personal_data", "ssn", "phone_number"],
217 confidence_floor: None,
218 version: "0.1.0",
219 },
220 StdlibAnchor {
221 name: "NoBias",
222 description: "Enforces political and demographic neutrality. Detects loaded language and explicit bias.",
223 severity: "warning",
224 require: &[],
225 reject: &["political_bias", "demographic_bias", "gender_bias"],
226 confidence_floor: None,
227 version: "0.1.0",
228 },
229 StdlibAnchor {
230 name: "ChildSafe",
231 description: "Ensures all content is appropriate for minors. Rejects adult content, graphic violence, profanity, and drugs.",
232 severity: "error",
233 require: &[],
234 reject: &["adult_content", "violence", "profanity", "drugs"],
235 confidence_floor: None,
236 version: "0.1.0",
237 },
238 StdlibAnchor {
239 name: "NoCodeExecution",
240 description: "Prevents code execution, system commands, and file operations.",
241 severity: "error",
242 require: &[],
243 reject: &["code_execution", "system_command", "file_write"],
244 confidence_floor: None,
245 version: "0.1.0",
246 },
247 StdlibAnchor {
248 name: "AuditTrail",
249 description: "Forces full reasoning trace in output. Requires visible reasoning steps for audit and review purposes.",
250 severity: "warning",
251 require: &["human_review"],
252 reject: &[],
253 confidence_floor: None,
254 version: "0.1.0",
255 },
256 StdlibAnchor {
258 name: "SyllogismChecker",
259 description: "Syntactically enforces standard logical format using 'Premise:' and 'Conclusion:' identifiers.",
260 severity: "error",
261 require: &["logical_structure"],
262 reject: &[],
263 confidence_floor: None,
264 version: "0.1.0",
265 },
266 StdlibAnchor {
267 name: "ChainOfThoughtValidator",
268 description: "Forces the model to explicitly write out step sequences before producing a final answer.",
269 severity: "error",
270 require: &["step_by_step"],
271 reject: &[],
272 confidence_floor: None,
273 version: "0.1.0",
274 },
275 StdlibAnchor {
276 name: "RequiresCitation",
277 description: "Strict verification enforcing explicit academic-style inline citations or external URLs.",
278 severity: "error",
279 require: &["inline_citation"],
280 reject: &["unverifiable_claim"],
281 confidence_floor: None,
282 version: "0.1.0",
283 },
284 StdlibAnchor {
285 name: "AgnosticFallback",
286 description: "Requires the model to explicitly state a lack of information instead of speculating.",
287 severity: "error",
288 require: &["epistemic_honesty"],
289 reject: &["unwarranted_speculation"],
290 confidence_floor: None,
291 version: "0.1.0",
292 },
293];
294
295pub const FLOWS: &[StdlibFlow] = &[
298 StdlibFlow {
299 name: "Summarize",
300 description: "Condense any document into a concise summary.",
301 parameters: &[("doc", "Document")],
302 return_type: "Summary",
303 category: "analysis",
304 version: "0.1.0",
305 },
306 StdlibFlow {
307 name: "ExtractEntities",
308 description: "Extract and classify named entities from a document.",
309 parameters: &[("doc", "Document")],
310 return_type: "EntityMap",
311 category: "extraction",
312 version: "0.1.0",
313 },
314 StdlibFlow {
315 name: "CompareDocuments",
316 description: "Compare two documents side-by-side with detailed analysis.",
317 parameters: &[("doc_a", "Document"), ("doc_b", "Document")],
318 return_type: "StructuredReport",
319 category: "analysis",
320 version: "0.1.0",
321 },
322 StdlibFlow {
323 name: "TranslateDocument",
324 description: "Translate a document with cultural context preservation.",
325 parameters: &[("doc", "Document"), ("target_lang", "String")],
326 return_type: "Translation",
327 category: "translation",
328 version: "0.1.0",
329 },
330 StdlibFlow {
331 name: "FactCheck",
332 description: "Verify factual claims with sourced evidence.",
333 parameters: &[("claims", "Document")],
334 return_type: "StructuredReport",
335 category: "verification",
336 version: "0.1.0",
337 },
338 StdlibFlow {
339 name: "SentimentAnalysis",
340 description: "Analyze tone and sentiment with nuanced scoring.",
341 parameters: &[("doc", "Document")],
342 return_type: "SentimentScore",
343 category: "analysis",
344 version: "0.1.0",
345 },
346 StdlibFlow {
347 name: "ClassifyContent",
348 description: "Classify content into user-defined categories.",
349 parameters: &[("doc", "Document"), ("categories", "String")],
350 return_type: "EntityMap",
351 category: "classification",
352 version: "0.1.0",
353 },
354 StdlibFlow {
355 name: "GenerateReport",
356 description: "Generate a structured report from raw data.",
357 parameters: &[("data", "Document")],
358 return_type: "StructuredReport",
359 category: "reporting",
360 version: "0.1.0",
361 },
362];
363
364pub const TOOLS: &[StdlibTool] = &[
367 StdlibTool {
368 name: "WebSearch",
369 description: "Live web search via Brave Search API.",
370 provider: "brave",
371 timeout: 10,
372 requires_api_key: true,
373 sandbox: false,
374 version: "0.1.0",
375 },
376 StdlibTool {
377 name: "CodeExecutor",
378 description: "Safe sandboxed code execution.",
379 provider: "",
380 timeout: 30,
381 requires_api_key: false,
382 sandbox: true,
383 version: "0.1.0",
384 },
385 StdlibTool {
386 name: "FileReader",
387 description: "Read local or remote files.",
388 provider: "",
389 timeout: 5,
390 requires_api_key: false,
391 sandbox: false,
392 version: "0.1.0",
393 },
394 StdlibTool {
395 name: "PDFExtractor",
396 description: "Extract text and structure from PDF.",
397 provider: "",
398 timeout: 15,
399 requires_api_key: false,
400 sandbox: false,
401 version: "0.1.0",
402 },
403 StdlibTool {
404 name: "ImageAnalyzer",
405 description: "Analyze images using vision capabilities.",
406 provider: "",
407 timeout: 20,
408 requires_api_key: true,
409 sandbox: false,
410 version: "0.1.0",
411 },
412 StdlibTool {
413 name: "Calculator",
414 description: "Precise arithmetic with safe expression eval.",
415 provider: "",
416 timeout: 2,
417 requires_api_key: false,
418 sandbox: true,
419 version: "0.1.0",
420 },
421 StdlibTool {
422 name: "DateTimeTool",
423 description: "Temporal reasoning — current date, time, timestamps.",
424 provider: "",
425 timeout: 1,
426 requires_api_key: false,
427 sandbox: true,
428 version: "0.1.0",
429 },
430 StdlibTool {
431 name: "APICall",
432 description: "Generic REST API caller.",
433 provider: "",
434 timeout: 30,
435 requires_api_key: true,
436 sandbox: false,
437 version: "0.1.0",
438 },
439];
440
441pub const VALID_NAMESPACES: &[&str] = &["anchors", "flows", "personas", "tools"];
444
445pub fn list_namespace(namespace: &str) -> Vec<StdlibEntry> {
447 match namespace {
448 "personas" => PERSONAS.iter().map(|p| StdlibEntry::Persona(p.clone())).collect(),
449 "anchors" => ANCHORS.iter().map(|a| StdlibEntry::Anchor(a.clone())).collect(),
450 "flows" => FLOWS.iter().map(|f| StdlibEntry::Flow(f.clone())).collect(),
451 "tools" => TOOLS.iter().map(|t| StdlibEntry::Tool(t.clone())).collect(),
452 _ => Vec::new(),
453 }
454}
455
456pub fn resolve(name: &str) -> Option<StdlibEntry> {
458 if let Some(p) = PERSONAS.iter().find(|p| p.name == name) {
459 return Some(StdlibEntry::Persona(p.clone()));
460 }
461 if let Some(a) = ANCHORS.iter().find(|a| a.name == name) {
462 return Some(StdlibEntry::Anchor(a.clone()));
463 }
464 if let Some(f) = FLOWS.iter().find(|f| f.name == name) {
465 return Some(StdlibEntry::Flow(f.clone()));
466 }
467 if let Some(t) = TOOLS.iter().find(|t| t.name == name) {
468 return Some(StdlibEntry::Tool(t.clone()));
469 }
470 None
471}
472
473pub fn has(name: &str) -> bool {
475 resolve(name).is_some()
476}
477
478pub fn total_count() -> usize {
480 PERSONAS.len() + ANCHORS.len() + FLOWS.len() + TOOLS.len()
481}