gtmux

gtmux / 指南guides

Screenshots for local agents给本地 agent 使用的截图能力

On this page
本页目录

Use gtmux screenshot from a local agent’s command tool. It emits versioned JSON, image paths and SHA256 hashes. A second MCP service is not needed for this workflow. The native operations require a compatible running Gtmux macOS App; querying capabilities never launches it or opens a permission prompt. A new App can take up to two seconds to acquire the screenshot endpoint from an older instance.

Observe, capture, inspect, mark, send

Keep images and sidecars in the current task’s output directory. Do not use gtmux configuration or state directories as a project workspace.

mkdir -p /tmp/my-task-shots
gtmux screenshot capabilities
gtmux screenshot sources --app com.mitchellh.ghostty
gtmux screenshot capture --source-ref REF --rect 40,60,800,500 --unit pt --output /tmp/my-task-shots/terminal.png

Choose REF from the returned window inventory. To select a display explicitly, use sources --displays. References expire after 30 seconds. The window’s owner, process birth, geometry, display mapping and backing scale are checked again before and after capture. A scale change with unchanged point bounds also expires the observation. A changed source is refused rather than silently widening to a whole display. Regions use source-local top-left points; a window can have a negative global display origin. Very large full sources and regions crossing different display scales are refused; select a smaller source or separate regions.

Read the returned preview_path through your agent’s image viewer. The sidecar includes full/preview dimensions and hashes, a capture ID and the point-to-image transform. Use exactly that coordinate frame when marking. An existing PNG/JPEG/other supported ImageIO image can instead be normalized with:

gtmux screenshot import --input /tmp/existing.jpg --output /tmp/my-task-shots/imported.png

Imported images are identified as imported, without invented live-window provenance. Annotation JSON addresses an exact image:

{
  "schema_version": 1,
  "capture_id": "COPY_FROM_SIDECAR",
  "image_sha256": "COPY_FROM_SIDECAR",
  "coordinate_space": "image_px",
  "annotations": [
    {"type": "rect", "x": 20, "y": 30, "width": 300, "height": 80, "color": "red"},
    {"type": "arrow", "from": [500, 200], "to": [320, 90], "color": "blue"},
    {"type": "text", "x": 20, "y": 130, "text": "Inspect this result"},
    {"type": "redact", "x": 20, "y": 220, "width": 200, "height": 40}
  ]
}

preview_px is also supported when the matching preview_id is supplied. Other marks are ellipse, mosaic, and line with points: [[x,y], ...]. Colors are red/blue/yellow; stroke styles are thin/medium/thick. Solid redact rounds coverage outward to intersected pixels, including in the downsampled preview, and removes covered pixels from the derived PNG; mosaic is visual obscuring and is not equivalent. The unredacted base still exists locally: keep it private, and send only the derived file.

gtmux screenshot annotate --capture /tmp/my-task-shots/terminal.capture.json --spec /tmp/my-task-shots/marks.json --output /tmp/my-task-shots/marked.png
gtmux screenshot edit --document /tmp/my-task-shots/marked.capture.json

Annotation uses the existing native renderer. Base image plus marks remain editable through the existing editor; each edit opens an independent window without replacing another draft; editor-busy is returned only when the eight-window limit is reached. Capture, import, annotation and editing never send implicitly. Output files are not overwritten. A later annotation of an editable derived document is refused: use edit, or explicitly import the flattened image as a new base.

Deliver to one exact conversation

gtmux screenshot target --pane %9 --session-id EXPECTED_SESSION_ID
gtmux screenshot send --image /tmp/my-task-shots/marked.png --target-ref TARGET_REF --request-id task-shot-00000001 --message-file /tmp/my-task-shots/note.txt
gtmux screenshot status task-shot-00000001

Target references last ten minutes and bind session, home, client, pane root and tmux server incarnation. This first version supports verified managed Codex and DeepSeek Harness native bindings. Other clients keep gtmux send --attach; no bare-terminal fallback is introduced. Resolve a reference on demand, rather than adding process inspections to normal agent-list polling.

A receipt records the last observed state and time:

StateMeaning
landedInput receipt confirms entry into the conversation.
active_turn_acceptedCurrent turn accepted the image input.
queuedBackend accepted it for a queue; entry into conversation is unconfirmed.
blocked / failedSubmission was refused or failed before a confirmed input receipt.
unknownAcceptance could not be confirmed. Preserve the ID and investigate; do not retry automatically.

None means the agent read the image or completed work. status reads the durable receipt; it does not resume a thread or claim a queued item is still queued now. The same request ID and payload never silently send twice; changing its image, note or target is a conflict. Resolve expired targets for new submissions; inspect an existing request by ID.

Limits and storage

Requests have a ten-second maximum budget, 256 KiB JSON, 30 MiB/image, 32 million pixels, 500 marks and 10,000 path points. Preview long edge is at most 1600 pixels. The App accepts local same-user Unix connections with pinned host identity, a per-host nonce and opened file descriptors; requests cannot name arbitrary native output paths. No TCP, shell execution, clipboard changes or implicit Screen Recording prompt occurs. The App blocks on its listener when idle, with two concurrent request slots. Deadline expiry, caller disconnect and host stop revoke the request and close its transport. Image decoding, rendering and file IO run away from the UI thread. An OS callback or filesystem call may itself be uninterruptible: the host retains a bounded outstanding-work permit until it actually completes, rejects replacement work with native-busy, and discards late results instead of opening an editor or publishing an artifact. A stalled OS capture does not prevent a capabilities query; it does not authorize automatically retrying an uncertain send.

The caller owns PNG/preview/sidecar outputs. Product-managed capture-bridge holds only the host/socket lease and identity. capture-requests holds a private target-signing key and hashed delivery receipts, capped at 1000 directory entries; it stores no note or image body. A full receipt budget returns an explicit error and does not discard unresolved receipts. This increment does not automatically migrate or delete existing archives. Existing attachment delivery retains its established product-managed uploads behavior.

Linux can query CLI help and use supported delivery logic, but native image operations report platform-unsupported. Native recording permission, real window capture and signed installation are acceptance items distinct from synthetic renderer/socket tests.

Editing several screenshots

Press ⌥⌘4 again to take another screenshot while a previous editor is open. Each window has its own image, annotations, message and delivery result. Up to eight windows may stay open; save or close one before opening more. Copy, Save and a confirmed send close only their own window.

The destination picker uses the same session title as the menu bar. Type a title, project or pane ID to filter the list; abbreviations work too. Use ↑/↓ and Return to select, or Escape to close the list. The secondary line identifies the agent and tmux location. Sending requires an explicit action; a real pending approval still needs your attention. Connection failures are reported separately and preserve the draft.

Source: docs/guides/agent-screenshots.md at 29f9eb0 · Edit on GitHub

本地 agent 直接通过命令工具运行 gtmux screenshot 即可,返回带版本号的 JSON、图片路径和 SHA256。此工作流不需要额外 MCP 服务。原生截图/标注需要兼容且正在运行的 Mac App;能力查询不会启动 App 或弹权限申请。更新 App 时,本地接口最多用两秒等待旧实例交接。

观察、截取、查看、标记、发送

图片与 sidecar 存在当前任务自己的输出目录,不把 gtmux 配置或状态目录当项目工作区。

mkdir -p /tmp/my-task-shots
gtmux screenshot capabilities
gtmux screenshot sources --app com.mitchellh.ghostty
gtmux screenshot capture --source-ref REF --rect 40,60,800,500 --unit pt --output /tmp/my-task-shots/terminal.png

从窗口清单选择 REF;明确需要整个显示器时用 sources --displays。引用 30 秒后过期,截取前后都会核窗口所属进程、进程启动时间、边界、显示器映射及像素缩放;即使逻辑边界没变,缩放改变也会让原观察失效。来源改变会拒绝,不会悄悄扩大到整个屏幕。区域坐标是来源左上角的逻辑点,支持显示器全局原点为负;超大完整来源、跨不同缩放显示器的区域会拒绝,需要选较小来源或分区截取。

agent 用自己的图片查看工具读取返回的 preview_path。sidecar 给出原图/预览尺寸与哈希、capture ID 和坐标变换;标注必须使用该帧。也可导入已有图片:

gtmux screenshot import --input /tmp/existing.jpg --output /tmp/my-task-shots/imported.png

导入结果明确标为 imported,不伪造实时窗口来源。标注 JSON 示例:

{
  "schema_version": 1,
  "capture_id": "从 sidecar 复制",
  "image_sha256": "从 sidecar 复制",
  "coordinate_space": "image_px",
  "annotations": [
    {"type": "rect", "x": 20, "y": 30, "width": 300, "height": 80, "color": "red"},
    {"type": "arrow", "from": [500, 200], "to": [320, 90], "color": "blue"},
    {"type": "text", "x": 20, "y": 130, "text": "检查这个结果"},
    {"type": "redact", "x": 20, "y": 220, "width": 200, "height": 40}
  ]
}

也支持 preview_px,但必须附相同帧的 preview_id。其他标记为 ellipse、mosaic、带 points: [[x,y], ...] 的 line。颜色 red/blue/yellow,线宽 thin/medium/thick。redact 对相交像素向外取整并用不透明色覆盖,缩小预览也保持这一规则,派生 PNG 中不保留被覆盖像素;mosaic 只是视觉模糊,不能当作同等脱敏。未脱敏原图仍在本地,需妥善保管,发送时明确选择派生文件。

gtmux screenshot annotate --capture /tmp/my-task-shots/terminal.capture.json --spec /tmp/my-task-shots/marks.json --output /tmp/my-task-shots/marked.png
gtmux screenshot edit --document /tmp/my-task-shots/marked.capture.json

复用现有原生渲染器及编辑器,保留原图和标记供调整。每次 edit 打开独立窗口,不替换已有草稿;同时打开八张后,新请求才返回 editor-busy。截取、导入、标注、打开编辑器都不会隐式发送,也不覆盖同名输出。已有可编辑派生文档不能再次隐式套一层标记:用 edit 调整,或明确把扁平图片重新 import 为新底图。

投递到准确会话

gtmux screenshot target --pane %9 --session-id EXPECTED_SESSION_ID
gtmux screenshot send --image /tmp/my-task-shots/marked.png --target-ref TARGET_REF --request-id task-shot-00000001 --message-file /tmp/my-task-shots/note.txt
gtmux screenshot status task-shot-00000001

目标引用有效十分钟,绑定 session、home、客户端、pane 根进程与 tmux server 的启动身份。首期支持已核验的 managed Codex、DeepSeek Harness 原生绑定,其他客户端继续使用既有 gtmux send --attach,不新增向裸终端输入的回退。目标按需解析,不往常态会话列表刷新里增加进程扫描。

回执是带时间的最近一次观察:

状态含义
landed输入回执确认已进入对话。
active_turn_accepted当前轮次已接纳图片输入。
queued后台接受排队,尚未确认进入对话。
blocked / failed被拒绝或未取得输入确认前失败。
unknown无法确认是否已接受;保留请求 ID 排查,不自动重发。

这些都不代表 agent 已读或任务完成。status 只读持久回执,不恢复 thread,不声称之前 queued 的消息现在仍在排队。同 ID/同载荷不会悄悄再次发送;更换图片、说明或目标会返回冲突。过期目标为新提交重新解析,旧请求直接按 ID 查状态。

边界与落盘

请求最多十秒、JSON 256 KiB、单图 30 MiB/3200 万像素、500 个标记/10000 个路径点;预览长边最多 1600 像素。App 只接本用户 Unix 连接,核宿主进程与实例 nonce,通过已打开文件描述符传图,不接受任意原生输出路径;无 TCP、命令执行、剪贴板修改或隐式录屏权限申请。闲置时监听阻塞等待,最多两个并发请求槽位。超时、调用方断开或宿主停止后,请求失效并关闭连接;图片解码、渲染和文件读写离开 UI 线程。底层系统回调或文件系统调用可能无法中断,此时保留有界工作配额直到实际结束,新工作返回 native-busy,迟到结果不会再打开编辑器或发布产物。底层截取挂起时仍可查询 capabilities,但这不代表可以自动重发结果未知的投递。

调用方持有 PNG/preview/sidecar。产品管理的 capture-bridge 只存 socket、宿主身份和锁;capture-requests 存私有目标签名 key、哈希回执,不写图片或说明正文,目录最多 1000 项。满额会明确失败,不自动删未确认回执。本轮不自动迁移或删除已有归档。附件投递沿用既有 uploads 行为。

Linux 可读 CLI 帮助并使用受支持的投递逻辑,原生图片操作返回 platform-unsupported。真实录屏授权、真实窗口截取及签名安装验收,与合成图片/隔离 socket 测试分开记录。

同时编辑多张截图

上一张截图还开着时,再按 ⌥⌘4 就能截取新图。每个窗口独立保存图片、标注、附言和发送结果,最多同时打开八张;达到上限后,先保存或关闭一张即可继续。复制、保存或确认发送成功,只会关闭对应的窗口。

目标列表与菜单栏使用相同的会话标题。输入标题、项目名或窗格编号即可搜索,也支持缩写匹配;按 ↑/↓ 选择,回车确认,Esc 关闭列表。第二行显示 Agent 和 tmux 位置,便于区分同名会话。截图只在明确点击发送时投递;真正的审批请求仍需先处理。连接问题会单独提示,并保留截图和文字。

来源:docs/guides/agent-screenshots.zh.md(29f9eb0)· 在 GitHub 上编辑

← ccy.dev