mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-03 21:31:26 +00:00
@openclaw/diffs
Read-only diff viewer plugin for OpenClaw agents.
It gives agents one tool, diffs, that can:
- render a gateway-hosted diff view, a file (PNG or PDF), or both
- accept either arbitrary
beforeandaftertext or a unified patch
What Agents Get
The tool can return:
details.viewerUrl: a gateway URL that can be opened in the canvasdetails.filePath: a local rendered artifact path when file rendering is requesteddetails.fileFormat: the rendered file format (pngorpdf)details.format: compatibility alias fordetails.fileFormat
This means an agent can:
- call
diffswithmode=view, then passdetails.viewerUrltocanvas present - call
diffswithmode=file(optionallyfileFormat=pdf), then send the file through the normalmessagetool usingpathorfilePath - call
diffswithmode=bothwhen it wants both outputs
Tool Inputs
Before and after:
{
"before": "# Hello\n\nOne",
"after": "# Hello\n\nTwo",
"path": "docs/example.md",
"mode": "view"
}
Patch:
{
"patch": "diff --git a/src/example.ts b/src/example.ts\n--- a/src/example.ts\n+++ b/src/example.ts\n@@ -1 +1 @@\n-const x = 1;\n+const x = 2;\n",
"mode": "both"
}
Useful options:
mode:view,file, orbothlayout:unifiedorsplittheme:lightordark(default:dark)fileFormat:pngorpdf(default:png)fileQuality:standard,hq, orprintfileScale: device scale override (1-4)fileMaxWidth: max width override in CSS pixels (640-2400)expandUnchanged: expand unchanged sectionspath: display name for before and after inputtitle: explicit viewer titlettlSeconds: artifact lifetimebaseUrl: override the gateway base URL used in the returned viewer link
Plugin Defaults
Set plugin-wide defaults in ~/.openclaw/openclaw.json:
{
plugins: {
entries: {
diffs: {
enabled: true,
config: {
defaults: {
fontFamily: "Fira Code",
fontSize: 15,
lineSpacing: 1.6,
layout: "unified",
showLineNumbers: true,
diffIndicators: "bars",
wordWrap: true,
background: true,
theme: "dark",
fileFormat: "png",
fileQuality: "standard",
fileScale: 2,
fileMaxWidth: 960,
mode: "both",
},
},
},
},
},
}
Explicit tool parameters still win over these defaults.
Compatibility note: defaults.format is accepted as an alias for defaults.fileFormat.
Example Agent Prompts
Open in canvas:
Use the `diffs` tool in `view` mode for this before and after content, then open the returned viewer URL in the canvas.
Path: docs/example.md
Before:
# Hello
This is version one.
After:
# Hello
This is version two.
Render a file (PNG or PDF):
Use the `diffs` tool in `file` mode for this before and after input. After it returns `details.filePath`, use the `message` tool with `path` or `filePath` to send me the rendered diff image.
Path: README.md
Before:
OpenClaw supports plugins.
After:
OpenClaw supports plugins and hosted diff views.
Do both:
Use the `diffs` tool in `both` mode for this diff. Open the viewer in the canvas and then send the rendered image by passing `details.filePath` to the `message` tool.
Path: src/demo.ts
Before:
const status = "old";
After:
const status = "new";
Patch input:
Use the `diffs` tool with this unified patch in `view` mode. After it returns the viewer URL, present it in the canvas.
diff --git a/src/example.ts b/src/example.ts
--- a/src/example.ts
+++ b/src/example.ts
@@ -1,3 +1,3 @@
export function add(a: number, b: number) {
- return a + b;
+ return a + b + 1;
}
Notes
- The viewer is hosted locally through the gateway under
/plugins/diffs/.... - Artifacts are ephemeral and stored in the local temp directory.
- PNG/PDF rendering requires a Chromium-compatible browser. Set
browser.executablePathif auto-detection is not enough. - If your delivery channel compresses images heavily (for example Telegram or WhatsApp), prefer
fileFormat: "pdf"to preserve readability. - Diff rendering is powered by Diffs.