Use aic patch for deterministic symbol-aware edits that can be previewed before they are applied.
- Request schema:
docs/agent-tooling/schemas/patch-request.schema.json - Response schema:
docs/agent-tooling/schemas/patch-response.schema.json - Example project:
examples/e7/patch_protocol
- Author a patch document that satisfies
patch-request.schema.json. - Run preview first:
aic patch --preview examples/e7/patch_protocol/patches/valid_patch.json --project examples/e7/patch_protocol --json- Apply only after preview is clean:
aic patch --apply examples/e7/patch_protocol/patches/valid_patch.json --project examples/e7/patch_protocol --json- Re-run
aic check <project>after apply if the patch is part of a larger edit batch.
Required fields:
kind: "add_function"function.namefunction.return_typefunction.body
Optional fields:
target_fileafter_symbolfunction.params[]function.effects[]function.capabilities[]function.requiresfunction.ensures
Example:
{
"kind": "add_function",
"target_file": "src/main.aic",
"after_symbol": "handle_result",
"function": {
"name": "validate_port",
"params": [{ "name": "c", "ty": "Config" }],
"return_type": "Bool",
"body": "c.port >= 0"
}
}Required fields:
kind: "modify_match_arm"target_functionmatch_indexarm_patternnew_body
Optional fields:
target_file
Example:
{
"kind": "modify_match_arm",
"target_file": "src/main.aic",
"target_function": "handle_result",
"match_index": 0,
"arm_pattern": "Err(e)",
"new_body": "0 - e"
}Required fields:
kind: "add_field"target_structfield.namefield.ty
Optional fields:
target_file
Example:
{
"kind": "add_field",
"target_file": "src/main.aic",
"target_struct": "Config",
"field": {
"name": "timeout",
"ty": "Int"
}
}- Keep
target_fileproject-relative whenever possible. - Do not queue two operations against the same semantic target in one document. Overlaps are rejected deterministically.
- Keep operation ordering intentional.
operation_indexin conflicts maps directly to array position. - Treat preview output as the authoritative diff plan. Do not assume source spans yourself.
- Unknown fields are rejected by the parser.
Successful responses contain:
files_changed[]applied_edits[]previews[]
Path fields in patch responses are canonical machine paths:
- absolute
- symlink-resolved for existing prefixes
- separator-normalized to
/
Conflict responses contain:
conflicts[].operation_indexconflicts[].kindconflicts[].message- optional
conflicts[].file
Common conflict kinds:
document: patch JSON could not be read or parsedresolve_target: target file or symbol could not be resolvedplan: requested symbol/arm/field could not be plannedoverlap: two operations target the same semantic locationvalidate: patched source no longer parsesvalidate_semantics: patched source parses but fails frontend type/effect validationwrite_prepare: failed to stage temporary patch output before commitprecondition: source changed between planning and commit; apply aborted before writescommit: atomic commit/replace phase failed; rollback attempted automatically
previewnever mutates the workspace.applywrites only when every operation is valid.applyuses staged temp files plus atomic rename commit per target file.- Multi-file apply is transactional: precondition/prepare failures abort before commit and commit failures trigger deterministic rollback to the original workspace state.