# AI Refactoring Debug

> AI-powered refactoring and debugging -- OpenRewrite, AI log analysis, root cause analysis, Sentry Seer, error tracking, and migration automation.

- Skill: `leolin990405/ai-refactoring-debug` (Agent Skill)
- Install (CLI): `npx get-skill add leolin990405/ai-refactoring-debug`
- Raw SKILL.md: https://api.skillmd.com/api/skills/leolin990405/ai-refactoring-debug/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: LeoLin990405 (https://skillmd.com/u/leolin990405)
- Updated: 2026-11-11
- Page: https://skillmd.com/skills/leolin990405/ai-refactoring-debug

---


# AI Refactoring & Debugging

## AI Refactoring

### OpenRewrite (Deterministic)

Large-scale automated refactoring using Lossless Semantic Trees.

**Gradle**:
```groovy
plugins { id("org.openrewrite.rewrite") version "7.x.x" }
rewrite { activeRecipe("org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_4") }
```

**Maven**:
```xml
<plugin>
  <groupId>org.openrewrite.maven</groupId>
  <artifactId>rewrite-maven-plugin</artifactId>
  <configuration>
    <activeRecipes>
      <recipe>org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_4</recipe>
    </activeRecipes>
  </configuration>
</plugin>
```

**Custom Recipe (YAML)**:
```yaml
type: specs.openrewrite.org/v1beta/recipe
name: com.mycompany.UpgradeLibs
recipeList:
  - org.openrewrite.java.dependencies.ChangeDependency:
      oldGroupId: com.mycompany
      oldArtifactId: legacy-utils
      newGroupId: com.mycompany
      newArtifactId: modern-utils
      newVersion: 2.x
```

### AI-Assisted Patterns

| Pattern | Approach |
|---------|----------|
| Extract method | AI identifies long functions, suggests extraction |
| Dead code removal | AI traces call graphs to find unused code |
| Dependency upgrades | OpenRewrite recipes for deterministic migration |
| Language migration | AI translates patterns (Java → Kotlin) |
| API modernization | AI identifies deprecated patterns |

## AI Debugging

### Error Tracking Tools

| Tool | Key AI Feature |
|------|---------------|
| **Sentry Seer** | Autonomous diagnosis from traces + commit history |
| **Datadog Bits AI** | Correlates metrics, logs, traces |
| **Rollbar** | AI-powered error grouping |

### AI Log Analysis

Key metrics:
- **70-90%** alert noise reduction via intelligent clustering
- **95%+** anomaly detection accuracy (Isolation Forest)
- **40-60%** MTTR reduction via dependency graph analysis

### CI Integration for AI Debugging
```yaml
name: AI Error Analysis
on:
  workflow_run:
    workflows: ["Tests"]
    types: [completed]
jobs:
  analyze:
    if: failure()
    steps:
      - run: gh run view $RUN_ID --log-failed > logs.txt
      - name: AI Root Cause Analysis
        run: |
          # Feed logs to AI for analysis
          # Post as PR comment
```

### Debugging Techniques

1. **NLP similarity** — group errors by comparing stack traces
2. **Transaction tracing** — follow paths across microservices
3. **Service dependency graphs** — find breaking points
4. **Flaky test detection** — AI isolates false positives

## AI Documentation

| Tool | Purpose |
|------|---------|
| DocuWriter.ai | Code docs, Swagger, UML |
| Mintlify | API docs, developer portals |
| Swimm | Code-coupled auto-updating docs |
| Sourcery | Docstrings + optimization |

### Changelog Automation
```bash
git-cliff --output CHANGELOG.md       # Rule-based
changeish generate                     # AI-powered (Ollama)
```

## Best Practices

1. **Deterministic for migrations** (OpenRewrite), **AI for creative refactoring**
2. Combine error tracking with code review (link errors to PRs)
3. AI for initial triage, human for complex architecture issues
4. Structured logging (correlation IDs, spans) enables better AI analysis
5. Teams with AI refactoring achieve **3x faster modernization**

## Sources

- [OpenRewrite](https://docs.openrewrite.org/)
- [Sentry Seer](https://sentry.io/)
- [AI Log Analysis](https://signoz.io/guides/ai-log-analysis/)

