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
//! # Atento Core - Chain Execution Engine
//!
//! Atento Core is a powerful Rust library for defining and executing sequential chained scripts
//! with multi-interpreter support, robust error handling, and advanced variable passing capabilities.
//!
//! ## Key Features
//!
//! - **Multi-Interpreter Support**: Execute scripts in Bash, Batch, `PowerShell`, Pwsh, and Python
//! - **Sequential Execution**: Guaranteed step order with dependency management
//! - **Variable Passing**: Global parameters and step-to-step output chaining
//! - **Type Safety**: Strongly typed parameters (string, int, float, bool, datetime)
//! - **Cross-Platform**: Works reliably on Linux, macOS, and Windows
//! - **Secure Execution**: Temporary file isolation and proper permission handling
//! - **Embedded Logging**: Captures stdout, stderr, and errors inline in JSON results
//! - **No Telemetry**: Never collects usage stats or requires licensing checks
//!
//! ## Quick Start
//!
//! ```rust,no_run
//! use atento_core;
//!
//! fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Run a chain from a YAML file
//! atento_core::run("chain.yaml")?;
//! Ok(())
//! }
//! ```
//!
//! ## Chain Structure
//!
//! Chains are defined in YAML format with the following structure:
//!
//! ```yaml
//! name: "Example Chain"
//! timeout: 300 # Global timeout in seconds
//!
//! parameters:
//! project_name:
//! type: string
//! value: "my-project"
//! build_number:
//! type: int
//! value: 42
//!
//! steps:
//! setup:
//! name: "Setup Environment"
//! type: bash # Interpreter: bash, batch, powershell, pwsh, python
//! timeout: 60
//! script: |
//! echo "Setting up {{ inputs.project }}"
//! echo "BUILD_DIR=/tmp/build-{{ inputs.build_num }}"
//! inputs:
//! project:
//! ref: parameters.project_name
//! build_num:
//! ref: parameters.build_number
//! outputs:
//! build_directory:
//! pattern: "BUILD_DIR=(.*)"
//!
//! build:
//! name: "Build Project"
//! type: python
//! script: |
//! import os
//! build_dir = "{{ inputs.build_dir }}"
//! print(f"Building in {build_dir}")
//! print("BUILD_SUCCESS=true")
//! inputs:
//! build_dir:
//! ref: steps.setup.outputs.build_directory
//! outputs:
//! status:
//! pattern: "BUILD_SUCCESS=(.*)"
//!
//! results:
//! build_status:
//! ref: steps.build.outputs.status
//! workspace:
//! ref: steps.setup.outputs.build_directory
//! ```
//!
//! ## Supported Interpreters
//!
//! | Type | Description | Platform |
//! |------|-------------|----------|
//! | `bash` | Bash shell scripts | Unix/Linux/macOS |
//! | `batch` | Windows batch files | Windows |
//! | `powershell` | `PowerShell` (Windows) | Windows |
//! | `pwsh` | `PowerShell` Core | Cross-platform |
//! | `python` | Python scripts | Cross-platform |
//! | `python3` | Python3 scripts | Cross-platform |
//!
//! ## Variable Substitution
//!
//! Use `{{ inputs.variable_name }}` syntax in scripts to substitute input values:
//!
//! ```yaml
//! script: |
//! echo "Processing {{ inputs.filename }} in {{ inputs.directory }}"
//! cp "{{ inputs.source }}" "{{ inputs.destination }}"
//! ```
//!
//! ## Output Extraction
//!
//! Capture values from command output using regex patterns with capture groups:
//!
//! ```yaml
//! outputs:
//! version:
//! pattern: "Version: ([0-9]+\.[0-9]+\.[0-9]+)"
//! status:
//! pattern: "Status: (SUCCESS|FAILED)"
//! ```
//!
//! ## Error Handling
//!
//! The library provides comprehensive error handling for:
//! - File I/O operations
//! - YAML parsing errors
//! - Chain validation failures
//! - Script execution timeouts
//! - Type conversion errors
//! - Unresolved variable references
//!
//! ## Example Usage
//!
//! ```no_run
//! # use atento_core::{Chain, AtentoError};
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Load and validate a chain
//! let yaml_content = std::fs::read_to_string("chain.yaml")?;
//! let chain: Chain = serde_yaml::from_str(&yaml_content)?;
//!
//! // Validate the chain structure
//! chain.validate()?;
//!
//! // Execute the chain
//! let result = chain.run();
//!
//! // Serialize results to JSON
//! let json_output = serde_json::to_string_pretty(&result)?;
//! println!("{}", json_output);
//! # Ok(())
//! # }
//! ```
use Path;
// Re-export main types for library users
pub use ;
pub use DataType;
pub use ;
pub use ;
pub use ;
/// Runs a chain from a YAML file.
///
/// # Arguments
/// * `filename` - Path to the chain YAML file
///
/// # Errors
/// Returns an error if:
/// - The file cannot be read
/// - The YAML cannot be parsed
/// - The chain validation fails
/// - The chain execution fails
/// - The results cannot be serialized to JSON