{"uid":"cap_GaHO4Q2ai2xj858m-7wrz","slug":"code-refactor-with-diff-and-rationale-5ab9aaaf","name":"Code Refactor with Diff and Rationale","description":"Refactor code while preserving behavior. Returns diff + rationale.","url":"https://dev-5090-box.tailfb4c1f.ts.net/v1/coder/refactor?utm_source=zero.xyz","method":"POST","headers":{},"bodySchema":{"type":"object","properties":{"usage":{"type":"object"},"choices":{"type":"array"}}},"responseSchema":null,"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.03","displayCostAsset":"USDC","priceDynamic":false,"priceHint":null,"priceStatus":"priced","priceSource":"probe","requiresHandshake":false,"reviewCount":0,"rating":{"score":"0.00","successRate":"0.00","reviews":0,"stars":null,"state":"unrated"},"availabilityStatus":"unknown","priceObserved":null,"sessionDeposit":null,"pricing":{"kind":"static","summary":"$0.03/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.03","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.03","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_nhUQqBl6BzhcvhQaMp1hZ","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.03","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Refactors a code snippet while preserving its behavior, returning a diff and a written rationale explaining the changes.","exampleAgentPrompt":"Refactor this Python function to be cleaner and more Pythonic — keep the behavior exactly the same and give me a diff plus a rationale explaining each change: def add(a, b): result = a + b; return result","exampleUseCases":[{"title":"Legacy function cleanup","prompt":"This JavaScript function works but it's a mess — can you refactor it to use modern ES6+ patterns without breaking anything, and show me exactly what changed with a rationale?"},{"title":"Reduce code duplication","prompt":"I've got this Java class with a lot of repeated logic — refactor it to remove the duplication while keeping the behavior identical, and give me a diff with an explanation of why you made each change."},{"title":"Improve readability before code review","prompt":"Before I submit this PR, can you refactor this Python module to make it more readable and idiomatic, preserving all existing behavior? I need a diff and a written rationale to include in my PR description."}],"resultDescription":"Returns a diff showing exactly what lines changed and a written rationale explaining the reasoning behind each refactoring decision, while guaranteeing behavioral equivalence of the original code.","failureModes":["Code snippet is too large or complex for the model context window","Ambiguous or mixed-language snippets may produce incorrect diffs","If the code has side effects that are hard to detect, behavioral preservation cannot be fully guaranteed","Malformed or unparseable code may cause an empty or incorrect diff","Model may occasionally hallucinate changes that subtly alter behavior in edge cases"],"whenToPreferThis":"Choose this endpoint when you need both a concrete diff and a human-readable rationale explaining refactoring decisions — not just a rewritten version. It's particularly useful for preparing code review materials, documenting technical debt cleanup, or understanding why changes were made. Prefer it over a generic code completion endpoint when behavioral preservation and auditability are the priority.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-10-12T12:36:00.539Z","isFirstParty":false,"canonicalSlug":"code-refactor-with-diff-and-rationale-5ab9aaaf"}