Skip to content
A flat, simple 8-bit icon shows two rectangles side by side, each resembling a sheet of paper. Colorful lines highlight differences: some lines are red for deleted content, green for added content, and gray for unchanged content. The image uses only five colors, has no text, people, background, shadows, or 3D effects, and measures 128 by 128 pixels.

Diff

In GenAIScript, the system.diff utility generates concise file diffs for efficient comparison and updates. This is particularly useful for version control or making precise changes within files. Learn how to create these diffs and best practices for interpreting them.

  • Diffs emphasize only the modified lines.
  • Retains minimal unmodified lines for context.
  • Uses an intuitive syntax tailored for large files with small changes.
  • Existing lines: Start with their original line number.
  • Deleted lines: Begin with - followed by the line number.
  • Added lines: Prefixed with + (no line number).
  • Deleted lines must exist, while added lines should be new.
  • Preserve indentation and focus on minimal unmodified lines.

Below is an example of the diff format:

[10] const oldValue = 42;
[11] const removed = 'This line was removed';
const added = 'This line was newly added';
[12] const unchanged = 'This line remains the same';
  1. Limit the surrounding unmodified lines to 2 lines maximum.
  2. Omit unchanged files or identical lines.
  3. Focus on concise changes for efficiency.

When generating diffs within your script, use system.diff for streamlined comparisons. Below is an example:

system({
title: "Generate concise diffs",
});
export default function (ctx) {
const { $ } = ctx;
$`## DIFF file format`;
}

For more details on system.diff, refer to the online documentation.