intent_engine/setup/
mod.rs

1//! Setup module for configuring intent-engine integration with AI tools
2//!
3//! This module provides a unified setup command that configures both hooks and MCP servers
4//! for various AI assistant tools (Claude Code, Gemini CLI, Codex, etc.)
5
6use crate::error::{IntentError, Result};
7use serde::{Deserialize, Serialize};
8use std::path::PathBuf;
9use std::str::FromStr;
10
11pub mod claude_code;
12pub mod common;
13pub mod interactive;
14
15/// Installation scope for setup
16#[derive(Debug, Clone, Copy, PartialEq, Eq)]
17pub enum SetupScope {
18    /// User-level installation (recommended, works across all projects)
19    User,
20    /// Project-level installation (specific to current project)
21    Project,
22    /// Both user and project level
23    Both,
24}
25
26impl FromStr for SetupScope {
27    type Err = IntentError;
28
29    fn from_str(s: &str) -> Result<Self> {
30        match s.to_lowercase().as_str() {
31            "user" => Ok(SetupScope::User),
32            "project" => Ok(SetupScope::Project),
33            "both" => Ok(SetupScope::Both),
34            _ => Err(IntentError::InvalidInput(format!(
35                "Invalid scope: {}. Must be 'user', 'project', or 'both'",
36                s
37            ))),
38        }
39    }
40}
41
42/// Options for setup operations
43#[derive(Debug, Clone)]
44pub struct SetupOptions {
45    /// Installation scope
46    pub scope: SetupScope,
47    /// Dry run mode (show what would be done)
48    pub dry_run: bool,
49    /// Force overwrite existing configuration
50    pub force: bool,
51    /// Custom config file path (optional)
52    pub config_path: Option<PathBuf>,
53}
54
55impl Default for SetupOptions {
56    fn default() -> Self {
57        Self {
58            scope: SetupScope::User,
59            dry_run: false,
60            force: false,
61            config_path: None,
62        }
63    }
64}
65
66/// Result of a setup operation
67#[derive(Debug, Serialize, Deserialize)]
68pub struct SetupResult {
69    /// Whether the operation succeeded
70    pub success: bool,
71    /// Human-readable message
72    pub message: String,
73    /// Files that were created or modified
74    pub files_modified: Vec<PathBuf>,
75    /// Connectivity test result (if performed)
76    pub connectivity_test: Option<ConnectivityResult>,
77}
78
79/// Result of a connectivity test
80#[derive(Debug, Serialize, Deserialize)]
81pub struct ConnectivityResult {
82    /// Whether the test passed
83    pub passed: bool,
84    /// Test details
85    pub details: String,
86}
87
88/// Result of a diagnosis operation
89#[derive(Debug, Serialize, Deserialize)]
90pub struct DiagnosisReport {
91    /// Overall status (all checks passed?)
92    pub overall_status: bool,
93    /// Individual check results
94    pub checks: Vec<DiagnosisCheck>,
95    /// Suggested fixes for failed checks
96    pub suggested_fixes: Vec<String>,
97}
98
99/// Individual diagnosis check
100#[derive(Debug, Serialize, Deserialize)]
101pub struct DiagnosisCheck {
102    /// Check name
103    pub name: String,
104    /// Whether the check passed
105    pub passed: bool,
106    /// Details or error message
107    pub details: String,
108}
109
110/// Trait for setup modules
111pub trait SetupModule {
112    /// Module name (e.g., "claude-code")
113    fn name(&self) -> &str;
114
115    /// Perform setup
116    fn setup(&self, opts: &SetupOptions) -> Result<SetupResult>;
117
118    /// Diagnose existing setup
119    fn diagnose(&self) -> Result<DiagnosisReport>;
120
121    /// Test connectivity
122    fn test_connectivity(&self) -> Result<ConnectivityResult>;
123}