Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
test(runtime): cover host tool image normalization
vastsa936e46230889
diff --git a/docs/spec/03-runtime/02-agent-runtime.md b/docs/spec/03-runtime/02-agent-runtime.mdindex 230e520af..139ca9421 100644--- a/docs/spec/03-runtime/02-agent-runtime.md+++ b/docs/spec/03-runtime/02-agent-runtime.md@@ -41,6 +41,11 @@ crates/host-core (tool execution + permissions)- executes builtin/plugin tools- returns normalized tool results+The Node runtime normalizes text and image content from host tool results,+including MCP `content` blocks and bare plugin content-block arrays. Well-formed+image blocks are passed to vision-capable models and retained when tool history+is restored; malformed image entries are ignored without failing the tool call.+## 4. Runtime API (package-level)```tsdiff --git a/packages/agent-runtime/src/runtime.test.ts b/packages/agent-runtime/src/runtime.test.tsindex eac2fa163..e84ea5fa4 100644--- a/packages/agent-runtime/src/runtime.test.ts+++ b/packages/agent-runtime/src/runtime.test.ts@@ -10772,6 +10772,67 @@ describe("toolResultFromUi image restoration (issue #1073)", () => {{ type: "image", data: "cG5nLWJ5dGVz", mimeType: "image/png" },]);});++ it.each([+ [+ "MCP content property",+ {+ content: [+ { type: "text", text: "MCP returned a screenshot" },+ { type: "image", data: "cG5nLWJ5dGVz", mimeType: "image/png" },+ ],+ isError: false,+ },+ ],+ [+ "plugin bare content-block array",+ [+ { type: "text", text: "Plugin returned a screenshot" },+ { type: "image", data: "cG5nLWJ5dGVz", mimeType: "image/png" },+ ],+ ],+ ])("normalizes %s into model image blocks", async (_shape, rawContent) => {+ const host = {+ call: vi.fn().mockImplementation((method: string) =>+ Promise.resolve(+ method === "project.instructions.resolve"+ ? { entries: [] }+ : { ok: true, content: rawContent },+ ),+ ),+ };+ const runtime = createRuntime({ host });+ const read = (runtime as any).toolCatalog.get("Read");+ const result = await read.execute("image-result", { path: "screenshot.png" });+ const expectedText =+ _shape === "MCP content property"+ ? "MCP returned a screenshot"+ : "Plugin returned a screenshot";+ const expected = [+ { type: "text", text: expectedText },+ { type: "image", data: "cG5nLWJ5dGVz", mimeType: "image/png" },+ ];++ expect(result.content).toEqual(expected);+ expect(result.details).toMatchObject({ imageCount: 1 });++ const restored = toolResultFromUi(+ {+ id: "image-result",+ role: "tool",+ content: "",+ createdAt: new Date(timestamp).toISOString(),+ toolCallId: "image-result",+ toolName: "Read",+ toolResult: result,+ toolStatus: "success",+ isError: false,+ },+ timestamp,+ );+ expect(restored.content).toEqual(expected);+ await runtime.dispose();+ });});it("does not reuse stale plugin declarations when schema or permission metadata changes", async () => {