axon-lang 2.11.0

AXON — the formal cognitive language: a deterministic, proof-carrying AI runtime. Native Rust lexer/parser/type-checker/IR generator (re-exported from axon-frontend) plus the runtime: typed channels (π-calculus mobility, capability extrusion), algebraic effects via Free Monad CPS handlers, lease kernel + reconcile loop, the Epistemic Security Kernel, Trust Types, Proof-Carrying Code (independently verifiable proof objects), and the closed-catalog extension mechanism. Crate publishes as `axon-lang`; library import is `use axon::*` so existing call sites keep working unchanged.
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
//! AXON Standard Library — built-in personas, anchors, flows, and tools.
//!
//! This module provides a static registry of all stdlib components,
//! mirroring the Python `axon.stdlib` module with hardcoded definitions.
//!
//! 4 namespaces × 36 total entries:
//!   - 8 personas (Analyst, LegalExpert, Coder, Researcher, Writer, Summarizer, Critic, Translator)
//!   - 12 anchors (8 core + 4 logic/epistemic)
//!   - 8 flows (Summarize, ExtractEntities, CompareDocuments, etc.)
//!   - 8 tools (WebSearch, CodeExecutor, FileReader, etc.)

// ── Entry types ─────────────────────────────────────────────────────────────

#[derive(Debug, Clone)]
pub struct StdlibPersona {
    pub name: &'static str,
    pub description: &'static str,
    pub tone: &'static str,
    pub domain: &'static [&'static str],
    pub confidence_threshold: f64,
    pub cite_sources: bool,
    pub category: &'static str,
    pub version: &'static str,
}

#[derive(Debug, Clone)]
pub struct StdlibAnchor {
    pub name: &'static str,
    pub description: &'static str,
    pub severity: &'static str,
    pub require: &'static [&'static str],
    pub reject: &'static [&'static str],
    pub confidence_floor: Option<f64>,
    pub version: &'static str,
}

#[derive(Debug, Clone)]
pub struct StdlibFlow {
    pub name: &'static str,
    pub description: &'static str,
    pub parameters: &'static [(&'static str, &'static str)],
    pub return_type: &'static str,
    pub category: &'static str,
    pub version: &'static str,
}

#[derive(Debug, Clone)]
pub struct StdlibTool {
    pub name: &'static str,
    pub description: &'static str,
    pub provider: &'static str,
    pub timeout: u32,
    pub requires_api_key: bool,
    pub sandbox: bool,
    pub version: &'static str,
}

#[derive(Debug, Clone)]
pub enum StdlibEntry {
    Persona(StdlibPersona),
    Anchor(StdlibAnchor),
    Flow(StdlibFlow),
    Tool(StdlibTool),
}

impl StdlibEntry {
    pub fn name(&self) -> &str {
        match self {
            StdlibEntry::Persona(p) => p.name,
            StdlibEntry::Anchor(a) => a.name,
            StdlibEntry::Flow(f) => f.name,
            StdlibEntry::Tool(t) => t.name,
        }
    }

    pub fn description(&self) -> &str {
        match self {
            StdlibEntry::Persona(p) => p.description,
            StdlibEntry::Anchor(a) => a.description,
            StdlibEntry::Flow(f) => f.description,
            StdlibEntry::Tool(t) => t.description,
        }
    }

    pub fn version(&self) -> &str {
        match self {
            StdlibEntry::Persona(p) => p.version,
            StdlibEntry::Anchor(a) => a.version,
            StdlibEntry::Flow(f) => f.version,
            StdlibEntry::Tool(t) => t.version,
        }
    }
}

// ── Personas (8) ────────────────────────────────────────────────────────────

pub const PERSONAS: &[StdlibPersona] = &[
    StdlibPersona {
        name: "Analyst",
        description: "Expert data analyst with deep pattern recognition skills.",
        tone: "precise",
        domain: &["data analysis", "pattern recognition", "statistics"],
        confidence_threshold: 0.85,
        cite_sources: true,
        category: "analysis",
        version: "0.1.0",
    },
    StdlibPersona {
        name: "LegalExpert",
        description: "A precise legal analyst for contract review, compliance checking, and regulatory analysis. Does not provide legal advice.",
        tone: "precise",
        domain: &["contract law", "compliance", "regulation"],
        confidence_threshold: 0.90,
        cite_sources: true,
        category: "legal",
        version: "0.1.0",
    },
    StdlibPersona {
        name: "Coder",
        description: "A technical coding expert for software development, debugging, code review, and architectural decisions.",
        tone: "technical",
        domain: &["software engineering", "debugging", "architecture"],
        confidence_threshold: 0.80,
        cite_sources: false,
        category: "engineering",
        version: "0.1.0",
    },
    StdlibPersona {
        name: "Researcher",
        description: "A rigorous academic researcher specializing in literature review, source verification, and methodological analysis.",
        tone: "technical",
        domain: &["academic research", "citation", "methodology"],
        confidence_threshold: 0.82,
        cite_sources: true,
        category: "research",
        version: "0.1.0",
    },
    StdlibPersona {
        name: "Writer",
        description: "A creative writer for content generation, editing, copywriting, and narrative crafting.",
        tone: "creative",
        domain: &["content creation", "editing", "copywriting"],
        confidence_threshold: 0.75,
        cite_sources: false,
        category: "creative",
        version: "0.1.0",
    },
    StdlibPersona {
        name: "Summarizer",
        description: "A condensation specialist that distills complex information into clear, concise summaries.",
        tone: "friendly",
        domain: &["condensation", "abstraction", "synthesis"],
        confidence_threshold: 0.80,
        cite_sources: false,
        category: "analysis",
        version: "0.1.0",
    },
    StdlibPersona {
        name: "Critic",
        description: "A formal evaluator specializing in critical assessment, risk analysis, and quality review.",
        tone: "formal",
        domain: &["evaluation", "risk assessment", "review"],
        confidence_threshold: 0.85,
        cite_sources: true,
        category: "analysis",
        version: "0.1.0",
    },
    StdlibPersona {
        name: "Translator",
        description: "A multilingual translator with deep understanding of cultural nuances and idiomatic expressions.",
        tone: "conversational",
        domain: &["cross-language translation", "cross-cultural adaptation"],
        confidence_threshold: 0.80,
        cite_sources: false,
        category: "translation",
        version: "0.1.0",
    },
];

// ── Anchors (12) ────────────────────────────────────────────────────────────

pub const ANCHORS: &[StdlibAnchor] = &[
    // Core anchors (8)
    StdlibAnchor {
        name: "NoHallucination",
        description: "Requires cited sources for all claims. Rejects speculation and unverifiable assertions.",
        severity: "error",
        require: &["source_citation"],
        reject: &["speculation", "unverifiable_claim"],
        confidence_floor: Some(0.80),
        version: "0.1.0",
    },
    StdlibAnchor {
        name: "FactualOnly",
        description: "Restricts output to factual claims only. No opinions, unless explicitly declared as Opinion type.",
        severity: "error",
        require: &["factual_grounding"],
        reject: &["opinion", "speculation"],
        confidence_floor: Some(0.85),
        version: "0.1.0",
    },
    StdlibAnchor {
        name: "SafeOutput",
        description: "Rejects harmful content, violence, and hate speech.",
        severity: "error",
        require: &[],
        reject: &["harmful_content", "violence", "hate_speech"],
        confidence_floor: None,
        version: "0.1.0",
    },
    StdlibAnchor {
        name: "PrivacyGuard",
        description: "Prevents exposure of PII (SSNs, credit cards, emails, phone numbers).",
        severity: "error",
        require: &[],
        reject: &["pii", "personal_data", "ssn", "phone_number"],
        confidence_floor: None,
        version: "0.1.0",
    },
    StdlibAnchor {
        name: "NoBias",
        description: "Enforces political and demographic neutrality. Detects loaded language and explicit bias.",
        severity: "warning",
        require: &[],
        reject: &["political_bias", "demographic_bias", "gender_bias"],
        confidence_floor: None,
        version: "0.1.0",
    },
    StdlibAnchor {
        name: "ChildSafe",
        description: "Ensures all content is appropriate for minors. Rejects adult content, graphic violence, profanity, and drugs.",
        severity: "error",
        require: &[],
        reject: &["adult_content", "violence", "profanity", "drugs"],
        confidence_floor: None,
        version: "0.1.0",
    },
    StdlibAnchor {
        name: "NoCodeExecution",
        description: "Prevents code execution, system commands, and file operations.",
        severity: "error",
        require: &[],
        reject: &["code_execution", "system_command", "file_write"],
        confidence_floor: None,
        version: "0.1.0",
    },
    StdlibAnchor {
        name: "AuditTrail",
        description: "Forces full reasoning trace in output. Requires visible reasoning steps for audit and review purposes.",
        severity: "warning",
        require: &["human_review"],
        reject: &[],
        confidence_floor: None,
        version: "0.1.0",
    },
    // Logic & Epistemic anchors (4)
    StdlibAnchor {
        name: "SyllogismChecker",
        description: "Syntactically enforces standard logical format using 'Premise:' and 'Conclusion:' identifiers.",
        severity: "error",
        require: &["logical_structure"],
        reject: &[],
        confidence_floor: None,
        version: "0.1.0",
    },
    StdlibAnchor {
        name: "ChainOfThoughtValidator",
        description: "Forces the model to explicitly write out step sequences before producing a final answer.",
        severity: "error",
        require: &["step_by_step"],
        reject: &[],
        confidence_floor: None,
        version: "0.1.0",
    },
    StdlibAnchor {
        name: "RequiresCitation",
        description: "Strict verification enforcing explicit academic-style inline citations or external URLs.",
        severity: "error",
        require: &["inline_citation"],
        reject: &["unverifiable_claim"],
        confidence_floor: None,
        version: "0.1.0",
    },
    StdlibAnchor {
        name: "AgnosticFallback",
        description: "Requires the model to explicitly state a lack of information instead of speculating.",
        severity: "error",
        require: &["epistemic_honesty"],
        reject: &["unwarranted_speculation"],
        confidence_floor: None,
        version: "0.1.0",
    },
];

// ── Flows (8) ───────────────────────────────────────────────────────────────

pub const FLOWS: &[StdlibFlow] = &[
    StdlibFlow {
        name: "Summarize",
        description: "Condense any document into a concise summary.",
        parameters: &[("doc", "Document")],
        return_type: "Summary",
        category: "analysis",
        version: "0.1.0",
    },
    StdlibFlow {
        name: "ExtractEntities",
        description: "Extract and classify named entities from a document.",
        parameters: &[("doc", "Document")],
        return_type: "EntityMap",
        category: "extraction",
        version: "0.1.0",
    },
    StdlibFlow {
        name: "CompareDocuments",
        description: "Compare two documents side-by-side with detailed analysis.",
        parameters: &[("doc_a", "Document"), ("doc_b", "Document")],
        return_type: "StructuredReport",
        category: "analysis",
        version: "0.1.0",
    },
    StdlibFlow {
        name: "TranslateDocument",
        description: "Translate a document with cultural context preservation.",
        parameters: &[("doc", "Document"), ("target_lang", "String")],
        return_type: "Translation",
        category: "translation",
        version: "0.1.0",
    },
    StdlibFlow {
        name: "FactCheck",
        description: "Verify factual claims with sourced evidence.",
        parameters: &[("claims", "Document")],
        return_type: "StructuredReport",
        category: "verification",
        version: "0.1.0",
    },
    StdlibFlow {
        name: "SentimentAnalysis",
        description: "Analyze tone and sentiment with nuanced scoring.",
        parameters: &[("doc", "Document")],
        return_type: "SentimentScore",
        category: "analysis",
        version: "0.1.0",
    },
    StdlibFlow {
        name: "ClassifyContent",
        description: "Classify content into user-defined categories.",
        parameters: &[("doc", "Document"), ("categories", "String")],
        return_type: "EntityMap",
        category: "classification",
        version: "0.1.0",
    },
    StdlibFlow {
        name: "GenerateReport",
        description: "Generate a structured report from raw data.",
        parameters: &[("data", "Document")],
        return_type: "StructuredReport",
        category: "reporting",
        version: "0.1.0",
    },
];

// ── Tools (8) ───────────────────────────────────────────────────────────────

pub const TOOLS: &[StdlibTool] = &[
    StdlibTool {
        name: "WebSearch",
        description: "Live web search via Brave Search API.",
        provider: "brave",
        timeout: 10,
        requires_api_key: true,
        sandbox: false,
        version: "0.1.0",
    },
    StdlibTool {
        name: "CodeExecutor",
        description: "Safe sandboxed code execution.",
        provider: "",
        timeout: 30,
        requires_api_key: false,
        sandbox: true,
        version: "0.1.0",
    },
    StdlibTool {
        name: "FileReader",
        description: "Read local or remote files.",
        provider: "",
        timeout: 5,
        requires_api_key: false,
        sandbox: false,
        version: "0.1.0",
    },
    StdlibTool {
        name: "PDFExtractor",
        description: "Extract text and structure from PDF.",
        provider: "",
        timeout: 15,
        requires_api_key: false,
        sandbox: false,
        version: "0.1.0",
    },
    StdlibTool {
        name: "ImageAnalyzer",
        description: "Analyze images using vision capabilities.",
        provider: "",
        timeout: 20,
        requires_api_key: true,
        sandbox: false,
        version: "0.1.0",
    },
    StdlibTool {
        name: "Calculator",
        description: "Precise arithmetic with safe expression eval.",
        provider: "",
        timeout: 2,
        requires_api_key: false,
        sandbox: true,
        version: "0.1.0",
    },
    StdlibTool {
        name: "DateTimeTool",
        description: "Temporal reasoning — current date, time, timestamps.",
        provider: "",
        timeout: 1,
        requires_api_key: false,
        sandbox: true,
        version: "0.1.0",
    },
    StdlibTool {
        name: "APICall",
        description: "Generic REST API caller.",
        provider: "",
        timeout: 30,
        requires_api_key: true,
        sandbox: false,
        version: "0.1.0",
    },
];

// ── Public API ──────────────────────────────────────────────────────────────

pub const VALID_NAMESPACES: &[&str] = &["anchors", "flows", "personas", "tools"];

/// List all entries in a namespace, sorted by name.
pub fn list_namespace(namespace: &str) -> Vec<StdlibEntry> {
    match namespace {
        "personas" => PERSONAS.iter().map(|p| StdlibEntry::Persona(p.clone())).collect(),
        "anchors" => ANCHORS.iter().map(|a| StdlibEntry::Anchor(a.clone())).collect(),
        "flows" => FLOWS.iter().map(|f| StdlibEntry::Flow(f.clone())).collect(),
        "tools" => TOOLS.iter().map(|t| StdlibEntry::Tool(t.clone())).collect(),
        _ => Vec::new(),
    }
}

/// Resolve a specific entry by name across all namespaces.
pub fn resolve(name: &str) -> Option<StdlibEntry> {
    if let Some(p) = PERSONAS.iter().find(|p| p.name == name) {
        return Some(StdlibEntry::Persona(p.clone()));
    }
    if let Some(a) = ANCHORS.iter().find(|a| a.name == name) {
        return Some(StdlibEntry::Anchor(a.clone()));
    }
    if let Some(f) = FLOWS.iter().find(|f| f.name == name) {
        return Some(StdlibEntry::Flow(f.clone()));
    }
    if let Some(t) = TOOLS.iter().find(|t| t.name == name) {
        return Some(StdlibEntry::Tool(t.clone()));
    }
    None
}

/// Check if a name exists in any namespace.
pub fn has(name: &str) -> bool {
    resolve(name).is_some()
}

/// Total count of all stdlib entries.
pub fn total_count() -> usize {
    PERSONAS.len() + ANCHORS.len() + FLOWS.len() + TOOLS.len()
}