Skip to content

Commit 5567b78

Browse files
committed
feat: Add Phase 3 optimization files and documentation
1 parent 6b38c66 commit 5567b78

28 files changed

+14162
-34
lines changed

.cargo/config.toml.bak

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Optimized build configurations for Code Guardian
2+
3+
[build]
4+
# Enable incremental compilation for faster rebuilds
5+
incremental = true
6+
7+
# Build cache settings
8+
target-dir = "target"
9+
10+
# Enable parallel rustc
11+
# rustc-wrapper = "sccache" # Optional: requires sccache installation
12+
13+
# Use faster linker when available
14+
# [target.x86_64-unknown-linux-gnu]
15+
# linker = "clang"
16+
# rustflags = ["-C", "link-arg=-fuse-ld=lld"]
17+
18+
# [target.x86_64-apple-darwin]
19+
# rustflags = ["-C", "link-arg=-fuse-ld=lld"]
20+
21+
# [target.x86_64-pc-windows-msvc]
22+
# linker = "rust-lld.exe"
23+
24+
# Cargo aliases for common development tasks
25+
[alias]
26+
# Fast development check (no clippy)
27+
quick = "check --all-targets"
28+
29+
# Fast test run (unit tests only)
30+
test-fast = "test --lib"
31+
32+
# Fast build for development
33+
dev-build = "build --workspace"
34+
35+
# Release build with full optimization
36+
release-build = "build --release --workspace"
37+
38+
# Clean and rebuild everything
39+
fresh = ["clean", "build", "--workspace"]
40+
41+
# Profile compilation times
42+
time = "build --timings"
43+
44+
# Check dependencies for security issues
45+
audit = "audit"
46+
47+
# Update dependencies
48+
update-deps = "update"
49+
50+
# Format, lint, and test in sequence
51+
quality = ["fmt", "clippy", "test"]
52+
53+
# Development profile optimizations
54+
[profile.dev]
55+
# Optimize dependencies but not our code for faster builds
56+
opt-level = 0
57+
debug = true
58+
debug-assertions = true
59+
overflow-checks = true
60+
lto = false
61+
panic = 'unwind'
62+
incremental = true
63+
codegen-units = 256 # More codegen units for parallel compilation
64+
65+
# Optimize dependencies for better development experience
66+
[profile.dev.package."*"]
67+
opt-level = 2
68+
debug = false
69+
70+
# Fast development profile (even faster builds)
71+
[profile.dev-fast]
72+
inherits = "dev"
73+
opt-level = 0
74+
debug = false # No debug info for faster builds
75+
debug-assertions = false
76+
overflow-checks = false
77+
incremental = true
78+
codegen-units = 256
79+
80+
# Test profile optimizations
81+
[profile.test]
82+
opt-level = 1 # Some optimization for faster test execution
83+
debug = true
84+
debug-assertions = true
85+
overflow-checks = true
86+
incremental = true
87+
88+
# Release profile optimizations
89+
[profile.release]
90+
opt-level = 3 # Maximum optimization
91+
debug = false # No debug info in release
92+
debug-assertions = false
93+
overflow-checks = false
94+
lto = "fat" # Full link-time optimization
95+
panic = 'abort' # Smaller binary size
96+
codegen-units = 1 # Better optimization
97+
strip = true # Strip symbols for smaller binary
98+
99+
# Production release profile
100+
[profile.release-prod]
101+
inherits = "release"
102+
opt-level = "s" # Optimize for size
103+
lto = "fat"
104+
panic = 'abort'
105+
strip = true
106+
107+
# Benchmark profile
108+
[profile.bench]
109+
opt-level = 3
110+
debug = false
111+
debug-assertions = false
112+
overflow-checks = false
113+
lto = "fat"
114+
codegen-units = 1
115+
116+
# Git fetch optimization
117+
[net]
118+
retry = 3
119+
git-fetch-with-cli = true
120+
121+
# HTTP timeout settings
122+
[http]
123+
timeout = 30
124+
multiplexing = true
125+
user-agent = "code-guardian (rust-cargo)"

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CARGO_INCREMENTAL=1
2+
CARGO_TARGET_DIR=target

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ node_modules
3131

3232
# Archived plans
3333
/plans/archive
34+
clippy_output.json

.opencode/package.json

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
{
2+
"name": "code-guardian-opencode-plugin",
3+
"version": "1.0.0",
4+
"description": "OpenCode plugin for Code Guardian, providing linting and testing best practices",
5+
"type": "module",
26
"dependencies": {
3-
"@opencode-ai/plugin": "0.15.0"
7+
"@opencode-ai/plugin": "0.15.3"
8+
},
9+
"devDependencies": {
10+
"@babel/core": "^7.28.4",
11+
"@babel/preset-env": "^7.28.3",
12+
"@types/jest": "^29.5.8",
13+
"@typescript-eslint/eslint-plugin": "^6.21.0",
14+
"@typescript-eslint/parser": "^6.21.0",
15+
"eslint": "^8.57.0",
16+
"jest": "^29.7.0",
17+
"ts-jest": "^29.1.1"
18+
},
19+
"scripts": {
20+
"lint": "eslint . --ext .js,.ts",
21+
"test": "jest"
422
}
5-
}
23+
}

crates/cli/src/commands/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//! Command implementations for Code Guardian CLI
2+
//!
3+
//! This module contains the core command implementations organized by functionality.
4+
5+
pub mod scan;
6+
pub mod report;
7+
pub mod git;
8+
pub mod production;
9+
10+
pub use scan::*;
11+
pub use report::*;
12+
pub use git::*;
13+
pub use production::*;

crates/cli/src/commands/report.rs

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
//! Report command implementations
2+
3+
use anyhow::Result;
4+
use std::path::PathBuf;
5+
use code_guardian_storage::SqliteStorage;
6+
use code_guardian_output::formatters::{JsonFormatter, TextFormatter, HtmlFormatter, MarkdownFormatter};
7+
use crate::utils::get_db_path;
8+
9+
pub struct ReportCommand {
10+
pub id: Option<i64>,
11+
pub format: String,
12+
pub db: Option<PathBuf>,
13+
pub output: Option<PathBuf>,
14+
}
15+
16+
impl ReportCommand {
17+
pub fn new(format: String) -> Self {
18+
Self {
19+
id: None,
20+
format,
21+
db: None,
22+
output: None,
23+
}
24+
}
25+
26+
pub fn with_id(mut self, id: i64) -> Self {
27+
self.id = Some(id);
28+
self
29+
}
30+
31+
pub fn with_output(mut self, output: PathBuf) -> Self {
32+
self.output = Some(output);
33+
self
34+
}
35+
36+
pub async fn execute(&self) -> Result<()> {
37+
let db_path = get_db_path(self.db.clone());
38+
let storage = SqliteStorage::new(&db_path)?;
39+
40+
let results = if let Some(id) = self.id {
41+
vec![storage.get_scan_results(id).await?]
42+
} else {
43+
// Get latest scan results
44+
storage.get_latest_scan_results(1).await?
45+
};
46+
47+
if results.is_empty() {
48+
println!("No scan results found");
49+
return Ok(());
50+
}
51+
52+
let formatted_output = match self.format.as_str() {
53+
"json" => {
54+
let formatter = JsonFormatter::new();
55+
formatter.format(&results[0])?
56+
}
57+
"html" => {
58+
let formatter = HtmlFormatter::new();
59+
formatter.format(&results[0])?
60+
}
61+
"markdown" => {
62+
let formatter = MarkdownFormatter::new();
63+
formatter.format(&results[0])?
64+
}
65+
_ => {
66+
let formatter = TextFormatter::new();
67+
formatter.format(&results[0])?
68+
}
69+
};
70+
71+
if let Some(output_path) = &self.output {
72+
std::fs::write(output_path, formatted_output)?;
73+
println!("📄 Report written to {}", output_path.display());
74+
} else {
75+
println!("{}", formatted_output);
76+
}
77+
78+
Ok(())
79+
}
80+
}
81+
82+
pub struct HistoryCommand {
83+
pub db: Option<PathBuf>,
84+
pub limit: Option<usize>,
85+
}
86+
87+
impl HistoryCommand {
88+
pub fn new() -> Self {
89+
Self {
90+
db: None,
91+
limit: Some(10),
92+
}
93+
}
94+
95+
pub async fn execute(&self) -> Result<()> {
96+
let db_path = get_db_path(self.db.clone());
97+
let storage = SqliteStorage::new(&db_path)?;
98+
99+
let history = storage.get_scan_history(self.limit.unwrap_or(10)).await?;
100+
101+
if history.is_empty() {
102+
println!("No scan history found");
103+
return Ok(());
104+
}
105+
106+
println!("📊 Scan History:");
107+
println!("{:<5} {:<20} {:<15} {:<10}", "ID", "Timestamp", "Path", "Issues");
108+
println!("{}", "-".repeat(60));
109+
110+
for entry in history {
111+
println!(
112+
"{:<5} {:<20} {:<15} {:<10}",
113+
entry.id,
114+
entry.timestamp.format("%Y-%m-%d %H:%M:%S"),
115+
entry.path.display(),
116+
entry.issue_count
117+
);
118+
}
119+
120+
Ok(())
121+
}
122+
}
123+
124+
#[cfg(test)]
125+
mod tests {
126+
use super::*;
127+
128+
#[test]
129+
fn test_report_command_creation() {
130+
let cmd = ReportCommand::new("json".to_string());
131+
assert_eq!(cmd.format, "json");
132+
assert!(cmd.id.is_none());
133+
}
134+
135+
#[test]
136+
fn test_report_command_builder() {
137+
let cmd = ReportCommand::new("html".to_string())
138+
.with_id(123)
139+
.with_output(PathBuf::from("output.html"));
140+
141+
assert_eq!(cmd.format, "html");
142+
assert_eq!(cmd.id, Some(123));
143+
assert_eq!(cmd.output, Some(PathBuf::from("output.html")));
144+
}
145+
146+
#[test]
147+
fn test_history_command_creation() {
148+
let cmd = HistoryCommand::new();
149+
assert_eq!(cmd.limit, Some(10));
150+
assert!(cmd.db.is_none());
151+
}
152+
}

0 commit comments

Comments
 (0)