mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-25 11:55:47 -06:00
508dd471b0
* feat(slack): render live session cards as the default Slack progress mode Slack streaming.mode default flips partial->progress. Progress mode renders one live Block Kit session card with a status header, narration, plan, activity, diff stat, and elapsed time; it is edited in place and finalized to success or error with an Open in OpenClaw button when gateway.publicOrigin is set. Final assistant text always delivers separately. The shared progress compositor gains a success-only additive per-turn diffStat mirroring the task ledger fold. resolveGatewayPublicOrigin is exported through the plugin SDK. The diffs viewer URL falls back to publicOrigin. The old rich/text progress render fork is deleted. Native task cards remain unchanged and opt-in. * chore(config): regenerate bundled channel config metadata * refactor(slack): keep session card state type internal * refactor(slack): split session-card and diff-stat owners under lint ceilings * refactor(channels): reuse diff-stat type from its owner module Import ChannelProgressDraftDiffStat from progress-draft-diffstat instead of redeclaring it in the compositor, resolving the all-exports deadcode scan. * chore(plugin-sdk): regenerate api baselines for channel barrels Baselines drifted after the rebase reconciled them against main; regenerate to match the branch's actual channel-message/channel-outbound surface. * fix(slack): drop a session card that cannot terminalize after final delivery If the final reply is delivered but the terminal card edit fails, the caller now clears the stale card instead of leaving it stuck in its Working state (mirrors the pre-card preview cleanup). Adds a transport-failure regression and corrects three tests that asserted the prior ignore-the-result behavior. Documents resolveGatewayPublicOrigin as a dependency-light runtime helper on the config-contracts SDK subpath, which previously described a type-only surface. Addresses ClawSweeper P2 (unfinalized card) and P1 (runtime SDK contract). * fix(slack): suppress default tool messages under the default progress card resolveChannelStreamingSuppressDefaultToolProgressMessages re-derived the stream mode from config with an "off" default, unlike its sibling resolvers which take a caller-resolved mode override. After this branch made progress the Slack default, a default-config channel turn saw mode "off" and left a stray "Using tool: X" plain message posting alongside the session card. Thread the caller-resolved mode through (compositor passes params.mode; Slack dispatch passes slackStreaming.mode), matching resolveChannelStreamingPreviewToolProgress. Retarget the progress-session-card delivery-trace golden at an EMPTY Slack config so it proves the real default path; the regenerated golden is byte-identical, confirming defaults now yield the clean card sequence (one card post, separate final text, one terminal update with the Open in OpenClaw button, no stray tool message). Switch the dispatch delivery-mode mock to the real resolver so the card tests exercise the true channel default (automatic), not a hand-rolled one. * chore(plugin-sdk): regenerate api baselines for the streaming mode param resolveChannelStreamingSuppressDefaultToolProgressMessages gained an optional mode override; the changed signature reflows the surface hash of every barrel that re-exports it, so regenerate the affected baselines. * chore(config): regenerate config baselines
233 lines
7.5 KiB
Markdown
233 lines
7.5 KiB
Markdown
# @openclaw/diffs
|
|
|
|
Read-only diff viewer plugin for **OpenClaw** agents.
|
|
|
|
## Install
|
|
|
|
```bash
|
|
openclaw plugins install @openclaw/diffs
|
|
```
|
|
|
|
Restart the Gateway after installing or updating the plugin.
|
|
|
|
It gives agents one tool, `diffs`, that can:
|
|
|
|
- render a gateway-hosted diff viewer for canvas use
|
|
- render the same diff to a file (PNG or PDF)
|
|
- accept either arbitrary `before` and `after` text or a unified patch
|
|
|
|
## What Agents Get
|
|
|
|
The tool can return:
|
|
|
|
- `details.changed`: `false` when before/after inputs are identical and no artifact was rendered; `true` for rendered results
|
|
- `details.viewerUrl`: a gateway URL that can be opened in the canvas
|
|
- `details.filePath`: a local rendered artifact path when file rendering is requested
|
|
- `details.fileFormat`: the rendered file format (`png` or `pdf`)
|
|
- `details.artifactId` and `details.expiresAt`: artifact identity and TTL metadata
|
|
- `details.context`: available routing metadata such as `agentId`, `sessionId`, `messageChannel`, and `agentAccountId`
|
|
|
|
When the plugin is enabled, it also ships a companion skill from `skills/` and prepends stable tool-usage guidance into system-prompt space via `before_prompt_build`. The hook uses `prependSystemContext`, so the guidance stays out of user-prompt space while still being available every turn.
|
|
|
|
This means an agent can:
|
|
|
|
- call `diffs` with `mode=view`, then pass `details.viewerUrl` to `canvas present`
|
|
- call `diffs` with `mode=file`, then send the file through the normal `message` tool using `path` or `filePath`
|
|
- call `diffs` with `mode=both` when it wants both outputs
|
|
|
|
## Tool Inputs
|
|
|
|
Before and after:
|
|
|
|
```json
|
|
{
|
|
"before": "# Hello\n\nOne",
|
|
"after": "# Hello\n\nTwo",
|
|
"path": "docs/example.md",
|
|
"mode": "view"
|
|
}
|
|
```
|
|
|
|
Patch:
|
|
|
|
```json
|
|
{
|
|
"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`, or `both`
|
|
Deprecated alias: `image` behaves like `file` and is still accepted for backward compatibility.
|
|
- `layout`: `unified` or `split`
|
|
- `theme`: `light` or `dark` (default: `dark`)
|
|
- `fileFormat`: `png` or `pdf` (default: `png`)
|
|
- `fileQuality`: `standard`, `hq`, or `print`
|
|
- `fileScale`: device scale override (`1`-`4`)
|
|
- `fileMaxWidth`: max width override in CSS pixels (`640`-`2400`)
|
|
- `expandUnchanged`: expand unchanged sections (per-call option only, not a plugin default key)
|
|
- `path`: display name for before and after input
|
|
- `lang`: language hint for before/after input; unknown values fall back to plain text
|
|
- Default syntax highlighting covers common source, config, and documentation languages. Install `diffs-language-pack` for the extended language catalog.
|
|
- `title`: explicit viewer title
|
|
- `ttlSeconds`: artifact lifetime for viewer and standalone file outputs
|
|
- `baseUrl`: override the gateway base URL used in the returned viewer link (origin or origin+base path only; no query/hash)
|
|
- `viewerBaseUrl` plugin config: persistent fallback used when a tool call omits `baseUrl`
|
|
|
|
Input safety limits:
|
|
|
|
- `before` and `after`: max 512 KiB each
|
|
- `patch`: max 2 MiB
|
|
- patch rendering cap: max 128 files / 120,000 lines
|
|
|
|
## Plugin Defaults
|
|
|
|
Set plugin-wide defaults in `~/.openclaw/openclaw.json`:
|
|
|
|
```json5
|
|
{
|
|
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",
|
|
ttlSeconds: 21600,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
```
|
|
|
|
Explicit tool parameters still win over these defaults.
|
|
|
|
## Docs
|
|
|
|
- https://docs.openclaw.ai/tools/diffs
|
|
|
|
## Package
|
|
|
|
- Plugin id: `diffs`
|
|
- Package: `@openclaw/diffs`
|
|
- Minimum OpenClaw host: `2026.4.30`
|
|
|
|
Security options:
|
|
|
|
- `security.allowRemoteViewer` (default `false`): allows non-loopback access to `/plugins/diffs/view/...` token URLs
|
|
- `viewerBaseUrl` (optional): persistent viewer-link origin/path fallback for shareable URLs
|
|
- `defaults.ttlSeconds` (default `1800`, max `21600`): default artifact lifetime for viewer and standalone file outputs
|
|
|
|
Example:
|
|
|
|
```json5
|
|
{
|
|
plugins: {
|
|
entries: {
|
|
diffs: {
|
|
enabled: true,
|
|
config: {
|
|
viewerBaseUrl: "https://gateway.example.com/openclaw",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
```
|
|
|
|
## Example Agent Prompts
|
|
|
|
Open in canvas:
|
|
|
|
```text
|
|
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):
|
|
|
|
```text
|
|
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 file.
|
|
|
|
Path: README.md
|
|
|
|
Before:
|
|
OpenClaw supports plugins.
|
|
|
|
After:
|
|
OpenClaw supports plugins and hosted diff views.
|
|
```
|
|
|
|
Do both:
|
|
|
|
```text
|
|
Use the `diffs` tool in `both` mode for this diff. Open the viewer in the canvas and then send the rendered file by passing `details.filePath` to the `message` tool.
|
|
|
|
Path: src/demo.ts
|
|
|
|
Before:
|
|
const status = "old";
|
|
|
|
After:
|
|
const status = "new";
|
|
```
|
|
|
|
Patch input:
|
|
|
|
```text
|
|
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
|
|
|
|
- Multi-file patches start with a changed-files summary card: totals, per-file `+N`/`-N` stats, change badges, and anchor links.
|
|
- Rendered PNG/PDF files keep the per-file header counts but omit the interactive view toggles.
|
|
- The viewer is hosted locally through the gateway under `/plugins/diffs/...`.
|
|
- Viewer HTML and metadata are ephemeral SQLite plugin blobs. The URL token is returned to the caller while SQLite stores only its SHA-256 hash.
|
|
- Rendered PNG/PDF files remain temporary materializations in `$TMPDIR/openclaw-diffs` because delivery APIs require a file path. No JSON metadata sidecars are written or imported.
|
|
- Default viewer URLs use `gateway.publicOrigin` when configured, then the existing bind-aware Gateway fallback. Plugin `viewerBaseUrl` and per-call `baseUrl` take precedence.
|
|
- If `gateway.trustedProxies` includes loopback for a same-host proxy (for example Tailscale Serve), raw `127.0.0.1` viewer requests without forwarded client-IP headers fail closed by design.
|
|
- In that topology, prefer `mode=file` / `mode=both` for attachments, or intentionally enable remote viewers and set plugin `viewerBaseUrl` (or pass a proxy/public `baseUrl`) when you need a shareable viewer URL.
|
|
- Remote viewer misses are throttled to reduce token-guess abuse.
|
|
- PNG or PDF rendering requires a Chromium-compatible browser. Set `browser.executablePath` if auto-detection is not enough.
|
|
- If your delivery channel compresses images heavily (for example Telegram or WhatsApp), prefer `fileFormat: "pdf"` to preserve readability.
|
|
- `N unmodified lines` rows may not always include expand controls for patch input, because many patch hunks do not carry full expandable context data.
|
|
- Diff rendering is powered by [Diffs](https://diffs.com).
|