From cf121a7260eb326c71d69d7aca97f70060e6ded1 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 27 Jul 2026 23:01:10 +0200 Subject: [PATCH] Fix snapshot tool annotations and ..-prefixed workspace paths - Drop readonly/idempotent hints from preview_snapshot now that it writes - Treat only real .. segments as escapes when resolving workspace assets - Append image galleries when turns share a target row Co-Authored-By: Claude Fable 5 --- apps/server/src/assets/AssetAccess.test.ts | 29 +++++++++++++++++++ apps/server/src/assets/AssetAccess.ts | 11 ++++++- apps/server/src/mcp/McpHttpServer.test.ts | 6 ++-- apps/server/src/mcp/toolkits/preview/tools.ts | 5 +++- .../components/chat/MessagesTimeline.logic.ts | 9 +++++- 5 files changed, 55 insertions(+), 5 deletions(-) diff --git a/apps/server/src/assets/AssetAccess.test.ts b/apps/server/src/assets/AssetAccess.test.ts index 55d953ed78..0ae7ecafab 100644 --- a/apps/server/src/assets/AssetAccess.test.ts +++ b/apps/server/src/assets/AssetAccess.test.ts @@ -139,6 +139,35 @@ describe("AssetAccess", () => { }).pipe(Effect.provide(testLayer)), ); + it.effect("serves workspace files in directories whose name starts with ..", () => + Effect.gen(function* () { + const fileSystem = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const root = yield* fileSystem.makeTempDirectoryScoped({ + prefix: "t3-asset-dotdot-name-", + }); + yield* fileSystem.makeDirectory(path.join(root, "..screenshots"), { recursive: true }); + const imagePath = path.join(root, "..screenshots", "capture.png"); + yield* fileSystem.writeFile(imagePath, new Uint8Array([137, 80, 78, 71])); + const canonicalImagePath = yield* fileSystem.realPath(imagePath); + + const result = yield* issueAssetUrl({ + resource: { + _tag: "workspace-file", + threadId: ThreadId.make("thread-1"), + path: "..screenshots/capture.png", + }, + workspaceRoot: root, + }); + const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length); + const token = suffix.slice(0, suffix.indexOf("/")); + expect(yield* resolveAsset(token, "capture.png")).toEqual({ + kind: "file", + path: canonicalImagePath, + }); + }).pipe(Effect.provide(testLayer)), + ); + it.effect("rejects workspace files outside the authorized root", () => Effect.gen(function* () { const fileSystem = yield* FileSystem.FileSystem; diff --git a/apps/server/src/assets/AssetAccess.ts b/apps/server/src/assets/AssetAccess.ts index 94b2c6a7b0..79aea5dfcb 100644 --- a/apps/server/src/assets/AssetAccess.ts +++ b/apps/server/src/assets/AssetAccess.ts @@ -216,7 +216,16 @@ const resolveCanonicalWorkspaceFile = Effect.fn("AssetAccess.resolveCanonicalWor const path = yield* Path.Path; const relative = path.relative(canonicalRoot.value, canonicalFile.value); - if (relative === "" || relative.startsWith("..") || path.isAbsolute(relative)) return null; + // `..name` is an ordinary in-root directory, so only a real `..` segment + // counts as an escape. + if ( + relative === "" || + relative === ".." || + relative.startsWith(`..${path.sep}`) || + path.isAbsolute(relative) + ) { + return null; + } const info = yield* optionOnNotFound(fileSystem.stat(canonicalFile.value)); return Option.isSome(info) && info.value.type === "File" ? canonicalFile.value : null; diff --git a/apps/server/src/mcp/McpHttpServer.test.ts b/apps/server/src/mcp/McpHttpServer.test.ts index 7ec461f29e..fdb20a095c 100644 --- a/apps/server/src/mcp/McpHttpServer.test.ts +++ b/apps/server/src/mcp/McpHttpServer.test.ts @@ -260,8 +260,10 @@ it.effect("registers annotated tools and preserves authenticated request context expect(statusTool?.tool.annotations?.destructiveHint).toBe(false); const snapshotTool = server.tools.find(({ tool }) => tool.name === "preview_snapshot"); - expect(snapshotTool?.tool.annotations?.readOnlyHint).toBe(true); - expect(snapshotTool?.tool.annotations?.idempotentHint).toBe(true); + // save/savePath write files, so the snapshot tool is not read-only. + expect(snapshotTool?.tool.annotations?.readOnlyHint).toBe(false); + expect(snapshotTool?.tool.annotations?.idempotentHint).toBe(false); + expect(snapshotTool?.tool.annotations?.destructiveHint).toBe(false); expect(snapshotTool?.tool.annotations?.openWorldHint).toBe(true); const clickTool = server.tools.find(({ tool }) => tool.name === "preview_click"); diff --git a/apps/server/src/mcp/toolkits/preview/tools.ts b/apps/server/src/mcp/toolkits/preview/tools.ts index 518eedb7a4..52e269b7d7 100644 --- a/apps/server/src/mcp/toolkits/preview/tools.ts +++ b/apps/server/src/mcp/toolkits/preview/tools.ts @@ -116,7 +116,10 @@ export const PreviewSetAppearanceTool = safeBrowserTool( .annotate(Tool.Idempotent, true), ); -export const PreviewSnapshotTool = readonlyBrowserTool( +// Not `readonlyBrowserTool`: `save`/`savePath` write a screenshot file, and +// `save:true` names a fresh artifact per call, so it is neither read-only +// nor idempotent. +export const PreviewSnapshotTool = safeBrowserTool( Tool.make("preview_snapshot", { description: "Inspect a page before interacting. Pass tabId to inspect a specific tab; omit it to use this agent session's current tab. Returns page state, semantic elements, diagnostics, action history, and a PNG screenshot. To keep visual evidence for the human (before/after states of UI work), pass save:true — the result then includes savedScreenshotPath, which you embed in your final reply with markdown image syntax, e.g. ![after](). Use savePath only when the screenshot should live inside the repo.", diff --git a/apps/web/src/components/chat/MessagesTimeline.logic.ts b/apps/web/src/components/chat/MessagesTimeline.logic.ts index 44e34684bb..605d1db24b 100644 --- a/apps/web/src/components/chat/MessagesTimeline.logic.ts +++ b/apps/web/src/components/chat/MessagesTimeline.logic.ts @@ -367,7 +367,14 @@ function appendImageOutputRows(input: { trailingOutputs.push(outputRow); continue; } - outputsAfterRowId.set(targetRowId, [outputRow]); + // A grouped work row can cover several turns, so multiple turns may map to + // the same target row — append rather than replacing the previous gallery. + const existingOutputs = outputsAfterRowId.get(targetRowId); + if (existingOutputs) { + existingOutputs.push(outputRow); + } else { + outputsAfterRowId.set(targetRowId, [outputRow]); + } } return input.rows