fix(commands): use dynamic base branch and safe rollback in remove-ai-slops

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-04-01 18:21:00 -07:00
parent 51d9685571
commit 842434c81f
3 changed files with 30 additions and 9 deletions
+3
View File
@@ -12,6 +12,7 @@ declare module "bun:test" {
} }
export function describe(name: string, fn: () => void): void export function describe(name: string, fn: () => void): void
export function test(name: string, fn: () => void | Promise<void>): void
export function it(name: string, fn: () => void | Promise<void>): void export function it(name: string, fn: () => void | Promise<void>): void
export function beforeEach(fn: () => void | Promise<void>): void export function beforeEach(fn: () => void | Promise<void>): void
export function afterEach(fn: () => void | Promise<void>): void export function afterEach(fn: () => void | Promise<void>): void
@@ -28,6 +29,8 @@ declare module "bun:test" {
interface Matchers { interface Matchers {
toBe(expected: unknown): void toBe(expected: unknown): void
toBeDefined(): void
toBeUndefined(): void
toBeNull(): void toBeNull(): void
toEqual(expected: unknown): void toEqual(expected: unknown): void
toContain(expected: unknown): void toContain(expected: unknown): void
@@ -1,3 +1,5 @@
/// <reference path="../../../bun-test.d.ts" />
import { afterEach, beforeEach, describe, test, expect } from "bun:test" import { afterEach, beforeEach, describe, test, expect } from "bun:test"
import { loadBuiltinCommands } from "./commands" import { loadBuiltinCommands } from "./commands"
import { HANDOFF_TEMPLATE } from "./templates/handoff" import { HANDOFF_TEMPLATE } from "./templates/handoff"
@@ -170,6 +172,15 @@ describe("REMOVE_AI_SLOPS_TEMPLATE", () => {
expect(REMOVE_AI_SLOPS_TEMPLATE).toContain("Safety Verification") expect(REMOVE_AI_SLOPS_TEMPLATE).toContain("Safety Verification")
expect(REMOVE_AI_SLOPS_TEMPLATE).toContain("Behavior Preservation") expect(REMOVE_AI_SLOPS_TEMPLATE).toContain("Behavior Preservation")
}) })
test("should detect the base branch dynamically instead of hardcoding main", () => {
//#given - the template string
//#when / #then
expect(REMOVE_AI_SLOPS_TEMPLATE).toContain("git symbolic-ref refs/remotes/origin/HEAD")
expect(REMOVE_AI_SLOPS_TEMPLATE).toContain('git merge-base "$BASE_BRANCH" HEAD')
expect(REMOVE_AI_SLOPS_TEMPLATE).not.toContain("git merge-base main HEAD")
})
}) })
describe("HANDOFF_TEMPLATE", () => { describe("HANDOFF_TEMPLATE", () => {
@@ -17,20 +17,27 @@ You are a senior code quality engineer specialized in identifying and removing A
## Process ## Process
### Phase 1: Identify Changed Files ### Phase 1: Identify Changed Files
Execute the following command to get all changed files in the current branch: Detect the repository base branch dynamically, then get all changed files in the current branch:
\\\`\\\`\\\`bash \`\`\`bash
git diff $(git merge-base main HEAD)..HEAD --name-only BASE_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@' || echo "main")
\\\`\\\`\\\` git diff $(git merge-base "$BASE_BRANCH" HEAD)..HEAD --name-only
\`\`\`
If \`git symbolic-ref refs/remotes/origin/HEAD\` is unavailable, detect the base branch at runtime using the repo's configured remote default branch. Only fall back to \`main\` as a last resort.
### Phase 2: Parallel AI Slop Removal ### Phase 2: Parallel AI Slop Removal
For each changed file, spawn an agent in parallel using the Task tool with the ai-slop-remover skill: For each changed file, spawn an agent in parallel using the Task tool with the ai-slop-remover skill:
\\\`\\\`\\\` \`\`\`
task(category="quick", load_skills=["ai-slop-remover"], run_in_background=true, description="Remove AI slops from {filename}", prompt="Remove AI slops from: {file_path}") task(category="quick", load_skills=["ai-slop-remover"], run_in_background=true, description="Remove AI slops from {filename}", prompt="Remove AI slops from: {file_path}")
\\\`\\\`\\\` \`\`\`
**CRITICAL**: Launch ALL agents in a SINGLE message with multiple Task tool calls for maximum parallelism. **CRITICAL**: Launch ALL agents in a SINGLE message with multiple Task tool calls for maximum parallelism.
Before running ai-slop-remover on each file, save a file-specific rollback artifact that captures only the delta introduced by the slop-removal pass. Use a safe pattern such as generating a per-file patch and reverse-applying it if review fails.
Do NOT use \`git checkout -- {file_path}\` or any rollback that discards pre-existing branch changes in the file.
### Phase 3: Critical Review ### Phase 3: Critical Review
After all ai-slop-remover agents complete, perform a critical review with the following checklist: After all ai-slop-remover agents complete, perform a critical review with the following checklist:
@@ -56,14 +63,14 @@ After all ai-slop-remover agents complete, perform a critical review with the fo
If any issues are found during critical review: If any issues are found during critical review:
1. Identify the specific problem 1. Identify the specific problem
2. Explain why it's a problem 2. Explain why it's a problem
3. Use git checkout to revert the changes from ai-slop-remover 3. Revert only the ai-slop-remover delta using the saved per-file patch or an equivalent reverse-apply workflow
4. If remaining ai-slops are found after reverting, remove them by editing the file yourself - with parallel tool calls, per-file 4. If remaining ai-slops are found after reverting, remove them by editing the file yourself - with parallel tool calls, per-file
5. Verify the fix doesn't introduce new issues 5. Verify the fix doesn't introduce new issues
## Output Format ## Output Format
### Summary Report ### Summary Report
\\\`\\\`\\\` \`\`\`
## AI Slop Removal Summary ## AI Slop Removal Summary
### Files Processed ### Files Processed
@@ -80,7 +87,7 @@ If any issues are found during critical review:
### Final Status ### Final Status
[CLEAN / ISSUES FIXED / REQUIRES ATTENTION] [CLEAN / ISSUES FIXED / REQUIRES ATTENTION]
\\\`\\\`\\\` \`\`\`
## Quality Assurance ## Quality Assurance
- NEVER remove code that serves a functional purpose - NEVER remove code that serves a functional purpose