topos_compare_code
Compute AST tree-edit distance between two code snippets to detect clones or quantify refactor impact. Returns normalized similarity and edit operations.
Instructions
Compute the AST (tree-edit) distance between two source-code
strings.
Read-only and idempotent; parses both snippets in memory, never
writes or scores. Use for clone detection or to measure refactor
impact; the topos_assess_* tools already fold this in as an
anti-gaming check, so call it directly only for the raw number.
Returns a ComparisonResult: normalized_distance in [0, 1],
similarity (= 1 - it), raw_distance, an operations edit-count
map, and source_valid/target_valid (error set if either fails
to parse).
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"source_code": "<source_code>",
"target_code": "<target_code>"
},
"name": "topos_compare_code"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| language | No | python, rust, javascript, typescript, cpp, or go. | python |
| source_code | Yes | Baseline code. | |
| target_code | Yes | Proposed/target code. |