TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Effectful-Tech/clanka/llms.txt
Use this file to discover all available pages before exploring further.
ApplyPatch module provides the applyPatch tool that Clanka agents call to modify files. It accepts two patch formats — standard git/unified diffs and the wrapped apply_patch format — and validates every hunk against the current file contents before writing anything to disk.
applyPatch(patchText)
Agents call this function from within their JavaScript sandbox:
A patch string in one of the two supported formats (git/unified diff or wrapped
apply_patch). Heredoc syntax (cat <<'EOF' … EOF) is automatically stripped before parsing.A success message listing every file that was modified, for example:Status letters follow git conventions:
M for modified, A for added, D for deleted, R for renamed/moved.Supported patch formats
Git / unified diff
The standard format produced bygit diff or diff -u. Each file section starts with diff --git, ---, and +++ headers.
rename from / rename to headers or by supplying different --- and +++ paths.
Wrapped apply_patch format
A custom envelope used by agents that prefer explicit file directives:
| Directive | Effect |
|---|---|
*** Add File: <path> | Create a new file with the lines that follow (prefixed +). |
*** Delete File: <path> | Remove the file entirely. |
*** Update File: <path> | Apply hunks to an existing file. |
*** Move to: <newpath> | Rename the file after applying hunks (placed after *** Update File:). |
The wrapped format supports multiple file sections in one patch block, unlike the single-file
parseWrapped helper used internally.Rename and move support
Files can be moved or renamed as part of a patch. In git diff format userename from / rename to headers or different ---/+++ paths. In the wrapped format add *** Move to: <newpath> immediately after *** Update File: <path>.
The parsed result carries the destination in the movePath field of a FilePatch:
Low-level API
These exports are available for tooling or testing outside of an agent context.parsePatch(input)
Parse a patch string into an array of FilePatch objects without touching the filesystem.
A patch string in either supported format. Whitespace normalisation and heredoc stripping are applied automatically.
An ordered list of file operations to apply. Throws
Error if the patch is empty, malformed, or contains no hunks.patchChunks(file, input, chunks)
Apply a pre-parsed list of Chunk objects to a file’s string content and return the updated content. Used internally by parsePatch and exposed for testing.
The file path, used only in error messages when a hunk cannot be located.
The current file content as a string.
The parsed hunks to apply.
The updated file content. Line endings are preserved (CRLF files remain CRLF).