agentic_navigation_guide/
types.rs

1//! Core data types for the agentic navigation guide
2
3use serde::{Deserialize, Serialize};
4use std::path::PathBuf;
5
6/// Represents a filesystem item type
7#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
8pub enum FilesystemItem {
9    /// A regular file
10    File {
11        /// The file path relative to its parent
12        path: String,
13        /// Optional comment describing the file
14        comment: Option<String>,
15    },
16    /// A directory
17    Directory {
18        /// The directory path relative to its parent
19        path: String,
20        /// Optional comment describing the directory
21        comment: Option<String>,
22        /// Child items within this directory
23        children: Vec<NavigationGuideLine>,
24    },
25    /// A symbolic link
26    Symlink {
27        /// The symlink path relative to its parent
28        path: String,
29        /// Optional comment describing the symlink
30        comment: Option<String>,
31        /// The target of the symlink (if specified in the guide)
32        target: Option<String>,
33    },
34}
35
36/// Represents a single line in the navigation guide
37#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
38pub struct NavigationGuideLine {
39    /// The line number in the original document
40    pub line_number: usize,
41    /// The indentation level (number of spaces / indent_size)
42    pub indent_level: usize,
43    /// The filesystem item this line represents
44    pub item: FilesystemItem,
45}
46
47impl NavigationGuideLine {
48    /// Get the path of the filesystem item
49    pub fn path(&self) -> &str {
50        match &self.item {
51            FilesystemItem::File { path, .. }
52            | FilesystemItem::Directory { path, .. }
53            | FilesystemItem::Symlink { path, .. } => path,
54        }
55    }
56
57    /// Get the comment of the filesystem item
58    pub fn comment(&self) -> Option<&str> {
59        match &self.item {
60            FilesystemItem::File { comment, .. }
61            | FilesystemItem::Directory { comment, .. }
62            | FilesystemItem::Symlink { comment, .. } => comment.as_deref(),
63        }
64    }
65
66    /// Check if this item is a directory
67    pub fn is_directory(&self) -> bool {
68        matches!(self.item, FilesystemItem::Directory { .. })
69    }
70
71    /// Get the children of a directory item
72    pub fn children(&self) -> Option<&[NavigationGuideLine]> {
73        match &self.item {
74            FilesystemItem::Directory { children, .. } => Some(children),
75            _ => None,
76        }
77    }
78}
79
80/// Represents a complete navigation guide
81#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
82pub struct NavigationGuide {
83    /// The root items in the guide
84    pub items: Vec<NavigationGuideLine>,
85    /// The original prologue content (before the guide block)
86    pub prologue: Option<String>,
87    /// The original epilogue content (after the guide block)
88    pub epilogue: Option<String>,
89}
90
91impl NavigationGuide {
92    /// Create a new empty navigation guide
93    pub fn new() -> Self {
94        Self {
95            items: Vec::new(),
96            prologue: None,
97            epilogue: None,
98        }
99    }
100
101    /// Get the full path for an item by traversing up the hierarchy
102    pub fn get_full_path(&self, item: &NavigationGuideLine) -> PathBuf {
103        // This is a simplified version - in practice we'd need to traverse
104        // the hierarchy to build the full path
105        PathBuf::from(item.path())
106    }
107}
108
109impl Default for NavigationGuide {
110    fn default() -> Self {
111        Self::new()
112    }
113}
114
115/// Execution mode for the CLI tool
116#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
117pub enum ExecutionMode {
118    /// Default execution mode
119    Default,
120    /// Running as a post-tool-use hook
121    PostToolUse,
122    /// Running as a pre-commit hook
123    PreCommitHook,
124}
125
126impl Default for ExecutionMode {
127    fn default() -> Self {
128        Self::Default
129    }
130}
131
132/// Log level for output verbosity
133#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
134pub enum LogLevel {
135    /// Minimal output
136    Quiet,
137    /// Normal output
138    Default,
139    /// Verbose output
140    Verbose,
141}
142
143impl Default for LogLevel {
144    fn default() -> Self {
145        Self::Default
146    }
147}
148
149/// Configuration for the CLI tool
150#[derive(Debug, Clone, Serialize, Deserialize, Default)]
151pub struct Config {
152    /// The execution mode
153    pub execution_mode: ExecutionMode,
154    /// The log level
155    pub log_level: LogLevel,
156    /// The root directory for operations
157    pub root_path: Option<PathBuf>,
158    /// The path to the navigation guide file
159    pub guide_path: Option<PathBuf>,
160    /// The original guide path as provided by the user (for error messages)
161    pub original_guide_path: Option<String>,
162    /// The original root path as provided by the user (for error messages)
163    pub original_root_path: Option<String>,
164}