Use when (1) user provides a code snippet and asks to convert it from one programming language to another (e.g., Python to JavaScript, Java to Kotlin). (2) u...
This skill converts code snippets and data structures between programming languages, formats, and conventions. It handles syntactic transformation (language-to-language), representational transformation (JSON to TypeScript types), and stylistic transformation (older patterns to newer ones). It does NOT just copy-paste — it applies semantic equivalence, meaning the output code must be functionally equivalent to the input.
Key responsibilities:
/convert-code-snippets --language#Language-to-language conversion. Converts code from source language to target language. Requires --from and --to flags:
text
--from python --to javascript
--from java --to kotlin
--from go --to rust
--from typescript --to python
Supported languages: Python, JavaScript, TypeScript, Java, Kotlin, Go, Rust, C++, C#, Swift, Ruby, PHP.
/convert-code-snippets --schema#Schema to code conversion. Converts a data schema (JSON Schema, OpenAPI, SQL schema) into typed code:
JSON Schema → TypeScript interfaces, Python dataclasses, Java classes, Go structsOpenAPI spec → client code (TypeScript, Python), server stubsSQL CREATE TABLE → ORM models (SQLAlchemy, TypeORM, Prisma)/convert-code-snippets --style#Code style transformation. Converts code between conventions:
callback-to-async — converts callback-based code to async/awaitclass-to-function — converts class-based OOP to functional stylecommonjs-to-esm — converts require() to import/ exportpython2-to-python3 — converts Python 2 print statements, unicode handlingjsx-to-tsx — converts JavaScript JSX to TypeScript TSX/convert-code-snippets --format#Data format conversion. Converts between structured data formats:
json-to-yaml, yaml-to-json, toml-to-jsoncsv-to-json, json-to-csv, tsv-to-csvxml-to-json, json-to-xmlFrom file extension:
text
.py → Python .js → JavaScript .java → Java
.ts → TypeScript .kt → Kotlin .go → Go
.rs → Rust .cpp → C++ .cs → C#
.swift → Swift .rb → Ruby .php → PHP
.tsx → TypeScript .jsx → JavaScript .json → JSON
.yaml → YAML .yml → YAML .toml → TOML
.csv → CSV .xml → XML .sql → SQL
From content (if extension ambiguous):
def , import , print( → Pythonfunction , const , let , => → JavaScriptpublic class , System.out. → Java: string, : number, interface → TypeScriptIf source or target is ambiguous, ask the user: "Cannot determine target language — please specify --from python --to javascript explicitly."
Read the source code as UTF-8 text. Use a parser if available for the source language:
ast module to parse into ASTesprima or babel parserFor languages without parser support, use structural pattern matching:
def name( or function name(class Name or class Name extendsimport or from or require(: Type or -> TypeExtract: function signatures, class definitions, imports, type annotations, comments.
Build a transformation map for the specific language pair. Common mappings:
Python → JavaScript:
text
def fn(x, y) → function fn(x, y) {
print(x) → console.log(x)
None → null
True / False → true / false
x if cond else y → cond ? x : y
with open(f) as f: → (async () => { const fs = require('fs'); ... })()
def __init__(self): → constructor() {
self.x → this.x
f"string {x}" → `string ${x}`
[x for x in lst] → lst.map(x => x)
Python → TypeScript: (above + type annotations)
text
int, float, str → number, number, string
List[int] → number[]
Dict[str, int] → Record<string, number>
Optional[int] → number | null
def fn() -> int → function fn(): number
Java → Kotlin:
text
System.out.println() → println()
public class → class (public is default)
String → String (kotlin.String)
final → val
void method() → fun method(): Unit
if (x == null) → if (x == null)
Callback → Async/Await:
text
// Before (callback style)
apiCall(arg, function(err, result) {
if (err) return handleError(err);
process(result);
});
// After (async/await)
try {
const result = await apiCall(arg);
process(result);
} catch (err) {
handleError(err);
}
CommonJS → ESM:
text
const fs = require('fs'); → import fs from 'fs';
const {a, b} = require('./module'); → import {a, b} from './module.js';
module.exports = {fn}; → export const fn = ...;
module.exports.fn = fn; → export function fn() {...}
Indentation:
--indent flag (default: 2 spaces for most languages)Semicolons:
; at end of statement (unless already present or line ends with {/ }); if presentQuotes:
Imports/exports:
For parsed languages, attempt to parse the output:
ast.parse(output) — if it fails, report the error with line numbereslint --no-eslintrc --parser-options {ecmaVersion: 2020} filename.js if availableIf no parser available, do structural validation:
{...}, brackets [...], parentheses (...)function not Function, const not CONST)If validation fails, report: "Converted code is invalid [target language]: error at line {N}: {detail}. Reverting to source format."
Return:
json
{
"source_language": "python",
"target_language": "javascript",
"lines_converted": 142,
"functions_mapped": 8,
"classes_mapped": 3,
"imports_mapped": 12,
"comments_preserved": 7,
"warnings": [
{"line": 42, "issue": "Python dict comprehension has no direct JS equivalent — converted to .map() but verify correctness"},
{"line": 87, "issue": "Decorator @property cannot be represented in ES5 — needs manual conversion"}
],
"approximate_functional_equivalence": "85%"
}
is vs JavaScript ===)System.out.println() must become console.log(), not just stay as-is)--schema mode — TypeScript/Java/Kotlin output must have types# self in Python → // self in JavaScript — remove or update)approximate_functional_equivalence percentage and list specific areas needing manual reviewlen() → JS .length, Python str() → JS String())--style mode, add a comment // Auto-converted from [source style] — verify correctness at the topCriterionMinimumIdealSyntax validityOutput parses without error in target languageOutput passes linter with no warningsSemantic equivalenceApproximate functional equivalence >= 70%>= 90% with manual review only for complex featuresStandard library mappingAll detected stdlib calls mapped to target equivalentVerified by running converted code against test casesType preservationType annotations preserved where possibleFull type inference in target languageComment preservationComments that document behavior preservedComments translated, not just copiedEdge case handlingHandles null, empty input gracefullyAll edge cases have explicit handling with test cases
A good output is syntactically valid in the target language, semantically equivalent to the source (with known gaps documented), and formatted according to the target language's conventions.
ScenarioBadGoodPython is to JSReplaces is with === literallyMaps is to === for primitives but warns about object identity differencelen(list) in PythonWrites len(list) in JS (not valid)Converts to list.length``def fn(a, b=None)Converts to function fn(a, b=null) (loses default intent)Adds if (b === undefined) b = null or uses default parameter b = nullPython f-stringConverts f"{x}" to "${x}" (wrong in non-template context)Detects f-string, converts to template literal `${x}`Java for loopConverts for (int i=0; i<n; i++) to for i in range(n): (Pythonic but not equivalent)Preserves index-based loop or maps to for i in range(n) with noteMissing importSilently drops import osMaps to const os = require('os') (Node) or reports "os module has no direct JS equivalent"Callback to asyncConverts only one level of callbacksRecursively converts nested callbacks to async/await, flattening the chainUnknown constructSkips the function entirelyIncludes function signature as comment: // function unknownFeature() — needs manual implementation