@mono-agent/agent-runtime 0.18.3 → 0.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/MIGRATION.md +9 -1
- package/README.md +2 -0
- package/package.json +3 -1
- package/src/agent/tools/read.js +81 -1
package/MIGRATION.md
CHANGED
|
@@ -17,6 +17,14 @@ the configuration schema.
|
|
|
17
17
|
|
|
18
18
|
---
|
|
19
19
|
|
|
20
|
+
## 0.19.0
|
|
21
|
+
|
|
22
|
+
- **Oversized `Read` images:** raster image results with an edge above 8,000
|
|
23
|
+
pixels are now normalized before provider embedding. Source files are never
|
|
24
|
+
modified; safe images retain their exact bytes, resized GIF/WebP input keeps
|
|
25
|
+
its animation, and resized BMP input becomes PNG. Undecodable image data now
|
|
26
|
+
fails before the runtime creates an image content block.
|
|
27
|
+
|
|
20
28
|
## 0.18.2
|
|
21
29
|
|
|
22
30
|
- **Normalized native-subagent activity:** Claude SDK/CLI and Codex app-server
|
|
@@ -482,7 +490,7 @@ a compatibility subpath.
|
|
|
482
490
|
|
|
483
491
|
## Version
|
|
484
492
|
|
|
485
|
-
This guide describes the published `0.
|
|
493
|
+
This guide describes the published `0.19.x` package contract. Keep
|
|
486
494
|
`@mono-agent/agent-runtime`, `@mono-agent/runtime-adapter`, and other
|
|
487
495
|
`@mono-agent/*` packages on the same lockstep version when upgrading. The paired
|
|
488
496
|
runtime adapter no longer exposes `piReasoningSummary` in its run-options type.
|
package/README.md
CHANGED
|
@@ -1094,6 +1094,8 @@ The kernel's tool-bloat guard (`agent/tool-bloat.js`, internal) enforces a 256 K
|
|
|
1094
1094
|
|
|
1095
1095
|
Hosts that don't supply `persistArtifact` get the truncation summary but no on-disk capture.
|
|
1096
1096
|
|
|
1097
|
+
Before that byte cap runs, the builtin `Read` tool normalizes raster images with an edge longer than 8,000 px to fit within an 8,000 × 8,000 px box. Resizing preserves aspect ratio and the source format (resized BMP input becomes PNG), retains GIF/WebP animation, and never modifies the source file. Images already within the limit are embedded byte-for-byte unchanged.
|
|
1098
|
+
|
|
1097
1099
|
### Context compaction
|
|
1098
1100
|
|
|
1099
1101
|
The sole pi bridge runs on pi-agent-core's native `AgentHarness`. pi performs **no**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mono-agent/agent-runtime",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.1",
|
|
4
4
|
"description": "Agent runtime supporting Claude SDK/CLI, Codex, OpenCode, Pi SDK, and ACP v1 bridges out of the box",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "GPL-3.0-only",
|
|
@@ -144,9 +144,11 @@
|
|
|
144
144
|
"@mozilla/readability": "0.6.0",
|
|
145
145
|
"@opencode-ai/sdk": "^1.15.13",
|
|
146
146
|
"@vscode/ripgrep": "1.18.0",
|
|
147
|
+
"bmp-ts": "1.0.9",
|
|
147
148
|
"cross-spawn": "^7.0.6",
|
|
148
149
|
"defuddle": "0.19.2",
|
|
149
150
|
"linkedom": "0.18.13",
|
|
151
|
+
"sharp": "0.35.3",
|
|
150
152
|
"unpdf": "1.8.0",
|
|
151
153
|
"zod": "^4.3.6"
|
|
152
154
|
},
|
package/src/agent/tools/read.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from "node:fs";
|
|
2
2
|
import { extname } from "node:path";
|
|
3
|
+
import { decode as decodeBmp } from "bmp-ts";
|
|
4
|
+
import sharp from "sharp";
|
|
3
5
|
import {
|
|
4
6
|
DEFAULT_MAX_READ_CHARS,
|
|
5
7
|
DEFAULT_READ_LINES,
|
|
@@ -20,6 +22,82 @@ const IMAGE_MIME_BY_EXT = {
|
|
|
20
22
|
".bmp": "image/bmp",
|
|
21
23
|
};
|
|
22
24
|
|
|
25
|
+
// Anthropic rejects images with an edge longer than 8,000 px. Normalize Read
|
|
26
|
+
// results to that shared provider-safe ceiling before the tool-result byte cap
|
|
27
|
+
// runs, while leaving the source file untouched.
|
|
28
|
+
const MAX_INLINE_IMAGE_EDGE_PX = 8_000;
|
|
29
|
+
const ANIMATED_IMAGE_MIME_TYPES = new Set(["image/gif", "image/webp"]);
|
|
30
|
+
const OUTPUT_MIME_BY_FORMAT = {
|
|
31
|
+
png: "image/png",
|
|
32
|
+
jpeg: "image/jpeg",
|
|
33
|
+
gif: "image/gif",
|
|
34
|
+
webp: "image/webp",
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @param {string} target
|
|
39
|
+
* @param {string} filePath
|
|
40
|
+
* @param {string} imageMime
|
|
41
|
+
*/
|
|
42
|
+
async function readImageForModel(target, filePath, imageMime) {
|
|
43
|
+
const source = readFileSync(target);
|
|
44
|
+
const inputOptions = { animated: ANIMATED_IMAGE_MIME_TYPES.has(imageMime) };
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
let width;
|
|
48
|
+
let height;
|
|
49
|
+
let createPipeline;
|
|
50
|
+
|
|
51
|
+
if (imageMime === "image/bmp") {
|
|
52
|
+
// The prebuilt Sharp binaries do not include a BMP loader. Decode to raw
|
|
53
|
+
// RGBA first, then let Sharp handle the provider-safe resize and PNG output.
|
|
54
|
+
const decoded = decodeBmp(source, { toRGBA: true });
|
|
55
|
+
width = decoded.width;
|
|
56
|
+
height = Math.abs(decoded.height);
|
|
57
|
+
createPipeline = () => sharp(decoded.data, {
|
|
58
|
+
raw: { width, height, channels: 4 },
|
|
59
|
+
});
|
|
60
|
+
} else {
|
|
61
|
+
const metadata = await sharp(source, inputOptions).metadata();
|
|
62
|
+
width = metadata.width;
|
|
63
|
+
// Sharp exposes animated images as a vertical stack internally. Providers
|
|
64
|
+
// care about the dimensions of each frame, not the height of that stack.
|
|
65
|
+
height = metadata.pageHeight ?? metadata.height;
|
|
66
|
+
createPipeline = () => sharp(source, inputOptions);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!Number.isInteger(width) || width <= 0 || !Number.isInteger(height) || height <= 0) {
|
|
70
|
+
throw new Error("could not determine positive pixel dimensions");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (width <= MAX_INLINE_IMAGE_EDGE_PX && height <= MAX_INLINE_IMAGE_EDGE_PX) {
|
|
74
|
+
return { data: source, mimeType: imageMime };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
let pipeline = createPipeline()
|
|
78
|
+
.autoOrient()
|
|
79
|
+
.resize({
|
|
80
|
+
width: MAX_INLINE_IMAGE_EDGE_PX,
|
|
81
|
+
height: MAX_INLINE_IMAGE_EDGE_PX,
|
|
82
|
+
fit: "inside",
|
|
83
|
+
withoutEnlargement: true,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// Sharp cannot emit BMP, so resized BMP input becomes lossless PNG.
|
|
87
|
+
if (imageMime === "image/bmp") pipeline = pipeline.png();
|
|
88
|
+
|
|
89
|
+
const { data, info } = await pipeline.toBuffer({ resolveWithObject: true });
|
|
90
|
+
const mimeType = OUTPUT_MIME_BY_FORMAT[info.format];
|
|
91
|
+
if (mimeType === undefined) {
|
|
92
|
+
throw new Error(`unsupported normalized image format: ${info.format}`);
|
|
93
|
+
}
|
|
94
|
+
return { data, mimeType };
|
|
95
|
+
} catch (error) {
|
|
96
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
97
|
+
return { error: `Error: Unable to read image ${filePath}: ${reason}` };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
23
101
|
/**
|
|
24
102
|
* @param {{file_path: string, offset?: number, start_line?: number, limit?: number, max_output_chars?: number, workdir?: string}} params
|
|
25
103
|
* @param {{sandboxPolicy?: any, ctx?: any}} [options]
|
|
@@ -34,7 +112,9 @@ export async function readToolImpl({ file_path, offset = 0, start_line, limit, m
|
|
|
34
112
|
// capped by the shared tool-result bloat guard.
|
|
35
113
|
const imageMime = IMAGE_MIME_BY_EXT[extname(target).toLowerCase()];
|
|
36
114
|
if (imageMime !== undefined) {
|
|
37
|
-
|
|
115
|
+
const image = await readImageForModel(target, file_path, imageMime);
|
|
116
|
+
if (image.error !== undefined) return image.error;
|
|
117
|
+
return { kind: "image", data: image.data.toString("base64"), mimeType: image.mimeType };
|
|
38
118
|
}
|
|
39
119
|
const content = readFileSync(target, "utf8");
|
|
40
120
|
let lines = content.split("\n");
|