Skip to main content

agent_doc/
lib.rs

1//! agent-doc library — shared components for CLI, FFI, and editor plugins.
2//!
3//! Re-exports the core document manipulation modules that are shared between
4//! the CLI binary and native plugin bindings (JNI, napi-rs).
5
6pub mod component;
7pub mod crdt;
8pub mod ffi;
9pub mod frontmatter;
10pub mod merge;
11pub mod template;
12
13/// Default number of hex characters for boundary IDs.
14pub const BOUNDARY_ID_LEN: usize = 8;
15
16/// Generate a new boundary ID (short hex string from UUID v4).
17pub fn new_boundary_id() -> String {
18    let full = uuid::Uuid::new_v4().to_string().replace('-', "");
19    full[..BOUNDARY_ID_LEN.min(full.len())].to_string()
20}
21
22/// Generate a boundary ID with an optional summary suffix.
23///
24/// Format: `a0cfeb34` or `a0cfeb34:boundary-fix` (with summary).
25/// The summary is slugified (lowercase, non-alphanumeric → `-`, max 20 chars).
26pub fn new_boundary_id_with_summary(summary: Option<&str>) -> String {
27    let id = new_boundary_id();
28    match summary {
29        Some(s) if !s.is_empty() => {
30            let slug: String = s.to_lowercase()
31                .chars()
32                .map(|c| if c.is_alphanumeric() { c } else { '-' })
33                .collect::<String>()
34                .split('-')
35                .filter(|s| !s.is_empty())
36                .take(3) // max 3 words
37                .collect::<Vec<&str>>()
38                .join("-");
39            let slug = &slug[..slug.len().min(20)];
40            format!("{}:{}", id, slug)
41        }
42        _ => id,
43    }
44}
45
46/// Format a boundary marker comment.
47pub fn format_boundary_marker(id: &str) -> String {
48    format!("<!-- agent:boundary:{} -->", id)
49}