Fix LLM Artifacts
Apply fixes from a previous review-llm-artifacts run with automatic safe/risky classification.
Usage
CODEBLOCK0
Flags:
- -
--dry-run - Show what would be fixed without changing files - INLINECODE2 - Fix entire codebase (runs review with --all first)
- INLINECODE3 - Only fix specific category: INLINECODE4
Instructions
1. Parse Arguments
Extract flags from $ARGUMENTS:
- -
--dry-run - Preview mode only - INLINECODE7 - Full codebase scan
- INLINECODE8 - Filter to specific category
2. Pre-flight Safety Checks
CODEBLOCK1
If working directory is dirty, warn:
CODEBLOCK2
Create stash if dirty:
CODEBLOCK3
3. Load Review Results
Check for existing review file:
CODEBLOCK4
If file missing:
- - If
--all flag: Run review-llm-artifacts --all --json first - Otherwise: Fail with: "No review results found. Run
/beagle-core:review-llm-artifacts first."
If file exists, validate freshness:
CODEBLOCK5
If stale, prompt: "Review results are stale. Re-run review? (y/n)"
4. Partition Findings by Safety
Parse findings from JSON and classify by fix_safety field:
Safe Fixes (auto-apply):
- -
unused_import - Unused imports - INLINECODE14 - Stale TODO/FIXME comments
- INLINECODE15 - Obviously unreachable code
- INLINECODE16 - Overly verbose LLM-style comments
- INLINECODE17 - Redundant type annotations
Risky Fixes (require confirmation):
- -
test_refactor - Test structure changes - INLINECODE19 - Class/function extraction
- INLINECODE20 - Removing functional code
- INLINECODE21 - Test mock scope changes
- INLINECODE22 - Any behavioral modifications
5. Apply Safe Fixes
If --dry-run:
CODEBLOCK6
Otherwise, spawn parallel agents per category with Task tool:
CODEBLOCK7
Categories to parallelize:
- -
style - Comments, formatting - INLINECODE26 - Imports, unreachable code
- INLINECODE27 - Test-related safe fixes
- INLINECODE28 - Safe refactors
6. Handle Risky Fixes
For each risky fix, prompt interactively:
CODEBLOCK8
Track user choices:
- -
y - Apply this fix - INLINECODE30 - Skip this fix
- INLINECODE31 - Skip all remaining risky fixes
7. Post-Fix Verification
Detect project type and run appropriate linters:
Python:
CODEBLOCK9
TypeScript/JavaScript:
CODEBLOCK10
Go:
CODEBLOCK11
8. Run Tests
CODEBLOCK12
9. Report Results
CODEBLOCK13 bash
git diff --stat
## Cleanup
On successful completion (all verifications pass):
bash
rm .beagle/llm-artifacts-review.json
If any verification fails, keep the file and report:
Review file preserved at .beagle/llm-artifacts-review.json
Fix issues and re-run, or restore with: git stash pop
## Example
bash
Preview all fixes without applying
/beagle-core:fix-llm-artifacts --dry-run
Fix only dead code issues
/beagle-core:fix-llm-artifacts --category dead-code
Full codebase scan and fix
/beagle-core:fix-llm-artifacts --all
Fix style issues only, preview first
/beagle-core:fix-llm-artifacts --category style --dry-run
```
修复LLM产物
应用先前review-llm-artifacts运行中的修复,并自动进行安全/风险分类。
使用方法
/beagle-core:fix-llm-artifacts [--dry-run] [--all] [--category ]
标志:
- - --dry-run - 显示将要修复的内容,但不修改文件
- --all - 修复整个代码库(先使用--all运行审查)
- --category - 仅修复特定类别:tests|dead-code|abstraction|style
操作说明
1. 解析参数
从$ARGUMENTS中提取标志:
- - --dry-run - 仅预览模式
- --all - 全代码库扫描
- --category - 筛选特定类别
2. 飞行前安全检查
bash
检查未提交的更改
git status --porcelain
如果工作目录有未提交更改,发出警告:
警告:您有未提交的更改。将在继续前创建git stash。
如需恢复,请运行git stash pop。
如果有未提交更改则创建stash:
bash
git stash push -m beagle-core: pre-fix-llm-artifacts backup
3. 加载审查结果
检查现有审查文件:
bash
cat .beagle/llm-artifacts-review.json 2>/dev/null
如果文件缺失:
- - 如果使用--all标志:先运行review-llm-artifacts --all --json
- 否则:失败并提示:未找到审查结果。请先运行/beagle-core:review-llm-artifacts。
如果文件存在,验证时效性:
bash
从JSON获取存储的git HEAD
stored
head=$(jq -r .githead .beagle/llm-artifacts-review.json)
current_head=$(git rev-parse HEAD)
if [ $storedhead != $currenthead ]; then
echo 警告:审查在提交$storedhead时运行,但当前HEAD为$currenthead
fi
如果过期,提示:审查结果已过期。是否重新运行审查?(y/n)
4. 按安全性分类发现
从JSON解析发现结果并按fix_safety字段分类:
安全修复(自动应用):
- - unusedimport - 未使用的导入
- todocomment - 过时的TODO/FIXME注释
- deadcodeobvious - 明显不可达的代码
- verbosecomment - 过于冗长的LLM风格注释
- redundanttype - 冗余的类型注解
风险修复(需要确认):
- - testrefactor - 测试结构更改
- abstractionchange - 类/函数提取
- coderemoval - 删除功能性代码
- mockboundary - 测试mock作用域更改
- logic_change - 任何行为修改
5. 应用安全修复
如果使用--dry-run:
markdown
安全修复(将自动应用)
| 文件 | 行号 | 类型 | 描述 |
|---|
| src/api.py | 15 | unusedimport | 移除from typing import List |
| src/models.py |
42 | verbosecomment | 移除23行文档字符串 |
...
否则,使用Task工具按类别生成并行代理:
Task: 应用类别{category}的安全修复
文件:[该类别中有发现的文件列表]
说明:应用每个修复,保留周围代码。报告每个修复的成功/失败。
并行处理的类别:
- - style - 注释、格式
- dead-code - 导入、不可达代码
- tests - 测试相关的安全修复
- abstraction - 安全重构
6. 处理风险修复
对每个风险修复,交互式提示:
[src/services/auth.py:156] 删除看似未使用的authenticate_legacy()方法?
此方法在代码库中没有调用者,但可能被外部使用。
(y)是 / (n)否 / (s)跳过所有风险修复:
跟踪用户选择:
- - y - 应用此修复
- n - 跳过此修复
- s - 跳过所有剩余风险修复
7. 修复后验证
检测项目类型并运行相应的linter:
Python:
bash
检查是否存在ruff配置
if [ -f pyproject.toml ] || [ -f ruff.toml ]; then
ruff check --fix .
ruff format .
fi
检查是否存在mypy配置
if [ -f pyproject.toml ] || [ -f mypy.ini ]; then
mypy .
fi
TypeScript/JavaScript:
bash
检查eslint
if [ -f eslint.config.js ] || [ -f .eslintrc.json ]; then
npx eslint --fix .
fi
检查TypeScript
if [ -f tsconfig.json ]; then
npx tsc --noEmit
fi
Go:
bash
if [ -f go.mod ]; then
go vet ./...
go build ./...
fi
8. 运行测试
bash
Python
if [ -f pyproject.toml ] || [ -f pytest.ini ]; then
pytest
fi
JavaScript/TypeScript
if [ -f package.json ]; then
npm test 2>/dev/null || yarn test 2>/dev/null || true
fi
Go
if [ -f go.mod ]; then
go test ./...
fi
9. 报告结果
markdown
修复摘要
已应用的修复
- - [x] src/api.py:15 - 移除了未使用的导入List
- [x] src/models.py:42-64 - 移除了冗长的文档字符串
- [x] src/auth.py:156-189 - 移除了死方法(用户确认)
跳过的修复
- - [ ] src/services/cache.py:23 - 用户拒绝了风险修复
- [ ] tests/test_api.py:45 - 跳过了测试重构
验证结果
- - Linter:通过
- 类型检查:通过
- 测试:通过(42通过,0失败)
差异摘要
bash
git diff --stat
清理
成功完成时(所有验证通过):
bash
rm .beagle/llm-artifacts-review.json
如果任何验证失败,保留文件并报告:
审查文件已保留在.beagle/llm-artifacts-review.json
修复问题后重新运行,或使用以下命令恢复:git stash pop
示例
bash
预览所有修复但不应用
/beagle-core:fix-llm-artifacts --dry-run
仅修复死代码问题
/beagle-core:fix-llm-artifacts --category dead-code
全代码库扫描和修复
/beagle-core:fix-llm-artifacts --all
仅修复样式问题,先预览
/beagle-core:fix-llm-artifacts --category style --dry-run