AI.Tools.File.Edit.OMFG (fnord v0.8.83)

View Source

!@#$%^&*()_+ agents and their %$#@ing parameter shenanigans.

Goddamn Calling Patterns This Handles

The "Patch" Shenanigans

  • {"patch": "some instruction"} → converts to proper instructions format
  • {"changes": [{"patch": "..."}]} → normalizes patch params within changes

The "Insert After/Before" Madness

  • {"insert_after": "anchor", "content": "new stuff"} → natural language instructions
  • {"insert_before": "anchor", "content": "new stuff"} → natural language instructions
  • Uses pattern field as anchor if provided, otherwise "the specified location"

The "Context + Pattern" Confusion

  • {"context": "...", "pattern": "old", "content": "new"} → exact string matching
  • {"pattern": "find this", "replacement": "replace with"} → old_string/new_string
  • {"pattern": "modify this"} → natural language instruction when no replacement

The "Diff-Style Patch" Nightmare

  • Parses *** Begin Patch / @@ / --- / +++ format patches
  • Extracts meaningful + and - lines into "Add:" / "Remove:" instructions
  • Falls back to using entire diff as instruction if parsing fails

Multiple Shenanigans Simultaneously

  • Handles agents that use multiple insane patterns in one request
  • Preserves unknown parameters for debugging (doesn't break on mystery params)
  • Processes top-level patch + changes array without losing data

Summary

Functions

Normalize agent parameter chaos into something resembling sanity.

Functions

normalize_agent_chaos(args)

@spec normalize_agent_chaos(map()) ::
  {:ok, map()} | {:error, String.t()} | AI.Tools.args_error()

Normalize agent parameter chaos into something resembling sanity.

Takes whatever creative parameter combinations agents dream up and attempts to convert them into the expected format for the file edit tool.

Returns {:ok, normalized_args} or {:error, reason} if the shenanigans are too creative even for us to handle.