Skip to main content

axe_ir/
lib.rs

1//! Intermediate representation for the AXE (Agent eXtension Engine) spec.
2//!
3//! The IR captures the semantic core of agent extension definitions:
4//! instruction content, activation conditions, tool requirements,
5//! hook bindings, and variable references.
6//!
7//! See <https://github.com/claylo/axe> for the full spec.
8
9#![forbid(unsafe_code)]
10
11/// AXE specification version this IR targets.
12pub const SPEC_VERSION: &str = "1.0";
13
14/// A parsed agent extension in platform-neutral form.
15#[derive(Debug, Clone)]
16pub struct Extension {
17    /// Required metadata.
18    pub meta: Meta,
19    /// How and when this extension activates.
20    pub activation: Option<Activation>,
21    /// Capabilities this extension requires from the host platform.
22    pub capabilities: Vec<Capability>,
23    /// Markdown body containing agent instructions.
24    pub content: String,
25}
26
27/// Required extension metadata.
28#[derive(Debug, Clone)]
29pub struct Meta {
30    /// Extension name (`[a-z0-9-]`, max 64 chars).
31    pub name: String,
32    /// Human-readable description (max 1024 chars).
33    pub description: String,
34    /// AXE spec version the author wrote against.
35    pub axe_version: String,
36    /// Extension's own version (semver, optional).
37    pub version: Option<String>,
38}
39
40/// Activation conditions for the extension.
41#[derive(Debug, Clone)]
42pub struct Activation {
43    pub mode: ActivationMode,
44    pub patterns: Vec<String>,
45}
46
47/// How the extension decides to activate.
48#[derive(Debug, Clone, PartialEq, Eq)]
49pub enum ActivationMode {
50    Always,
51    Glob,
52    ModelDecision,
53    Manual,
54}
55
56/// Capabilities an extension may require.
57#[derive(Debug, Clone, PartialEq, Eq)]
58pub enum Capability {
59    ToolUse,
60    FileRead,
61    FileEdit,
62    ShellExec,
63    WebSearch,
64    Hook(HookEvent),
65    VariableSub,
66    Subagent,
67    McpServer,
68}
69
70/// Abstract hook events, mapped to vendor-specific names by backends.
71#[derive(Debug, Clone, PartialEq, Eq)]
72pub enum HookEvent {
73    SessionStart,
74    SessionEnd,
75    PreTool,
76    PostTool,
77    UserPrompt,
78    PreCompact,
79    SubagentStart,
80    SubagentStop,
81    Custom(String),
82}
83
84/// Diagnostic emitted during compilation.
85#[derive(Debug, Clone)]
86pub struct Diagnostic {
87    pub level: DiagnosticLevel,
88    /// Target platform (e.g., "cursor").
89    pub target: String,
90    /// What capability or feature is affected.
91    pub capability: String,
92    /// Human-readable explanation.
93    pub message: String,
94}
95
96/// Severity of a compilation diagnostic.
97#[derive(Debug, Clone, PartialEq, Eq)]
98pub enum DiagnosticLevel {
99    /// Informational — no action needed.
100    Info,
101    /// Feature will be shimmed or degraded.
102    Warning,
103    /// Feature cannot be represented on target.
104    Error,
105}