-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
Overview
Add semfora-engine precommit subcommand and hook installation support. Only analyzes changed files for speed.
Depends on: #141 (Phase 2)
Parent research: #135
Implementation
1. Add Precommit subcommand to CLI
In src/cli.rs:
/// Run suggestions on staged changes (for git pre-commit hooks)
Precommit(PrecommitArgs),
#[derive(Args, Debug)]
pub struct PrecommitArgs {
#[arg(long, default_value = "warn", value_enum)]
pub mode: PrecommitMode, // warn or fail
#[arg(long, default_value = "0.7")]
pub threshold: f64, // min confidence to trigger fail
#[arg(short, long)]
pub path: Option<PathBuf>,
}
pub enum PrecommitMode { Warn, Fail }2. Create src/commands/precommit.rs
- Run
git diff --cached --name-onlyto get staged files - Filter to supported languages (reuse
Lang::from_extension) - Load index, build
SuggestContextscoped to changed files only - Run suggest engine
- Format output (always text for terminal)
- Exit code: 0 for warn mode; 0 or 1 for fail mode based on threshold
3. Add setup precommit subcommand
semfora-engine setup precommit [--mode warn|fail]
- Detect hook system: check for
.husky/,.pre-commit-config.yaml,lefthook.yml - If none found, write
.git/hooks/pre-commitdirectly - Generate appropriate config for detected system
4. Pre-commit framework support
Create .pre-commit-hooks.yaml in repo root:
- id: semfora-suggest
name: semfora suggestions
entry: semfora-engine precommit
language: system
types: [file]
stages: [pre-commit]5. Configuration
In semfora.toml:
[suggest.precommit]
mode = "warn" # warn or fail
threshold = 0.7
fail_categories = ["dead-code", "complexity"] # only these can block commits
warn_categories = ["naming", "module-org"] # always warn-onlyTesting
- Test with mock git staged files
- Test warn mode (always exit 0)
- Test fail mode with threshold
- Test category-based fail/warn split
- Test hook installation for plain git, husky, pre-commit framework
- Performance test: should complete in <200ms for typical commit (5-20 files)
Reactions are currently unavailable