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 <[email protected]>
This commit is contained in:
Julius MarmingeandClaude Fable 5 authored and Gabriel De Andrade committed 2026-07-29 16:58:58 -04:00
1 parent e3edf9bc8e
commit cf121a7260
5 files changed
+55 -5

No files matched your search

@@ -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;
+10 -1
View File
@@ -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;
+4 -2
View File
@@ -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");
@@ -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](<savedScreenshotPath>). Use savePath only when the screenshot should live inside the repo.",
@@ -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