Skip to content

Commit d0b81ef

Browse files
GeneAIclaude
authored andcommitted
feat: Bug scanner tuning, VSCode cleanup, and PR review fix
## Bug Prediction Scanner - Add smart false positive filtering for dangerous_eval detection - Add context-aware broad exception analysis - Wire scanner to empathy.config.yml for customization - Reduce false positives from 110 to 79 patterns ## VSCode Extension (v1.3.1) - Remove Refactor Advisor and Test Generator dropdown panels - Keep Generate Tests button (runs workflow directly) - Temporarily hide Workflow Wizard panel ## PR Review Workflow - Fix "CodeReviewCrew unavailable" by mapping hybrid→anthropic - All 9 agents now properly initialize ## Documentation - Add bug prediction workflow to CLI Guide - Add scanner-patterns.md rule file - Add bug_predict section to empathy.config.yml 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 657f4e5 commit d0b81ef

File tree

102 files changed

+11540
-1025
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+11540
-1025
lines changed

.claude/CLAUDE.md

Lines changed: 8 additions & 404 deletions
Large diffs are not rendered by default.

.claude/python-standards.md

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -4,80 +4,3 @@
44
- Follow PEP 8
55
- Write docstrings
66
- Target 90%+ test coverage
7-
8-
## Cross-Platform Compatibility
9-
10-
The Empathy Framework must work on Windows, macOS, and Linux. Follow these guidelines:
11-
12-
### File Paths
13-
14-
- **Always use `pathlib.Path`** instead of string concatenation for paths
15-
- **Never hardcode path separators** (`/` or `\`)
16-
- **Use `empathy_os.platform_utils`** for OS-specific directories:
17-
18-
```python
19-
from empathy_os.platform_utils import get_default_log_dir, get_default_data_dir
20-
21-
# Good: Platform-appropriate paths
22-
log_dir = get_default_log_dir() # ~/Library/Logs/empathy on macOS, %APPDATA%/empathy/logs on Windows
23-
24-
# Bad: Hardcoded Unix path
25-
log_dir = Path("/var/log/empathy")
26-
```
27-
28-
### File Encoding
29-
30-
- **Always specify `encoding="utf-8"`** when opening text files:
31-
32-
```python
33-
# Good
34-
with open(path, "r", encoding="utf-8") as f:
35-
content = f.read()
36-
37-
# Bad (Windows defaults to cp1252)
38-
with open(path, "r") as f:
39-
content = f.read()
40-
```
41-
42-
- Use `empathy_os.platform_utils.read_text_file()` and `write_text_file()` for convenience
43-
44-
### Asyncio
45-
46-
- **Call `setup_asyncio_policy()`** before any `asyncio.run()` in CLI entry points:
47-
48-
```python
49-
from empathy_os.platform_utils import setup_asyncio_policy
50-
51-
def main():
52-
setup_asyncio_policy() # Required for Windows compatibility
53-
asyncio.run(async_main())
54-
```
55-
56-
- Windows requires `WindowsSelectorEventLoopPolicy` for compatibility with many libraries
57-
58-
### Line Endings
59-
60-
- Git handles line endings via `.gitattributes`
61-
- When writing files programmatically, use `\n` (Git will convert on checkout)
62-
63-
### Environment Variables
64-
65-
- Use `os.environ.get()` with sensible defaults
66-
- Remember Windows uses different variable names (`%APPDATA%` vs `$HOME`)
67-
68-
### Subprocess Calls
69-
70-
- Use `subprocess.run()` with `shell=False` when possible
71-
- Avoid shell-specific syntax (pipes, redirects) in subprocess calls
72-
- Use `shlex.split()` on Unix, but note it doesn't work on Windows
73-
74-
### Testing
75-
76-
- Mock `platform.system()` to test all OS paths:
77-
78-
```python
79-
with patch("platform.system", return_value="Windows"):
80-
assert is_windows() is True
81-
```
82-
83-
- Run tests on all platforms via CI (see `.github/workflows/tests.yml` - runs on ubuntu, macos, windows)

.claude/rules/empathy/debugging.md

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Debugging Patterns
22

33
Auto-generated from Empathy Framework learned patterns.
4-
Total patterns: 11
4+
Total patterns: 40
55

66
---
77

@@ -63,3 +63,48 @@ When debugging similar issues, consider these historical fixes:
6363
- **Root cause**: feat: Release v3.0.1 - XML-Enhanced Prompts & Security Fixes
6464
- **Fix**: See commit 8edfb707
6565
- **Files**: .claude/CLAUDE.md, .gitignore, CHANGELOG.md
66+
67+
### import_error
68+
- **Root cause**: fix: Resolve import conflict between workflows.py and workflows/ package
69+
- **Fix**: See commit 1b928aec
70+
- **Files**: src/empathy_os/workflows/__init__.py
71+
72+
### unknown
73+
- **Root cause**: ci: Add workflow_dispatch to PyPI publish workflow
74+
- **Fix**: See commit 32d3adcf
75+
- **Files**: .github/workflows/publish-pypi.yml
76+
77+
### type_mismatch
78+
- **Root cause**: fix: Convert MkDocs relative asset paths to absolute for CSS loading
79+
- **Fix**: See commit 2ae52706
80+
- **Files**: scripts/fix_mkdocs_paths.py, .../framework-docs/FOREWORD_BY_CLAUDE/index.html, .../framework-docs/about-the-author/index.html
81+
82+
### unknown
83+
- **Root cause**: fix: Force trailing slashes at all levels for MkDocs CSS compatibility
84+
- **Fix**: See commit 4e9157ce
85+
- **Files**: website/middleware.ts, website/next.config.ts, website/vercel.json
86+
87+
### unknown
88+
- **Root cause**: fix: Use skipTrailingSlashRedirect to stop Next.js from stripping trailing slashes
89+
- **Fix**: See commit 55265287
90+
- **Files**: website/next.config.ts, website/vercel.json
91+
92+
### unknown
93+
- **Root cause**: fix: Add Next.js middleware to enforce trailing slash for framework-docs
94+
- **Fix**: See commit 47662816
95+
- **Files**: website/middleware.ts
96+
97+
### unknown
98+
- **Root cause**: fix: Add Vercel trailingSlash config for framework-docs CSS
99+
- **Fix**: See commit 994d5ad5
100+
- **Files**: website/vercel.json
101+
102+
### unknown
103+
- **Root cause**: fix: Add vercel.json redirect for framework-docs trailing slash
104+
- **Fix**: See commit 0c56cfb1
105+
- **Files**: website/vercel.json
106+
107+
### unknown
108+
- **Root cause**: fix: Add redirect to ensure trailing slash for framework-docs CSS paths
109+
- **Fix**: See commit 3ba1de27
110+
- **Files**: website/next.config.ts
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# Bug Prediction Scanner Patterns
2+
3+
This document describes the patterns detected by `empathy workflow run bug-predict` and the smart filtering applied to reduce false positives.
4+
5+
## Detected Patterns
6+
7+
| Pattern | Severity | Description |
8+
|---------|----------|-------------|
9+
| `dangerous_eval` | HIGH | Use of `eval()` or `exec()` on untrusted input |
10+
| `broad_exception` | MEDIUM | Bare `except:` or `except Exception:` that may mask errors |
11+
| `incomplete_code` | LOW | TODO/FIXME comments indicating unfinished work |
12+
13+
## Automatic False Positive Filtering
14+
15+
### dangerous_eval Exclusions
16+
17+
The scanner automatically excludes:
18+
19+
1. **Scanner test files** - Files matching:
20+
- `test_bug_predict*`
21+
- `test_scanner*`
22+
- `test_security_scan*`
23+
24+
2. **Test fixtures** - Code inside `write_text()` calls (test data written to temp files)
25+
26+
3. **Detection code** - String literals like `if "eval(" in content`
27+
28+
4. **JavaScript regex.exec()** - Safe method calls like `pattern.exec(text)`
29+
30+
### broad_exception Exclusions
31+
32+
The scanner uses context analysis to allow acceptable patterns:
33+
34+
1. **Version detection with fallback**
35+
```python
36+
try:
37+
return get_version("package")
38+
except Exception:
39+
return "dev" # Acceptable: graceful fallback
40+
```
41+
42+
2. **Config loading with defaults**
43+
```python
44+
try:
45+
config = yaml.safe_load(f)
46+
except Exception:
47+
pass # Fall back to default config
48+
```
49+
50+
3. **Optional feature detection**
51+
```python
52+
try:
53+
import optional_lib
54+
except Exception:
55+
optional_lib = None
56+
```
57+
58+
4. **Cleanup/teardown code**
59+
- `__del__`, `__exit__`, `cleanup()`, `close()`, `teardown()`
60+
61+
5. **Logging with re-raise**
62+
```python
63+
except Exception as e:
64+
logger.error(f"Error: {e}")
65+
raise # Re-raises after logging
66+
```
67+
68+
6. **Intentional comments**
69+
- `# fallback`, `# optional`, `# best effort`, `# graceful`
70+
71+
## When Reviewing Scanner Results
72+
73+
1. **HIGH severity (dangerous_eval)**: Always investigate - these are security risks
74+
2. **MEDIUM severity (broad_exception)**: Review context - may be acceptable
75+
3. **LOW severity (incomplete_code)**: Track in backlog - not urgent
76+
77+
## Customizing Scanner Behavior
78+
79+
Add exclusions in `empathy.config.yml`:
80+
81+
```yaml
82+
bug_predict:
83+
exclude_files:
84+
- "**/test_*.py"
85+
- "**/fixtures/**"
86+
acceptable_exception_contexts:
87+
- version
88+
- config
89+
- cleanup
90+
```
91+
92+
## Related Commands
93+
94+
```bash
95+
# Run bug prediction
96+
empathy workflow run bug-predict
97+
98+
# Scan specific directory
99+
empathy workflow run bug-predict --input '{"path":"./src"}'
100+
101+
# JSON output for CI
102+
empathy workflow run bug-predict --json
103+
```

0 commit comments

Comments
 (0)