Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

- Limit `--hide-images` and `agent.showImages: false` to inline images emitted
by tool calls, including Copilot CLI `rawOutput` fallbacks and embedded image
resources. Explicit agent message images and attached `resource_link` images
are always sent.

- Add `/acp-new` to clear one WeChat user's ACP conversation without restarting
the bridge. The command stops that user's active turn and agent process, drops
queued and buffered messages, removes the persisted session ID for every
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Options:
- `--no-inbox`: do not save received files; the agent only sees a size notice.
- `--hide-thoughts`: do not forward agent thinking to WeChat (default: forwarded)
- `--show-diffs`: forward ACP file diffs to WeChat (default: hidden)
- `--hide-images`: do not forward agent image output to WeChat (default: forwarded)
- `--hide-images`: suppress inline images from tool calls. Explicit agent message images and attachments are still sent.
- `--hide-audio`: do not forward agent audio output to WeChat (default: forwarded)
- `--hide-resources`: do not forward agent resources or generated file attachments to WeChat (default: forwarded)
- `inject --text <text>`: enqueue a local text message for the running daemon
Expand Down Expand Up @@ -337,7 +337,7 @@ Notes:

- The command only works after the WeChat user already has an active ACP session. If not, send a normal message first so the session is created.
- Agent-specific `configId` values come from the ACP agent's `configOptions`, so that part of the list depends on the configured agent.
- The built-in `bridge.thoughts`, `bridge.diffs`, `bridge.images`, and `bridge.audio` options control output forwarding for the current WeChat user's session. They use the startup config as defaults, accept `on` or `off`, and are not persisted across session resets or bridge restarts.
- The built-in `bridge.thoughts`, `bridge.diffs`, and `bridge.audio` options control output forwarding for the current WeChat user's session. `bridge.images` controls only inline tool images; explicit response images and attached `resource_link` images are always sent. These options use the startup config as defaults, accept `on` or `off`, and are not persisted across session resets or bridge restarts.
- Runtime bridge changes take effect on the next agent turn. They do not change a turn that is already running.
- `agent.showResources` remains a startup-only setting and is not shown as a runtime option.
- This command is handled by `wechat-acp` itself and is **not** forwarded to the underlying agent.
Expand Down Expand Up @@ -462,6 +462,11 @@ created under the configured working directory, and the bridge sends that
snapshot back as a WeChat file message. Files whose type is a supported image
are delivered as native WeChat images instead of file cards.

Tool calls may also expose intermediate screenshots or video frames as inline
images. Use `--hide-images` or `agent.showImages: false` to suppress them.
Images that the agent explicitly emits in its response or sends through an
Comment thread
Eskibear marked this conversation as resolved.
Resolved
attached `resource_link` are always sent.

The MCP server listens only on a random `127.0.0.1` port, requires a
process-local bearer token, rejects browser-origin requests, and only reads
regular files whose resolved path stays inside the agent working directory.
Expand Down
2 changes: 1 addition & 1 deletion bin/wechat-acp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Options:
Send a standalone message after each completed agent turn
--hide-thoughts Do not forward agent thinking to WeChat (default: forwarded)
--show-diffs Forward ACP file diffs to WeChat (default: hidden)
--hide-images Do not forward agent image output to WeChat (default: forwarded)
--hide-images Do not forward intermediate inline tool images to WeChat
--hide-audio Do not forward agent audio output to WeChat (default: forwarded)
--hide-resources Do not forward agent embedded resources to WeChat (default: forwarded)
--text <text> Message text for "inject"
Expand Down
64 changes: 46 additions & 18 deletions src/acp/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export interface AgentImage {
mimeType: string;
}

type ImageSource = "explicit" | "tool";

/** Raster formats WeChat can render as native image messages. */
const SUPPORTED_IMAGE_MIME_TYPES = new Set([
"image/png",
Expand Down Expand Up @@ -468,13 +470,13 @@ export class WeChatAcpClient implements acp.Client {
turn.producedMessage = true;
}
} else if (update.content.type === "image") {
await this.maybeSendImage(update.content, turn);
await this.maybeSendImage(update.content, turn, "explicit");
} else if (update.content.type === "audio") {
await this.maybeSendAudio(update.content, turn);
} else if (update.content.type === "resource") {
await this.maybeRenderResource(update.content.resource, turn);
await this.maybeRenderResource(update.content.resource, turn, "explicit");
} else if (update.content.type === "resource_link") {
await this.maybeSendResourceLink(update.content, turn);
await this.maybeSendResourceLink(update.content, turn, "explicit");
}
// Throttle typing indicators
await this.maybeSendTyping(turn);
Expand All @@ -486,7 +488,7 @@ export class WeChatAcpClient implements acp.Client {
if (update.status === "completed" && update.content) {
for (const content of update.content) {
if (content.type === "content" && content.content.type === "resource_link") {
await this.maybeSendResourceLink(content.content, turn);
await this.maybeSendResourceLink(content.content, turn, "explicit");
}
}
}
Expand Down Expand Up @@ -531,17 +533,17 @@ export class WeChatAcpClient implements acp.Client {
turn.producedMessage = true;
} else if (c.type === "content" && c.content.type === "image") {
imageContentBlocks++;
await this.maybeSendImage(c.content, turn);
await this.maybeSendImage(c.content, turn, "tool");
} else if (c.type === "content" && c.content.type === "audio") {
await this.maybeSendAudio(c.content, turn);
} else if (c.type === "content" && c.content.type === "resource") {
resourceContentBlocks++;
if (await this.maybeRenderResource(c.content.resource, turn)) {
if (await this.maybeRenderResource(c.content.resource, turn, "tool")) {
resourceImages++;
}
} else if (c.type === "content" && c.content.type === "resource_link") {
resourceLinkContentBlocks++;
if (await this.maybeSendResourceLink(c.content, turn)) {
if (await this.maybeSendResourceLink(c.content, turn, "explicit")) {
resourceLinkImages++;
}
}
Expand Down Expand Up @@ -704,7 +706,7 @@ export class WeChatAcpClient implements acp.Client {
mimeType.trim()
) {
images++;
await this.maybeSendImage({ data, mimeType }, turn);
await this.maybeSendImage({ data, mimeType }, turn, "tool");
}
}
return images;
Expand Down Expand Up @@ -776,7 +778,7 @@ export class WeChatAcpClient implements acp.Client {
continue;
}
resources++;
if (await this.maybeRenderResource(clean, turn)) {
if (await this.maybeRenderResource(clean, turn, "tool")) {
images++;
}
}
Expand All @@ -803,7 +805,7 @@ export class WeChatAcpClient implements acp.Client {
blob: data,
...(typeof mimeType === "string" ? { mimeType } : {}),
};
if (await this.maybeRenderResource(clean, turn)) {
if (await this.maybeRenderResource(clean, turn, "tool")) {
images++;
}
}
Expand Down Expand Up @@ -844,6 +846,7 @@ export class WeChatAcpClient implements acp.Client {
...(typeof size === "number" ? { size } : {}),
},
turn,
"explicit",
)) {
images++;
}
Expand All @@ -854,16 +857,21 @@ export class WeChatAcpClient implements acp.Client {
private async maybeSendResourceLink(
link: AgentResourceLink,
turn: TurnState,
source: ImageSource,
): Promise<boolean> {
const opts = turn.opts;
const name = sanitizeInlineLabel(link.name ?? resourceDisplayName(link.uri));
const mimeType = sanitizeInlineLabel(link.mimeType ?? "")
.split(";")[0]
.trim()
.toLowerCase();
if (source === "tool" && opts.showImages === false && mimeType.startsWith("image/")) {
opts.log(`[resource-link] skipped tool image (showImages=false, ${name})`);
return true;
}
const routesToImagePipeline =
SUPPORTED_IMAGE_MIME_TYPES.has(mimeType) &&
opts.showImages !== false &&
(source !== "tool" || opts.showImages !== false) &&
Boolean(opts.onImageFlush);
if (opts.showResources === false) {
opts.log(`[resource-link] skipped (showResources=false, ${name})`);
Expand All @@ -890,7 +898,7 @@ export class WeChatAcpClient implements acp.Client {
opts.log(`[resource-link] unavailable: ${name}`);
return false;
}
return await this.maybeSendFile(file, turn);
return await this.maybeSendFile(file, turn, source);
} catch (err) {
turn.chunks.push(`\n⚠️ [file ${name} could not be resolved]\n`);
turn.producedMessage = true;
Expand All @@ -903,21 +911,29 @@ export class WeChatAcpClient implements acp.Client {
* Deliver a resolved file and return whether it was routed through the
* native image pipeline. A successful generic file delivery returns false.
*/
private async maybeSendFile(file: AgentFile, turn: TurnState): Promise<boolean> {
private async maybeSendFile(
file: AgentFile,
turn: TurnState,
source: ImageSource,
): Promise<boolean> {
const opts = turn.opts;
const name = sanitizeInlineLabel(file.name) || "artifact";
const mimeType =
sanitizeInlineLabel(file.mimeType).split(";")[0].trim().toLowerCase() ||
"application/octet-stream";
if (source === "tool" && opts.showImages === false && mimeType.startsWith("image/")) {
opts.log(`[file] skipped tool image (showImages=false, ${name})`);
return true;
}
const decodedBytes = decodedBase64ByteLength(file.data);
if (
opts.showImages !== false &&
(source !== "tool" || opts.showImages !== false) &&
opts.onImageFlush &&
SUPPORTED_IMAGE_MIME_TYPES.has(mimeType) &&
base64DecodedByteUpperBound(file.data) <= MAX_IMAGE_BYTES
) {
opts.log(`[file] routing image file ${name} through image pipeline (${mimeType}, ${decodedBytes} bytes)`);
await this.maybeSendImage({ data: file.data, mimeType }, turn);
await this.maybeSendImage({ data: file.data, mimeType }, turn, source);
return true;
}

Expand Down Expand Up @@ -964,12 +980,13 @@ export class WeChatAcpClient implements acp.Client {
private async maybeSendImage(
image: { data: string; mimeType: string },
turn: TurnState,
source: ImageSource,
): Promise<void> {
const opts = turn.opts;
// Trim once here so every image path (content block, message chunk,
// rawOutput fallback) validates and delivers the same normalized value.
const mimeType = image.mimeType.trim();
if (opts.showImages === false) {
if (source === "tool" && opts.showImages === false) {
opts.log(`[image] skipped (showImages=false, ${mimeType})`);
return;
}
Expand Down Expand Up @@ -1085,6 +1102,7 @@ export class WeChatAcpClient implements acp.Client {
private async maybeRenderResource(
resource: acp.EmbeddedResource["resource"],
turn: TurnState,
source: ImageSource,
): Promise<boolean> {
const opts = turn.opts;
const name = resourceDisplayName(resource.uri);
Expand All @@ -1099,10 +1117,19 @@ export class WeChatAcpClient implements acp.Client {
// through to the visible placeholder instead.
const mime = sanitizeInlineLabel(resource.mimeType ?? "");
const baseMime = mime.split(";")[0].trim().toLowerCase();
if (
!("text" in resource) &&
source === "tool" &&
opts.showImages === false &&
baseMime.startsWith("image/")
) {
opts.log(`[resource] skipped tool image (showImages=false, ${name})`);
return true;
}
const routesToImagePipeline =
!("text" in resource) &&
SUPPORTED_IMAGE_MIME_TYPES.has(baseMime) &&
opts.showImages !== false &&
(source !== "tool" || opts.showImages !== false) &&
Boolean(opts.onImageFlush);
if (opts.showResources === false) {
opts.log(`[resource] skipped (showResources=false, ${name})`);
Expand Down Expand Up @@ -1136,7 +1163,7 @@ export class WeChatAcpClient implements acp.Client {
if (routesToImagePipeline) {
// Route through the image pipeline so an image handed back as an
// embedded resource behaves exactly like an image content block.
await this.maybeSendImage({ data: resource.blob, mimeType: baseMime }, turn);
await this.maybeSendImage({ data: resource.blob, mimeType: baseMime }, turn, source);
return true;
}

Expand All @@ -1159,6 +1186,7 @@ export class WeChatAcpClient implements acp.Client {
mimeType: baseMime || "application/octet-stream",
},
turn,
source,
);
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const RUNTIME_BRIDGE_CONFIG_OPTIONS: ReadonlyArray<{
}> = [
{ id: "bridge.thoughts", setting: "thoughts", name: "Thoughts" },
{ id: "bridge.diffs", setting: "diffs", name: "Diffs" },
{ id: "bridge.images", setting: "images", name: "Images" },
{ id: "bridge.images", setting: "images", name: "Tool Images" },
{ id: "bridge.audio", setting: "audio", name: "Audio" },
];

Expand Down
6 changes: 3 additions & 3 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ export interface WeChatAcpConfig {
showThoughts: boolean;
showDiffs?: boolean;
/**
* Render agent-produced ACP `image` content blocks as native WeChat
* image messages. Defaults to `true`; set to `false` (or pass
* `--hide-images`) to drop them.
* Render inline images produced inside ACP tool calls. Defaults to `true`;
* set to `false` (or pass `--hide-images`) to suppress intermediate tool
* images. Explicit agent message images and attachments are always sent.
*/
showImages?: boolean;
/**
Expand Down
7 changes: 4 additions & 3 deletions tests/bridge-new-session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,16 +456,17 @@ test("acp-config updates runtime bridge settings without calling the agent", asy

await bridge.handleMessage(
textMessage(
`${BRIDGE_COMMANDS.acpConfig} set bridge.diffs on`,
`${BRIDGE_COMMANDS.acpConfig} set bridge.images off`,
"context-config",
),
);

assert.deepEqual(updates, [{ setting: "diffs", value: true }]);
assert.deepEqual(updates, [{ setting: "images", value: false }]);
assert.equal(bridge.enqueued.length, 0);
assert.ok(
bridge.sent.some(({ segment }) =>
segment.includes("bridge.diffs = on") &&
segment.includes("bridge.images = off") &&
segment.includes("**Tool Images**") &&
segment.includes("Runtime Bridge Config") &&
segment.includes("ACP Session Config")
),
Expand Down
Loading
Loading