{"uid":"cap_MAUE_WKArtvpg4AEuhQvi","slug":"code-refactor-with-diff-and-rationale-df8478c4","name":"Code Refactor with Diff and Rationale","description":"Refactor code while preserving behavior. Returns diff + rationale.","url":"https://linked-aimed-reproduced-changing.trycloudflare.com/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_dmP8TrtfpCp-8xe-c7EgI","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 unified diff and a written rationale explaining the changes.","exampleAgentPrompt":"Can you refactor this Python function to reduce nesting and improve readability — show me the diff and explain what you changed?\n\n```python\ndef process(data):\n    if data:\n        if data['active']:\n            for item in data['items']:\n                if item['valid']:\n                    print(item)\n```","exampleUseCases":[{"title":"Legacy function cleanup","prompt":"Refactor this legacy JavaScript function to use modern ES6+ syntax — keep the behavior identical and give me a diff plus an explanation of every change you made."},{"title":"Reduce code duplication","prompt":"This Python class has a lot of repeated logic across three methods. Can you refactor it to eliminate the duplication while keeping all the existing behavior, and show me exactly what changed?"},{"title":"Improve readability before PR","prompt":"I'm about to submit a PR for this Go function but the logic is hard to follow. Refactor it for clarity, return a diff I can review, and tell me why you made each change."}],"resultDescription":"Returns a unified diff showing exactly what lines changed, plus a written rationale explaining the motivation and reasoning behind each refactoring decision, while guaranteeing behavioral equivalence.","failureModes":["Malformed or empty code input may produce poor-quality or hallucinated refactors","Very large code snippets may be truncated due to context window limits","Non-standard or uncommon languages may yield lower-quality suggestions","Input schema mismatch (choices/usage fields) may cause unexpected behavior","The model may occasionally introduce subtle behavioral changes despite the behavior-preservation goal"],"whenToPreferThis":"Choose this endpoint when you need both a concrete code diff and a human-readable explanation of why changes were made — ideal for code review workflows, PR preparation, or teaching contexts. Prefer this over a generic chat completion when you need structured diff output with rationale. Use the security audit sibling for vulnerability-focused review, or the code review sibling for numbered correctness findings.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-10-12T18:38:22.563Z","isFirstParty":false,"canonicalSlug":"code-refactor-with-diff-and-rationale-df8478c4"}