Skip to main content

orchestrator_collab/
lib.rs

1//! Agent Collaboration Module
2//!
3//! Provides structured agent-to-agent communication, shared context,
4//! and DAG-based workflow execution.
5
6#![cfg_attr(
7    not(test),
8    deny(clippy::panic, clippy::unwrap_used, clippy::expect_used)
9)]
10#![deny(missing_docs)]
11
12/// Artifact models and shared-state helpers for multi-agent execution.
13pub mod artifact;
14/// Agent execution context types and template-rendering helpers.
15pub mod context;
16/// DAG primitives used by collaboration planning flows.
17pub mod dag;
18/// Structured agent output payloads and metrics.
19pub mod output;
20
21pub use artifact::*;
22pub use context::*;
23pub use dag::*;
24pub use output::*;
25
26/// Escape a string for safe embedding inside a bash double-quoted string.
27///
28/// Inside bash double quotes, the characters `\`, `$`, `` ` ``, `"`, and `!`
29/// are special. This function escapes them so that the shell passes the
30/// literal content to the target program without interpretation.
31pub(crate) fn escape_for_bash_dquote(s: &str) -> String {
32    let mut out = String::with_capacity(s.len() + s.len() / 8);
33    for ch in s.chars() {
34        match ch {
35            '\\' => out.push_str("\\\\"),
36            '$' => out.push_str("\\$"),
37            '`' => out.push_str("\\`"),
38            '"' => out.push_str("\\\""),
39            '!' => out.push_str("\\!"),
40            _ => out.push(ch),
41        }
42    }
43    out
44}
45
46#[cfg(test)]
47mod tests {
48    use super::*;
49
50    #[test]
51    fn test_escape_for_bash_dquote() {
52        assert_eq!(escape_for_bash_dquote("`resource.rs`"), "\\`resource.rs\\`");
53        assert_eq!(escape_for_bash_dquote("$HOME"), "\\$HOME");
54        assert_eq!(escape_for_bash_dquote(r#"say "hello""#), r#"say \"hello\""#);
55        assert_eq!(escape_for_bash_dquote(r"path\to"), r"path\\to");
56        assert_eq!(escape_for_bash_dquote("wow!"), "wow\\!");
57        assert_eq!(escape_for_bash_dquote("hello world"), "hello world");
58
59        let plan = "| `mod.rs` | ~200 | Core types, `pub(super)` |\n| $cost | ~$5 |";
60        let escaped = escape_for_bash_dquote(plan);
61        assert!(escaped.contains("\\`mod.rs\\`"));
62        assert!(escaped.contains("\\`pub(super)\\`"));
63        assert!(escaped.contains("\\$cost"));
64        assert!(escaped.contains("\\$5"));
65        assert!(!escaped.contains(" `m"));
66    }
67}