Screenshots from implementers

This commit is contained in:
Ian Gulliver
2026-10-18 00:39:04 -07:00
parent bd66538383
commit 0a1f58cafa
9 changed files with 59 additions and 13 deletions
+9 -1
View File
@@ -136,5 +136,13 @@ func capture(window id: Int?, display: Int?, crop: [String: Any]?, maxEdge: Doub
func captureTool(_ args: [String: Any]) async throws -> [Content] {
let shot = try await capture(window: args.int("window"), display: args.int("display"), crop: args.dict("crop"), maxEdge: args.double("max_edge") ?? 1568)
return [.text(shot.note), .png(shot.png)]
guard args.bool("save") else {
return [.text(shot.note), .png(shot.png)]
}
guard let dir = mediaDir else {
throw ToolError("save needs byre's media folder, and this byre-hands has none")
}
let url = URL(filePath: dir).appending(path: "capture-\(UUID().uuidString.prefix(8).lowercased()).png")
try shot.png.write(to: url)
return [.text("\(shot.note); saved to \(url.path)"), .png(shot.png)]
}
+8
View File
@@ -31,6 +31,14 @@ struct Tool {
let stdoutLock = NSLock()
let mediaDir: String? = {
let args = CommandLine.arguments
guard let i = args.firstIndex(of: "--media-dir"), i + 1 < args.count else {
return nil
}
return args[i + 1]
}()
@main
struct Server {
static func main() {
+2 -1
View File
@@ -31,7 +31,8 @@ let tools: [Tool] = [
"window": {"type": "integer", "description": "Window id from screen_list."},
"display": {"type": "integer", "description": "Display index from screen_list, when no window is given (default 0)."},
"crop": {"type": "object", "description": "Only this rectangle, in window (or display) points.", "properties": {"x": {"type": "number"}, "y": {"type": "number"}, "width": {"type": "number"}, "height": {"type": "number"}}},
"max_edge": {"type": "number", "description": "Longest edge of the image in pixels, 16 to 8192 (default 1568)."}
"max_edge": {"type": "number", "description": "Longest edge of the image in pixels, 16 to 8192 (default 1568)."},
"save": {"type": "boolean", "description": "Also save the image as a PNG in the task's media folder; the reply gives its path, which a Markdown image in your final message can show."}
}}
""",
run: captureTool