1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//! Initialize a new Patina project skeleton
//!
//! This module follows the dependable-rust pattern:
//! - Public interface (this file): ≤150 lines, clean API
//! - Internal implementation: All logic in internal/ submodules
//!
//! # Example
//!
//! ```no_run
//! use patina::commands::init;
//!
//! // Initialize a new project skeleton
//! init::execute(
//! ".".to_string(),
//! false, // force
//! false, // local
//! false, // no_commit
//! ).expect("Failed to initialize project");
//!
//! // Then add an adapter:
//! // patina adapter add claude
//! ```
use Result;
/// Execute the init command to create or reinitialize a Patina project skeleton
///
/// # Arguments
///
/// * `name` - Project name or "." for current directory
/// * `force` - Force initialization, backup and replace existing patina branch
/// * `local` - Skip GitHub integration (local-only mode)
/// * `no_commit` - Skip automatic git commit
///
/// # Process
///
/// 1. **Git Setup**: Ensures proper git branch and fork (if external repo)
/// 2. **Environment Detection**: Identifies available tools and languages
/// 3. **Project Setup**: Creates .patina/ and layer/ structure
/// 4. **Pattern Copying**: Copies core patterns from Patina
///
/// # What This Does NOT Do
///
/// - Create adapter directories (.claude/, .gemini/)
/// - Configure MCP
/// - Run scrape or oxidize
/// - Create devcontainer (use `patina yolo` for that)
///
/// Use `patina adapter add <claude|gemini|opencode>` to add LLM support.
///
/// # Re-initialization
///
/// When run in an existing Patina project:
/// - Preserves adapter config (adapters.allowed, adapters.default)
/// - Refreshes environment detection
///
/// # Errors
///
/// Returns an error if:
/// - Not a git repository
/// - Working tree has uncommitted changes (unless --force)
/// - Directory creation fails
/// - Environment validation shows critical missing tools