Context
Part of the --suggest recommendations engine (see #135). Depends on #137, #138, #140.
What to Build
1. --precommit flag and changed-file scoping
Add --precommit flag to CLI. When active:
- Detect staged files via
git diff --cached --name-only
- Scope
SuggestEngine to only those files + their direct callers/callees in the call graph (for context)
- Output in a pre-commit-friendly format (exit code 0 for pass, 1 for fail)
// src/suggest/precommit.rs
pub fn run_precommit(config: &SuggestConfig, cache: &CacheDir) -> Result<PrecommitResult> {
let changed_files = git_staged_files()?;
let scope = SuggestScope::Files(changed_files);
// ... evaluate with scope, apply precommit config
}
pub struct PrecommitResult {
pub recommendations: Vec<Recommendation>,
pub should_block: bool, // based on config thresholds
pub exit_code: i32,
}
2. Pre-commit config in .semfora/suggest.yaml
precommit:
enabled: true
mode: warn # warn (exit 0) | fail (exit 1 if threshold exceeded)
fail_threshold: 3 # block if > N suggestions
groups: # per-group override
dead-code: fail # always block on dead code
naming: warn # just warn on naming
complexity: fail
3. Hook installation helpers
semfora suggest --install-hook — writes to .git/hooks/pre-commit (or appends if exists)
semfora suggest --install-hook --husky — writes to .husky/pre-commit
- Provide
.pre-commit-hooks.yaml for the pre-commit framework:
- id: semfora-suggest
name: semfora code suggestions
entry: semfora-engine suggest --precommit
language: system
types: [file]
pass_filenames: false
4. Performance
- Only load symbols for changed files (use
CacheDir symbol lookup by file path)
- Expand scope to include 1-hop callers/callees for context-aware rules
- Target: <500ms for typical commits (1-10 files)
Acceptance Criteria
References
Context
Part of the
--suggestrecommendations engine (see #135). Depends on #137, #138, #140.What to Build
1.
--precommitflag and changed-file scopingAdd
--precommitflag to CLI. When active:git diff --cached --name-onlySuggestEngineto only those files + their direct callers/callees in the call graph (for context)2. Pre-commit config in
.semfora/suggest.yaml3. Hook installation helpers
semfora suggest --install-hook— writes to.git/hooks/pre-commit(or appends if exists)semfora suggest --install-hook --husky— writes to.husky/pre-commit.pre-commit-hooks.yamlfor the pre-commit framework:4. Performance
CacheDirsymbol lookup by file path)Acceptance Criteria
semfora suggest --precommitruns only on staged files--install-hookcreates working git hooks.pre-commit-hooks.yamlprovided for pre-commit frameworkReferences
src/git/mod.rs