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    /// Force overwrite existing configuration
48    pub force: bool,
49    /// Custom config file path (optional)
50    pub config_path: Option<PathBuf>,
51}
52
53impl Default for SetupOptions {
54    fn default() -> Self {
55        Self {
56            scope: SetupScope::User,
57            force: false,
58            config_path: None,
59        }
60    }
61}
62
63/// Result of a setup operation
64#[derive(Debug, Serialize, Deserialize)]
65pub struct SetupResult {
66    /// Whether the operation succeeded
67    pub success: bool,
68    /// Human-readable message
69    pub message: String,
70    /// Files that were created or modified
71    pub files_modified: Vec<PathBuf>,
72    /// Connectivity test result (if performed)
73    pub connectivity_test: Option<ConnectivityResult>,
74}
75
76/// Result of a connectivity test
77#[derive(Debug, Serialize, Deserialize)]
78pub struct ConnectivityResult {
79    /// Whether the test passed
80    pub passed: bool,
81    /// Test details
82    pub details: String,
83}
84
85/// Trait for setup modules
86pub trait SetupModule {
87    /// Module name (e.g., "claude-code")
88    fn name(&self) -> &str;
89
90    /// Perform setup
91    fn setup(&self, opts: &SetupOptions) -> Result<SetupResult>;
92
93    /// Test connectivity
94    fn test_connectivity(&self) -> Result<ConnectivityResult>;
95}