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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//! # Guardy - Fast, secure git hooks in Rust
//!
//! Guardy is a high-performance git hooks framework written in Rust that provides:
//!
//! - **Fast Security Scanning**: Multi-threaded secret detection with entropy analysis
//! - **Protected File Synchronization**: Keep configuration files in sync across repositories
//! - **Comprehensive Git Hook Support**: Pre-commit, pre-push, and other git hooks
//! - **Flexible Configuration**: YAML, TOML, and JSON configuration support
//!
//! ## Quick Start
//!
//! ### Installation
//!
//! ```bash
//! # Install from crates.io
//! cargo install guardy
//!
//! # Or clone and build
//! git clone https://github.com/deepbrainspace/guardy
//! cd guardy
//! cargo build --release
//! ```
//!
//! ### Basic Usage
//!
//! ```bash
//! # Install git hooks in your repository
//! guardy install
//!
//! # Scan files for secrets
//! guardy scan src/
//!
//! # Check status
//! guardy status
//!
//! # Sync protected files
//! guardy sync
//! ```
//!
//! ## Git Hooks Integration
//!
//! Guardy provides flexible git hook management with both built-in actions and custom commands.
//! Hooks can be configured to run secret scanning, file synchronization, and custom commands.
//!
//! ### Hook Configuration Example
//!
//! ```yaml
//! hooks:
//! pre-commit:
//! enabled: true
//! builtin: ["scan_secrets"] # Built-in secret scanning
//! custom:
//! - command: "cargo fmt --check"
//! description: "Check code formatting"
//! fail_on_error: true
//!
//! pre-push:
//! enabled: true
//! custom:
//! - command: "guardy sync update --force --config ./guardy.yaml"
//! description: "Sync protected files before push"
//! fail_on_error: true
//! ```
//!
//! ## Repository Synchronization
//!
//! The sync feature allows you to keep files synchronized from upstream repositories.
//! This is particularly useful for maintaining consistent configurations across multiple projects.
//!
//! ### Automating Sync with Hooks
//!
//! You can integrate sync into your git workflow to ensure files stay synchronized:
//!
//! ```yaml
//! sync:
//! repos:
//! - name: "shared-configs"
//! repo: "https://github.com/org/shared-configs"
//! version: "v1.0.0" # Can be tag, branch, or commit
//! source_path: ".github"
//! dest_path: "./.github"
//! include: ["**/*"]
//! exclude: ["*.md"]
//!
//! hooks:
//! pre-push:
//! enabled: true
//! custom:
//! - command: "guardy sync update --force --config ./guardy.yaml"
//! description: "Ensure configs are synchronized"
//! fail_on_error: true
//! ```
//!
//! This configuration ensures that protected files are restored to their canonical versions
//! before pushing changes, preventing drift from the upstream configuration.
//!
//! ## Library Usage
//!
//! Guardy can also be used as a library for building custom security tools:
//!
//! ```rust,no_run
//! use std::path::Path;
//!
//! use guardy::scan::Scanner;
//!
//! // Create scanner with global config
//! let scanner = Scanner::new()?;
//!
//! // Scan files for secrets with streaming output
//! let stats = scanner.scan(&[Path::new("src/").to_path_buf()])?;
//!
//! // Results are streamed during scanning
//! println!("Scanned {} files, found {} matches", stats.files_scanned, stats.total_matches);
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//! ## Protected File Sync
//!
//! Keep configuration files synchronized across repositories:
//!
//! ```yaml
//! # guardy.yaml
//! sync:
//! repos:
//! - name: "shared-config"
//! repo: "https://github.com/yourorg/shared-configs"
//! version: "main"
//! source_path: "."
//! dest_path: "."
//! include: ["*.yml", "*.json"]
//! exclude: [".git"]
//! ```
//!
//! ```bash
//! # Show what has changed
//! guardy sync diff
//!
//! # Update files interactively
//! guardy sync
//!
//! # Force update all changes
//! guardy sync --force
//! ```
//!
//! ## Features
//!
//! - **Multi-threaded scanning** with configurable parallelism
//! - **Entropy-based secret detection** for high accuracy
//! - **Git integration** with hooks and remote operations
//! - **File synchronization** with diff visualization
//! - **Multiple output formats** (JSON, HTML, plain text)
//! - **Comprehensive configuration** via YAML/TOML/JSON
// High-performance scanner with scan-v3 optimizations