hippox-drivers 0.3.5

🦛All indivisible atomic driver units in Hippox.
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
//! File hash calculation skills
//!
//! This module provides drivers for calculating various cryptographic
//! hashes of files including MD5, SHA1, SHA256, SHA512, and BLAKE3.
use crate::DriverCallback;
use crate::DriverContext;
use crate::DriverResult;
use crate::{
    DriverCategory,
    types::{Driver, DriverParameter},
};
use crate::{calculate_all_hashes, calculate_md5, calculate_sha1, calculate_sha256, calculate_sha512, file_exists, validate_path};
use serde_json::{Value, json};
use std::collections::HashMap;
use tracing::{debug, info, warn};
/// Driver for calculating MD5 hash of a file
#[derive(Debug)]
pub struct HashMd5Driver;
#[async_trait::async_trait]
impl Driver for HashMd5Driver {
    /// Returns the unique name of this driver
    fn name(&self) -> &str {
        "hash_md5"
    }
    /// Returns a brief description of the driver's functionality
    fn description(&self) -> &str {
        "Calculate MD5 hash of a file"
    }
    /// Returns detailed usage guidance for LLMs
    fn usage_hint(&self) -> &str {
        "Use this skill to get the MD5 checksum of a file for integrity verification."
    }
    /// Returns the parameter definitions for this driver
    fn parameters(&self) -> Vec<DriverParameter> {
        return vec![DriverParameter {
            name: "path".to_string(),
            param_type: "string".to_string(),
            description: "Path to the file to hash".to_string(),
            required: true,
            default: None,
            example: Some(Value::String("/tmp/file.txt".to_string())),
            enum_values: None,
        }];
    }
    /// Returns an example call for this driver
    fn example_call(&self) -> DriverResult<Value> {
        return Ok(json!({
            "action": "hash_md5",
            "parameters": {
                "path": "/tmp/file.txt"
            }
        }));
    }
    /// Returns an example output from this driver
    fn example_output(&self) -> String {
        return "MD5 hash of /tmp/file.txt: d41d8cd98f00b204e9800998ecf8427e".to_string();
    }
    /// Returns the category of this driver
    fn category(&self) -> DriverCategory {
        return DriverCategory::File;
    }
    /// Executes the driver with the given parameters
    async fn execute(
        &self,
        parameters: &HashMap<String, Value>,
        callback: Option<&dyn DriverCallback>,
        context: Option<&DriverContext>,
    ) -> DriverResult<String> {
        debug!("Executing hash_md5 driver");
        let path = parameters.get("path").and_then(|v| v.as_str()).ok_or_else(|| {
            debug!("Missing 'path' parameter");
            return crate::DriverError::missing_parameter("path");
        })?;
        debug!("Calculating MD5 hash for: {}", path);
        let validated_path = validate_path(path, None).map_err(|e| {
            debug!("Failed to validate path: {}", e);
            return crate::DriverError::execution(format!("Failed to validate path: {}", e));
        })?;
        if !file_exists(&validated_path.to_string_lossy()) {
            warn!("File not found: {}", path);
            return Err(crate::DriverError::execution(format!("File not found: {}", path)));
        }
        let hash = calculate_md5(&validated_path.to_string_lossy()).map_err(|e| {
            debug!("Failed to calculate MD5 hash: {}", e);
            return crate::DriverError::execution(format!("Failed to calculate MD5 hash: {}", e));
        })?;
        info!("MD5 hash calculated for {}", path);
        return Ok(format!("MD5 hash of {}: {}", path, hash));
    }
}
/// Driver for calculating SHA1 hash of a file
#[derive(Debug)]
pub struct HashSha1Driver;
#[async_trait::async_trait]
impl Driver for HashSha1Driver {
    /// Returns the unique name of this driver
    fn name(&self) -> &str {
        "hash_sha1"
    }
    /// Returns a brief description of the driver's functionality
    fn description(&self) -> &str {
        "Calculate SHA1 hash of a file"
    }
    /// Returns detailed usage guidance for LLMs
    fn usage_hint(&self) -> &str {
        "Use this skill to get the SHA1 checksum of a file for integrity verification."
    }
    /// Returns the parameter definitions for this driver
    fn parameters(&self) -> Vec<DriverParameter> {
        return vec![DriverParameter {
            name: "path".to_string(),
            param_type: "string".to_string(),
            description: "Path to the file to hash".to_string(),
            required: true,
            default: None,
            example: Some(Value::String("/tmp/file.txt".to_string())),
            enum_values: None,
        }];
    }
    /// Returns an example call for this driver
    fn example_call(&self) -> DriverResult<Value> {
        return Ok(json!({
            "action": "hash_sha1",
            "parameters": {
                "path": "/tmp/file.txt"
            }
        }));
    }
    /// Returns an example output from this driver
    fn example_output(&self) -> String {
        return "SHA1 hash of /tmp/file.txt: da39a3ee5e6b4b0d3255bfef95601890afd80709".to_string();
    }
    /// Returns the category of this driver
    fn category(&self) -> DriverCategory {
        return DriverCategory::File;
    }
    /// Executes the driver with the given parameters
    async fn execute(
        &self,
        parameters: &HashMap<String, Value>,
        callback: Option<&dyn DriverCallback>,
        context: Option<&DriverContext>,
    ) -> DriverResult<String> {
        debug!("Executing hash_sha1 driver");
        let path = parameters.get("path").and_then(|v| v.as_str()).ok_or_else(|| {
            debug!("Missing 'path' parameter");
            return crate::DriverError::missing_parameter("path");
        })?;
        debug!("Calculating SHA1 hash for: {}", path);
        let validated_path = validate_path(path, None).map_err(|e| {
            debug!("Failed to validate path: {}", e);
            return crate::DriverError::execution(format!("Failed to validate path: {}", e));
        })?;
        if !file_exists(&validated_path.to_string_lossy()) {
            warn!("File not found: {}", path);
            return Err(crate::DriverError::execution(format!("File not found: {}", path)));
        }
        let hash = calculate_sha1(&validated_path.to_string_lossy()).map_err(|e| {
            debug!("Failed to calculate SHA1 hash: {}", e);
            return crate::DriverError::execution(format!("Failed to calculate SHA1 hash: {}", e));
        })?;
        info!("SHA1 hash calculated for {}", path);
        return Ok(format!("SHA1 hash of {}: {}", path, hash));
    }
}
/// Driver for calculating SHA256 hash of a file
#[derive(Debug)]
pub struct HashSha256Driver;
#[async_trait::async_trait]
impl Driver for HashSha256Driver {
    /// Returns the unique name of this driver
    fn name(&self) -> &str {
        "hash_sha256"
    }
    /// Returns a brief description of the driver's functionality
    fn description(&self) -> &str {
        "Calculate SHA256 hash of a file"
    }
    /// Returns detailed usage guidance for LLMs
    fn usage_hint(&self) -> &str {
        "Use this skill to get the SHA256 checksum of a file for integrity verification."
    }
    /// Returns the parameter definitions for this driver
    fn parameters(&self) -> Vec<DriverParameter> {
        return vec![DriverParameter {
            name: "path".to_string(),
            param_type: "string".to_string(),
            description: "Path to the file to hash".to_string(),
            required: true,
            default: None,
            example: Some(Value::String("/tmp/file.txt".to_string())),
            enum_values: None,
        }];
    }
    /// Returns an example call for this driver
    fn example_call(&self) -> DriverResult<Value> {
        return Ok(json!({
            "action": "hash_sha256",
            "parameters": {
                "path": "/tmp/file.txt"
            }
        }));
    }
    /// Returns an example output from this driver
    fn example_output(&self) -> String {
        return "SHA256 hash of /tmp/file.txt: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855".to_string();
    }
    /// Returns the category of this driver
    fn category(&self) -> DriverCategory {
        return DriverCategory::File;
    }
    /// Executes the driver with the given parameters
    async fn execute(
        &self,
        parameters: &HashMap<String, Value>,
        callback: Option<&dyn DriverCallback>,
        context: Option<&DriverContext>,
    ) -> DriverResult<String> {
        debug!("Executing hash_sha256 driver");
        let path = parameters.get("path").and_then(|v| v.as_str()).ok_or_else(|| {
            debug!("Missing 'path' parameter");
            return crate::DriverError::missing_parameter("path");
        })?;
        debug!("Calculating SHA256 hash for: {}", path);
        let validated_path = validate_path(path, None).map_err(|e| {
            debug!("Failed to validate path: {}", e);
            return crate::DriverError::execution(format!("Failed to validate path: {}", e));
        })?;
        if !file_exists(&validated_path.to_string_lossy()) {
            warn!("File not found: {}", path);
            return Err(crate::DriverError::execution(format!("File not found: {}", path)));
        }
        let hash = calculate_sha256(&validated_path.to_string_lossy()).map_err(|e| {
            debug!("Failed to calculate SHA256 hash: {}", e);
            return crate::DriverError::execution(format!("Failed to calculate SHA256 hash: {}", e));
        })?;
        info!("SHA256 hash calculated for {}", path);
        return Ok(format!("SHA256 hash of {}: {}", path, hash));
    }
}
/// Driver for calculating SHA512 hash of a file
#[derive(Debug)]
pub struct HashSha512Driver;
#[async_trait::async_trait]
impl Driver for HashSha512Driver {
    /// Returns the unique name of this driver
    fn name(&self) -> &str {
        "hash_sha512"
    }
    /// Returns a brief description of the driver's functionality
    fn description(&self) -> &str {
        "Calculate SHA512 hash of a file"
    }
    /// Returns detailed usage guidance for LLMs
    fn usage_hint(&self) -> &str {
        "Use this skill to get the SHA512 checksum of a file for integrity verification."
    }
    /// Returns the parameter definitions for this driver
    fn parameters(&self) -> Vec<DriverParameter> {
        return vec![DriverParameter {
            name: "path".to_string(),
            param_type: "string".to_string(),
            description: "Path to the file to hash".to_string(),
            required: true,
            default: None,
            example: Some(Value::String("/tmp/file.txt".to_string())),
            enum_values: None,
        }];
    }
    /// Returns an example call for this driver
    fn example_call(&self) -> DriverResult<Value> {
        return Ok(json!({
            "action": "hash_sha512",
            "parameters": {
                "path": "/tmp/file.txt"
            }
        }));
    }
    /// Returns an example output from this driver
    fn example_output(&self) -> String {
        return "SHA512 hash of /tmp/file.txt: cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e".to_string();
    }
    /// Returns the category of this driver
    fn category(&self) -> DriverCategory {
        return DriverCategory::File;
    }
    /// Executes the driver with the given parameters
    async fn execute(
        &self,
        parameters: &HashMap<String, Value>,
        callback: Option<&dyn DriverCallback>,
        context: Option<&DriverContext>,
    ) -> DriverResult<String> {
        debug!("Executing hash_sha512 driver");
        let path = parameters.get("path").and_then(|v| v.as_str()).ok_or_else(|| {
            debug!("Missing 'path' parameter");
            return crate::DriverError::missing_parameter("path");
        })?;
        debug!("Calculating SHA512 hash for: {}", path);
        let validated_path = validate_path(path, None).map_err(|e| {
            debug!("Failed to validate path: {}", e);
            return crate::DriverError::execution(format!("Failed to validate path: {}", e));
        })?;
        if !file_exists(&validated_path.to_string_lossy()) {
            warn!("File not found: {}", path);
            return Err(crate::DriverError::execution(format!("File not found: {}", path)));
        }
        let hash = calculate_sha512(&validated_path.to_string_lossy()).map_err(|e| {
            debug!("Failed to calculate SHA512 hash: {}", e);
            return crate::DriverError::execution(format!("Failed to calculate SHA512 hash: {}", e));
        })?;
        info!("SHA512 hash calculated for {}", path);
        return Ok(format!("SHA512 hash of {}: {}", path, hash));
    }
}
/// Driver for calculating all hashes of a file
#[derive(Debug)]
pub struct HashFileDriver;
#[async_trait::async_trait]
impl Driver for HashFileDriver {
    /// Returns the unique name of this driver
    fn name(&self) -> &str {
        "hash_file"
    }
    /// Returns a brief description of the driver's functionality
    fn description(&self) -> &str {
        "Calculate all hashes (MD5, SHA1, SHA256, SHA512, BLAKE3) of a file"
    }
    /// Returns detailed usage guidance for LLMs
    fn usage_hint(&self) -> &str {
        "Use this skill to get comprehensive hash information for a file."
    }
    /// Returns the parameter definitions for this driver
    fn parameters(&self) -> Vec<DriverParameter> {
        return vec![DriverParameter {
            name: "path".to_string(),
            param_type: "string".to_string(),
            description: "Path to the file to hash".to_string(),
            required: true,
            default: None,
            example: Some(Value::String("/tmp/file.txt".to_string())),
            enum_values: None,
        }];
    }
    /// Returns an example call for this driver
    fn example_call(&self) -> DriverResult<Value> {
        return Ok(json!({
            "action": "hash_file",
            "parameters": {
                "path": "/tmp/file.txt"
            }
        }));
    }
    /// Returns an example output from this driver
    fn example_output(&self) -> String {
        return "File: /tmp/file.txt\nMD5: d41d8cd98f00b204e9800998ecf8427e\nSHA1: da39a3ee5e6b4b0d3255bfef95601890afd80709\nSHA256: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\nSHA512: cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e\nBLAKE3: ...".to_string();
    }
    /// Returns the category of this driver
    fn category(&self) -> DriverCategory {
        return DriverCategory::File;
    }
    /// Executes the driver with the given parameters
    async fn execute(
        &self,
        parameters: &HashMap<String, Value>,
        callback: Option<&dyn DriverCallback>,
        context: Option<&DriverContext>,
    ) -> DriverResult<String> {
        debug!("Executing hash_file driver");
        let path = parameters.get("path").and_then(|v| v.as_str()).ok_or_else(|| {
            debug!("Missing 'path' parameter");
            return crate::DriverError::missing_parameter("path");
        })?;
        debug!("Calculating all hashes for: {}", path);
        let validated_path = validate_path(path, None).map_err(|e| {
            debug!("Failed to validate path: {}", e);
            return crate::DriverError::execution(format!("Failed to validate path: {}", e));
        })?;
        if !file_exists(&validated_path.to_string_lossy()) {
            warn!("File not found: {}", path);
            return Err(crate::DriverError::execution(format!("File not found: {}", path)));
        }
        let result = calculate_all_hashes(&validated_path.to_string_lossy()).map_err(|e| {
            debug!("Failed to calculate hashes: {}", e);
            return crate::DriverError::execution(format!("Failed to calculate hashes: {}", e));
        })?;
        let mut output = format!("File: {}\n", result.path);
        if let Some(hash) = result.md5 {
            output.push_str(&format!("MD5: {}\n", hash));
        }
        if let Some(hash) = result.sha1 {
            output.push_str(&format!("SHA1: {}\n", hash));
        }
        if let Some(hash) = result.sha256 {
            output.push_str(&format!("SHA256: {}\n", hash));
        }
        if let Some(hash) = result.sha512 {
            output.push_str(&format!("SHA512: {}\n", hash));
        }
        if let Some(hash) = result.blake3 {
            output.push_str(&format!("BLAKE3: {}\n", hash));
        }
        info!("All hashes calculated for {}", path);
        return Ok(output);
    }
}