syncable_cli/agent/tools/mod.rs
1//! Agent tools using Rig's Tool trait
2//!
3//! These tools wrap existing CLI functionality for the agent to use.
4//!
5//! ## Available Tools
6//!
7//! ### File Operations
8//! - `ReadFileTool` - Read file contents
9//! - `WriteFileTool` - Write single files (Dockerfiles, Terraform, etc.)
10//! - `WriteFilesTool` - Write multiple files (Terraform modules, Helm charts)
11//! - `ListDirectoryTool` - List directory contents
12//!
13//! ### Analysis
14//! - `AnalyzeTool` - Analyze project architecture, dependencies, build commands
15//!
16//! ### Security
17//! - `SecurityScanTool` - Security vulnerability scanning
18//! - `VulnerabilitiesTool` - Dependency vulnerability checking
19//!
20//! ### Linting
21//! - `HadolintTool` - Native Dockerfile linting (best practices, security)
22//! - `DclintTool` - Native Docker Compose linting (best practices, style, security)
23//! - `HelmlintTool` - Native Helm chart structure/template linting
24//! - `KubelintTool` - Native Kubernetes manifest security/best practice linting
25//!
26//! ### Resource Optimization
27//! - `K8sOptimizeTool` - Kubernetes resource right-sizing and cost optimization
28//! - `K8sCostsTool` - Kubernetes workload cost attribution and analysis
29//! - `K8sDriftTool` - Detect configuration drift between manifests and cluster
30//!
31//! ### Prometheus Integration (for live K8s analysis)
32//! - `PrometheusDiscoverTool` - Discover Prometheus services in Kubernetes cluster
33//! - `PrometheusConnectTool` - Establish connection to Prometheus (port-forward or URL)
34//! - `BackgroundProcessManager` - Manage long-running background processes
35//!
36//! ### Helm vs Kubernetes Linting
37//! - **HelmlintTool**: Use for Helm chart development - validates Chart.yaml, values.yaml,
38//! Go template syntax, and Helm-specific best practices. Works on chart directories.
39//! - **KubelintTool**: Use for K8s security - checks rendered manifests for privileged containers,
40//! missing probes, RBAC issues, resource limits. Works on YAML files, Helm charts (renders them),
41//! and Kustomize directories.
42//!
43//! ### Diagnostics
44//! - `DiagnosticsTool` - Check for code errors via IDE/LSP or language-specific commands
45//!
46//! ### Terraform
47//! - `TerraformFmtTool` - Format Terraform configuration files
48//! - `TerraformValidateTool` - Validate Terraform configurations
49//! - `TerraformInstallTool` - Install Terraform CLI (auto-detects OS)
50//!
51//! ### Shell
52//! - `ShellTool` - Execute validation commands (docker build, terraform validate, helm lint)
53//!
54//! ### Planning (Forge-style workflow)
55//! - `PlanCreateTool` - Create structured plan files with task checkboxes
56//! - `PlanNextTool` - Get next pending task and mark it in-progress
57//! - `PlanUpdateTool` - Update task status (done, failed)
58//! - `PlanListTool` - List all available plan files
59//!
60//! ### Web
61//! - `WebFetchTool` - Fetch content from URLs (converts HTML to markdown)
62//!
63//! ### Platform (Syncable Platform API)
64//! - `ListOrganizationsTool` - List organizations the user belongs to
65//! - `ListProjectsTool` - List projects within an organization
66//! - `SelectProjectTool` - Select a project as current context
67//! - `CurrentContextTool` - Get the currently selected project context
68//! - `OpenProviderSettingsTool` - Open cloud provider settings in browser
69//! - `CheckProviderConnectionTool` - Check if a cloud provider is connected
70//! - `ListDeploymentConfigsTool` - List deployment configurations for a project
71//! - `TriggerDeploymentTool` - Trigger a deployment using a config
72//! - `GetDeploymentStatusTool` - Get deployment task status and progress
73//! - `ListDeploymentsTool` - List recent deployments with URLs
74//! - `GetServiceLogsTool` - Get container logs for a deployed service
75//!
76//! ## Error Handling Pattern
77//!
78//! Tools use the shared error utilities in `error.rs`:
79//!
80//! 1. Each tool keeps its own error type (e.g., `ReadFileError`, `ShellError`)
81//! 2. Use `ToolErrorContext` trait to add context when propagating errors
82//! 3. Use `format_error_for_llm` for structured JSON error responses to the agent
83//! 4. Error categories help the agent understand and recover from errors
84//!
85//! See `error.rs` for the complete error handling infrastructure.
86//!
87//! ## Response Format Pattern
88//!
89//! Tools use the shared response utilities in `response.rs` for consistent output:
90//!
91//! 1. Use `format_file_content` for file read operations (with truncation metadata)
92//! 2. Use `format_list` for directory listings and search results
93//! 3. Use `format_write_success` for successful write operations
94//! 4. Use `format_cancelled` for user-cancelled operations
95//! 5. Use `ResponseMetadata` to track truncation, compression, and item counts
96//!
97//! For large outputs (analysis, lint results), use `compress_tool_output` or
98//! `compress_analysis_output` from `compression.rs` which store full data
99//! and return a compressed summary with retrieval reference.
100//!
101//! ### Example
102//!
103//! ```ignore
104//! use crate::agent::tools::response::{format_file_content, format_list};
105//!
106//! // File read response
107//! Ok(format_file_content(&path, &content, total_lines, returned_lines, truncated))
108//!
109//! // Directory listing response
110//! Ok(format_list(&path, &entries, total_count, was_truncated))
111//! ```
112//!
113//! See `response.rs` for the complete response formatting infrastructure.
114
115mod analyze;
116pub mod background;
117pub mod compression;
118mod dclint;
119mod diagnostics;
120pub mod error;
121mod fetch;
122mod file_ops;
123mod hadolint;
124mod helmlint;
125mod k8s_costs;
126mod k8s_drift;
127mod k8s_optimize;
128mod kubelint;
129pub mod output_store;
130mod plan;
131pub mod platform;
132mod prometheus_connect;
133mod prometheus_discover;
134pub mod response;
135mod retrieve;
136mod security;
137mod shell;
138mod terraform;
139mod truncation;
140
141pub use truncation::{TruncationLimits, truncate_json_output};
142
143// Smart compression exports
144pub use compression::{CompressionConfig, compress_analysis_output, compress_tool_output};
145pub use retrieve::{ListOutputsTool, RetrieveOutputTool};
146
147// Error handling utilities for tools
148pub use error::{
149 ErrorCategory, ToolErrorContext, detect_error_category, format_error_for_llm,
150 format_error_with_context,
151};
152
153// Response formatting utilities for tools
154pub use response::{
155 ResponseMetadata, ToolResponse, format_cancelled, format_file_content,
156 format_file_content_range, format_list, format_list_with_metadata, format_success,
157 format_success_with_metadata, format_write_success,
158};
159
160pub use analyze::AnalyzeTool;
161pub use background::BackgroundProcessManager;
162pub use dclint::DclintTool;
163pub use diagnostics::DiagnosticsTool;
164pub use fetch::WebFetchTool;
165pub use file_ops::{ListDirectoryTool, ReadFileTool, WriteFileTool, WriteFilesTool};
166pub use hadolint::HadolintTool;
167pub use helmlint::HelmlintTool;
168pub use k8s_costs::K8sCostsTool;
169pub use k8s_drift::K8sDriftTool;
170pub use k8s_optimize::K8sOptimizeTool;
171pub use kubelint::KubelintTool;
172pub use plan::{PlanCreateTool, PlanListTool, PlanNextTool, PlanUpdateTool};
173pub use platform::{
174 CheckProviderConnectionTool, CreateDeploymentConfigTool, CurrentContextTool,
175 DeployServiceTool, GetDeploymentStatusTool, GetServiceLogsTool,
176 ListDeploymentCapabilitiesTool, ListDeploymentConfigsTool, ListDeploymentsTool,
177 ListOrganizationsTool, ListProjectsTool, OpenProviderSettingsTool, SelectProjectTool,
178 TriggerDeploymentTool,
179};
180pub use prometheus_connect::PrometheusConnectTool;
181pub use prometheus_discover::PrometheusDiscoverTool;
182pub use security::{SecurityScanTool, VulnerabilitiesTool};
183pub use shell::ShellTool;
184pub use terraform::{TerraformFmtTool, TerraformInstallTool, TerraformValidateTool};