V — 97 Operations for AI Agents
This page is the canonical reference an AI coding agent uses to refactor, query, and analyze V code through the act MCP server. 97 operations available: 23 refactor, 18 query, 42 analysis, 14 verification. Each operation is callable from Claude Code, Cursor, Codex, OpenCode, or any MCP-compatible agent host. Click any operation for a stable anchor link suitable for citation.
Worked V examples
act101 parses V with the tree-sitter grammar and edits expressions, control flow, and top-level declarations as syntax nodes, so a rewritten signature or an interpolated string lands on the exact construct it targets. It can convert a function's return type to Option, writing ?T so the possibility of failure is explicit in the signature. It can convert string concatenation to V's $ interpolation, folding 'Hello, ' + name + '!' into a single literal. It can add the mut keyword to a := short variable declaration, since V variables are immutable by default, and convert a match expression back into an if/else if/else chain, each branch keeping its body. It can also list a file's declarations as a skeleton, normalizing V's module and struct keywords onto act101's shared namespace and class kinds. Each example below is the verbatim output of the command shown, run against the file shown. Query outputs are pretty-printed with the timing block omitted.
Convert a return type to Option
user.v's get_user returns a bare string, with no way to signal in the signature that lookup can fail.
$ act refactor-lang convert_to_option_v --file user.v --params '{"line":1,"column":1,"symbol":"get_user"}'
Before
fn get_user(id int) string {
return 'user_$id'
}
After
fn get_user(id int) ?string {
return 'user_$id'
}
The return type becomes ?string; the body is unchanged.
Convert string concatenation to interpolation
main.v builds a greeting with +, joining three pieces into one string.
$ act refactor-lang convert_string_concatenation_to_interpolation_v --file main.v --params '{"line":1,"column":1,"symbol":"msg"}'
Before
msg := 'Hello, ' + name + '!'
After
msg := 'Hello, $name!'
'Hello, ' + name + '!' becomes 'Hello, $name!'; V's $name interpolation carries the variable into the literal.
Add the mut keyword to a variable
counter.v's main declares count with := and passes it to println.
$ act refactor-lang add_mutable_v --file counter.v --params '{"line":2,"column":2,"symbol":"count"}'
Before
fn main() {
count := 0
println(count)
}
After
fn main() {
mut count := 0
println(count)
}
count := 0 becomes mut count := 0; the rest of main is untouched.
Convert a match expression to an if-else chain
status.v matches code against 0 and 1, with an else arm for anything else, returning 'success', 'failure', or 'unknown'.
$ act refactor-lang convert_match_to_if_else_v --file status.v --params '{"line":1,"column":1,"symbol":"code"}'
Before
match code {
0 { return 'success' }
1 { return 'failure' }
else { return 'unknown' }
}
After
if code == 0 {
return 'success'
} else if code == 1 {
return 'failure'
} else {
return 'unknown'
}
The match becomes if code == 0 { ... } else if code == 1 { ... } else { ... }, each branch keeping its original return value.
Query the file's structure as a skeleton
inventory.v declares the inventory module, an Item struct, and two functions, total_value and find_item, that operate on a slice of items.
$ act query skeleton inventory.v
Before
module inventory
pub struct Item {
name string
price f64
stock int
}
pub fn total_value(items []Item) f64 {
mut sum := 0.0
for item in items {
sum += item.price * f64(item.stock)
}
return sum
}
pub fn find_item(items []Item, name string) ?Item {
for item in items {
if item.name == name {
return item
}
}
return none
}
Output
{
"type": "Skeleton",
"declarations": [
{
"kind": "namespace",
"name": "inventory",
"range": {
"start": {
"file": "inventory.v",
"line": 1,
"column": 1,
"byte_offset": 0
},
"end": {
"file": "inventory.v",
"line": 1,
"column": 17,
"byte_offset": 16
}
},
"name_range": {
"start": {
"file": "inventory.v",
"line": 1,
"column": 8,
"byte_offset": 7
},
"end": {
"file": "inventory.v",
"line": 1,
"column": 17,
"byte_offset": 16
}
}
},
{
"kind": "class",
"name": "Item",
"range": {
"start": {
"file": "inventory.v",
"line": 3,
"column": 1,
"byte_offset": 18
},
"end": {
"file": "inventory.v",
"line": 7,
"column": 2,
"byte_offset": 73
}
},
"name_range": {
"start": {
"file": "inventory.v",
"line": 3,
"column": 12,
"byte_offset": 29
},
"end": {
"file": "inventory.v",
"line": 3,
"column": 16,
"byte_offset": 33
}
}
},
{
"kind": "function",
"name": "total_value",
"range": {
"start": {
"file": "inventory.v",
"line": 9,
"column": 1,
"byte_offset": 75
},
"end": {
"file": "inventory.v",
"line": 15,
"column": 2,
"byte_offset": 205
}
},
"name_range": {
"start": {
"file": "inventory.v",
"line": 9,
"column": 8,
"byte_offset": 82
},
"end": {
"file": "inventory.v",
"line": 9,
"column": 19,
"byte_offset": 93
}
}
},
{
"kind": "function",
"name": "find_item",
"range": {
"start": {
"file": "inventory.v",
"line": 17,
"column": 1,
"byte_offset": 207
},
"end": {
"file": "inventory.v",
"line": 24,
"column": 2,
"byte_offset": 341
}
},
"name_range": {
"start": {
"file": "inventory.v",
"line": 17,
"column": 8,
"byte_offset": 214
},
"end": {
"file": "inventory.v",
"line": 17,
"column": 17,
"byte_offset": 223
}
}
}
]
}
The module surfaces as kind namespace and the struct as kind class: act101 normalizes declaration kinds across languages. total_value and find_item both surface as kind function, each with its own name range separate from its full range.
Query
18 query tools, the same on every supported language. Descriptions live in the shared reference: /docs/query-tools.
callers control_flow data_flow definition diagnostics effect_closure effect_summary fix_auto get_type graph import_organize interface mutations references repo_outline skeleton symbols symbols_batch
Refactor
| Operation | Description |
|---|---|
add-mutable-v |
Add mut modifier to V short variable declaration |
add-result-propagation-v |
Convert explicit error check to ? operator |
convert-match-to-if-else-v |
Convert match expression to if-else chain |
convert-string-concatenation-to-interpolation-v |
Convert string concatenation to interpolation |
convert-to-match-expression-v |
Convert if-else chain to match expression |
convert-to-option-v |
Wrap function return type in ? for optional |
extract-constant-v |
Extract an integer literal to a named constant in V |
extract_function |
Extract a code selection into a new function — automatically infers parameters, return types, and inserts the call site. Use instead of manually cutting/pasting code. Works without LSP; LSP improves type inference. Params: file (string), new_name (string), start_line (u32), start_column (u32), end_line (u32), end_column (u32) [, preview (bool), receipt (bool)] |
extract_variable |
Extract an expression into a named variable — inserts the declaration and replaces the expression with the variable name. Works without LSP. Params: file (string), new_name (string), start_line (u32), start_column (u32), end_line (u32), end_column (u32) [, preview (bool)] |
generate-documentation-comment-v |
Generate a documentation comment for a V function or struct |
generate-enum-from-variants-v |
Generate a V enum definition from a list of variants |
generate-enum-match-arms-v |
Fill in match arms for a V enum match expression |
generate-match-expression-v |
Insert a match expression template after the target line |
generate-struct-defaults-v |
Generate a new() constructor for a V struct |
inline |
Inline a variable, function, or method — replace every usage with its definition body, then remove the original. The inverse of extract. Works without LSP (single-file); LSP enables cross-file inlining. Params: file (string), symbol (string) [, line (u32), preview (bool), receipt (bool)] |
insert_body |
Replace a function's implementation body with new code. AST-validated — rejects if the result has parse errors, so you can't accidentally break syntax. Use instead of manual text editing for function rewrites. Params: file (string), symbol (string), code (string) [, commit (bool)] |
move_symbol |
Move a function, class, or type to a different file and automatically update all imports across the codebase. Use instead of manually cut/paste + fixing imports. Works without LSP (single-file); LSP enables cross-file import updates. Params: file (string), symbol (string), destination (string) [, preview (bool), receipt (bool)] |
organize-imports-v |
Sort V import statements alphabetically and remove duplicates |
recipe_run |
Run a codemod recipe: declarative match → transform → optional verify across modeled grammars. Preview lists matches; apply writes with optional E7 receipts and all-or-nothing rollback. Returns a per-site report. |
remove-unused-parameter-v |
Remove an unused parameter from a V function signature |
remove-unused-variable-v |
Remove an unused variable declaration in V |
rename |
Rename a symbol and automatically update ALL references across the codebase. Safer and faster than find-and-replace — AST-aware, won't rename strings or comments. Works without LSP (single-file); LSP enables cross-file renames. Params: file (string), old_name (string), new_name (string) [, line (u32), column (u32), preview (bool), receipt (bool)] |
simplify-boolean-comparison-v |
Simplify boolean comparisons in V (x == true → x) |
Analysis
42 analysis tools, the same on every supported language. Descriptions live in the shared reference: /docs/analysis-tools.
analyze_api_diff analyze_chokepoints analyze_clones analyze_clusters analyze_cohesion analyze_conformance analyze_coupling analyze_cycle_risk analyze_cycles analyze_dead_code analyze_depth analyze_entry_points analyze_export analyze_extraction analyze_fan_balance analyze_features analyze_hotspots analyze_impact analyze_inconsistencies analyze_inheritance analyze_interface_bloat analyze_interfaces analyze_layers analyze_orphan_types analyze_patterns analyze_platform_deps analyze_readiness analyze_roles analyze_seams analyze_stability analyze_surface analyze_test_gaps analyze_thickness analyze_type_completeness churn_hotspots co_change_clusters coverage_overlay ownership_map profile_overlay simulate split_module trace_overlay
Verify
14 verify tools, the same on every supported language. Descriptions live in the shared reference: /docs/verification.
bisect_regression gate generate_test_harness scan secret_surface summarize_pr taint_flow unsafe_surface verify_behavioral_equivalence verify_contract_preserved verify_diff_semantics verify_port_parity verify_side_effects verify_test_impact