fletchshot-mcp 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +193 -2
- package/dist/src/annotations.js +163 -0
- package/dist/src/annotations.js.map +1 -0
- package/dist/src/capture.js +68 -0
- package/dist/src/capture.js.map +1 -0
- package/dist/src/colors.js +50 -0
- package/dist/src/colors.js.map +1 -0
- package/dist/src/draft.js +54 -0
- package/dist/src/draft.js.map +1 -0
- package/dist/src/index.js +241 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/png.js +221 -0
- package/dist/src/png.js.map +1 -0
- package/dist/src/waitForReturn.js +68 -0
- package/dist/src/waitForReturn.js.map +1 -0
- package/dist/src/windowList.js +103 -0
- package/dist/src/windowList.js.map +1 -0
- package/package.json +46 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 FletchShot
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,194 @@
|
|
|
1
|
-
#
|
|
1
|
+
# FletchShot MCP (fletchshot-mcp)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An MCP server that lets a coding agent (Claude Code, Cursor, Codex, …) capture a
|
|
4
|
+
screenshot, draft an arrow/text/box/mosaic annotation on it, open it in
|
|
5
|
+
[FletchShot](https://fletchshot.app/agent.html?src=mcp) for a human to fix up, and receive back
|
|
6
|
+
the finished image once the human explicitly returns it.
|
|
7
|
+
|
|
8
|
+
This is a thin, local, stdio-only bridge. It never talks to the network, and it
|
|
9
|
+
never reads your screen or FletchShot's documents on its own — every image
|
|
10
|
+
only reaches the agent because a human pressed **"Return to agent"**
|
|
11
|
+
(⌘-Return) inside FletchShot.
|
|
12
|
+
|
|
13
|
+
macOS only. Requires [FletchShot](https://fletchshot.app/) (Mac App Store
|
|
14
|
+
build, bundle id `app.fletchshot.FletchShot`) to be installed, and Node.js 18+
|
|
15
|
+
to run this package.
|
|
16
|
+
|
|
17
|
+
> **Note:** drafts need a FletchShot version newer than 2.3.3, which is in App
|
|
18
|
+
> Store review. Older versions open the draft as a plain image without the
|
|
19
|
+
> Return button.
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
claude mcp add fletchshot -- npx -y fletchshot-mcp
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Cursor
|
|
28
|
+
|
|
29
|
+
Add to `.cursor/mcp.json` (project) or `~/.cursor/mcp.json` (global):
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
{
|
|
33
|
+
"mcpServers": {
|
|
34
|
+
"fletchshot": {
|
|
35
|
+
"type": "stdio",
|
|
36
|
+
"command": "npx",
|
|
37
|
+
"args": ["-y", "fletchshot-mcp"]
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Codex CLI
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
codex mcp add fletchshot -- npx -y fletchshot-mcp
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
or add to `~/.codex/config.toml` by hand:
|
|
50
|
+
|
|
51
|
+
```toml
|
|
52
|
+
[mcp_servers.fletchshot]
|
|
53
|
+
command = "npx"
|
|
54
|
+
args = ["-y", "fletchshot-mcp"]
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Required permission
|
|
58
|
+
|
|
59
|
+
The process that runs this server (your terminal, or whatever spawns it) needs
|
|
60
|
+
**Screen Recording** permission (System Settings → Privacy & Security → Screen
|
|
61
|
+
Recording), the same permission `screencapture` always needs. Window-mode
|
|
62
|
+
capture additionally shells out to `swift` (ships with Xcode Command Line
|
|
63
|
+
Tools) to enumerate on-screen windows; if `swift` isn't installed, `screen`
|
|
64
|
+
and `region` modes still work, and the tool will tell you to install Xcode
|
|
65
|
+
Command Line Tools (`xcode-select --install`) or use another mode.
|
|
66
|
+
|
|
67
|
+
No other permission, entitlement, or FletchShot setting is required — and
|
|
68
|
+
nothing is configured inside FletchShot's own Settings window for this (see
|
|
69
|
+
FletchShot's help page for why).
|
|
70
|
+
|
|
71
|
+
## Tools
|
|
72
|
+
|
|
73
|
+
1. **`capture`** — take a screenshot. `mode: "window"` matches a window by
|
|
74
|
+
app name and/or title substring (returns a candidate list instead of
|
|
75
|
+
capturing if there's no match or more than one); `mode: "screen"` captures
|
|
76
|
+
the whole screen; `mode: "region"` captures a screen-coordinate rectangle
|
|
77
|
+
after a delay (for menus/popovers, which can't be captured as a standalone
|
|
78
|
+
window — ask the human to open the menu within the delay). Returns the
|
|
79
|
+
file path, pixel size, scale (Retina = 2x, etc.), and the image itself
|
|
80
|
+
(unless it's too large to inline).
|
|
81
|
+
2. **`open_draft`** — take the path `capture` returned plus a list of simple
|
|
82
|
+
annotations (`arrow`, `text`, `rect`, `ellipse`, `mosaic`, `number`, all in
|
|
83
|
+
image-pixel, top-left-origin coordinates) and open it in FletchShot as an
|
|
84
|
+
editable draft. The human adjusts it, then presses **Return to agent**
|
|
85
|
+
(⌘-Return).
|
|
86
|
+
3. **`wait_for_return`** — wait until the human returns the draft (or a
|
|
87
|
+
timeout), then return the finished image.
|
|
88
|
+
|
|
89
|
+
Typical flow: `capture` → `open_draft` → (human edits, presses ⌘-Return) →
|
|
90
|
+
`wait_for_return`.
|
|
91
|
+
|
|
92
|
+
## Privacy
|
|
93
|
+
|
|
94
|
+
This server does not use the network at all (stdio transport only). Captured
|
|
95
|
+
screenshots and drafts are written to a temp directory on disk. The only path
|
|
96
|
+
by which an image can leave the machine is whatever the agent itself does
|
|
97
|
+
with the bytes it receives back from `wait_for_return` (e.g. send it to the
|
|
98
|
+
agent's own LLM backend) — and that only happens after a human has reviewed
|
|
99
|
+
the draft inside FletchShot and explicitly pressed "Return to agent".
|
|
100
|
+
FletchShot's own help page documents this in more detail:
|
|
101
|
+
<https://fletchshot.app/help.html?src=mcp#agent> (日本語: <https://fletchshot.app/help-ja.html?src=mcp#agent>).
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
# FletchShot MCP(日本語)
|
|
106
|
+
|
|
107
|
+
コーディングエージェント(Claude Code・Cursor・Codex など)が画面を撮り、矢印・文字・枠・
|
|
108
|
+
モザイクなどの注釈の下書きを作って [FletchShot](https://fletchshot.app/agent-ja.html?src=mcp) で開き、人が直して
|
|
109
|
+
「エージェントに返す」(⌘↩)を押したら仕上がり画像を受け取る——その橋渡しだけを行う MCP サーバー
|
|
110
|
+
です。
|
|
111
|
+
|
|
112
|
+
ローカルで完結する stdio 専用のサーバーで、通信は一切行いません。画像がエージェントへ渡るのは、
|
|
113
|
+
人が FletchShot 上で下書きを直し、明示的に「エージェントに返す」を押したときだけです。
|
|
114
|
+
|
|
115
|
+
macOS 専用です。[FletchShot](https://fletchshot.app/)(Mac App Store 版、バンドルID
|
|
116
|
+
`app.fletchshot.FletchShot`)のインストールと、このパッケージを動かす Node.js 18 以上が必要です。
|
|
117
|
+
|
|
118
|
+
> **注意:** 下書きを開くには、2.3.3 より新しい FletchShot(App Store の審査中)が必要です。
|
|
119
|
+
> それより前の版では、下書きは「返す」ボタンのない普通の画像として開きます。
|
|
120
|
+
|
|
121
|
+
## 導入
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
claude mcp add fletchshot -- npx -y fletchshot-mcp
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Cursor
|
|
128
|
+
|
|
129
|
+
`.cursor/mcp.json`(プロジェクト単位)か `~/.cursor/mcp.json`(全体)に追記します。
|
|
130
|
+
|
|
131
|
+
```json
|
|
132
|
+
{
|
|
133
|
+
"mcpServers": {
|
|
134
|
+
"fletchshot": {
|
|
135
|
+
"type": "stdio",
|
|
136
|
+
"command": "npx",
|
|
137
|
+
"args": ["-y", "fletchshot-mcp"]
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Codex CLI
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
codex mcp add fletchshot -- npx -y fletchshot-mcp
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
または `~/.codex/config.toml` に手で追記します。
|
|
150
|
+
|
|
151
|
+
```toml
|
|
152
|
+
[mcp_servers.fletchshot]
|
|
153
|
+
command = "npx"
|
|
154
|
+
args = ["-y", "fletchshot-mcp"]
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## 必要な許可
|
|
158
|
+
|
|
159
|
+
このサーバーを動かすプロセス(ターミナルなど、起動元)に **「画面収録」の許可**(システム設定 >
|
|
160
|
+
プライバシーとセキュリティ > 画面収録)が必要です。`screencapture` コマンドが常に必要とするのと
|
|
161
|
+
同じ許可です。ウィンドウ単体の撮影(`mode: "window"`)は、画面上のウィンドウ一覧を取るために
|
|
162
|
+
追加で `swift` コマンド(Xcode Command Line Tools 同梱)を呼びます。`swift` が無くても
|
|
163
|
+
`screen`・`region` モードは使えます(その場合はツールの戻り値で案内します)。導入に
|
|
164
|
+
`xcode-select --install` が必要な旨もそこで案内されます。
|
|
165
|
+
|
|
166
|
+
これ以外の許可・entitlement・FletchShot側の設定は不要です。FletchShotの設定画面にも、この
|
|
167
|
+
機能のための項目は置いていません(理由はFletchShotのヘルプページを参照してください)。
|
|
168
|
+
|
|
169
|
+
## ツール
|
|
170
|
+
|
|
171
|
+
1. **`capture`** — 画面を撮る。`mode: "window"` はアプリ名・ウィンドウタイトルの部分一致で
|
|
172
|
+
ウィンドウ単体を撮る(一致なし・複数一致なら撮らずに候補一覧を返す)。`mode: "screen"` は
|
|
173
|
+
画面全体。`mode: "region"` は画面座標の矩形を遅延つきで撮る(メニュー・ポップオーバー用。
|
|
174
|
+
ウィンドウ単体では撮れないため、遅延の間に人へメニューを開いてもらう)。戻り値はファイルパス・
|
|
175
|
+
ピクセルの幅高さ・倍率(Retinaなら2倍等)と、大きすぎない限り画像そのもの。
|
|
176
|
+
2. **`open_draft`** — `capture` が返したパスと、簡易な注釈(`arrow`・`text`・`rect`・
|
|
177
|
+
`ellipse`・`mosaic`・`number`。すべて画像ピクセル・左上原点で指定)を受け取り、FletchShotで
|
|
178
|
+
掴める下書きとして開く。人が直して「エージェントに返す」(⌘↩)を押す。
|
|
179
|
+
3. **`wait_for_return`** — 人が下書きを返す(または時間切れになる)まで待ち、仕上がり画像を
|
|
180
|
+
返す。
|
|
181
|
+
|
|
182
|
+
典型的な流れ: `capture` → `open_draft` →(人が直して⌘↩)→ `wait_for_return`。
|
|
183
|
+
|
|
184
|
+
## プライバシー
|
|
185
|
+
|
|
186
|
+
本サーバーは通信を一切行いません(stdioのみ)。撮影した画像・下書きはディスクの一時ディレクトリへ
|
|
187
|
+
書きます。画像が機外(エージェント自身のLLM基盤など)へ出うるのは、`wait_for_return` が返した
|
|
188
|
+
バイト列をエージェント側がどう使うか次第であり、それは人がFletchShot上で下書きを確認し、明示的に
|
|
189
|
+
「エージェントに返す」を押した後に限られます。詳細はFletchShotのヘルプページにも書いています:
|
|
190
|
+
<https://fletchshot.app/help-ja.html?src=mcp#agent>(English: <https://fletchshot.app/help.html?src=mcp#agent>)。
|
|
191
|
+
|
|
192
|
+
## License
|
|
193
|
+
|
|
194
|
+
MIT
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// エージェント向けの簡易な注釈記述 → FletchShot の下書きPNG形式v1(AnnotationArchive)への変換。
|
|
2
|
+
//
|
|
3
|
+
// 契約の正本: docs/plans/2026-11-12-FR-39-エージェント下書き.md「下書きの形式v1」節。
|
|
4
|
+
// Swift側の形は app/Sources/FletchShotCore/AnnotationArchive.swift・Annotation.swift
|
|
5
|
+
// (CGPoint→[x,y]・CGRect→[[x,y],[w,h]]は app/ 側で swift 実行し実機確認済み。本リポジトリのコメント参照)。
|
|
6
|
+
//
|
|
7
|
+
// 座標: エージェントは画像ピクセル空間・左上原点で指定する(手順1の実際の流れに合わせる)。
|
|
8
|
+
// ここで doc 座標(キャンバス pt 空間・左下原点・y上向き)へ変換する。
|
|
9
|
+
import { randomUUID } from "node:crypto";
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import { resolveColor } from "./colors.js";
|
|
12
|
+
// 座標は {x,y} オブジェクトのほか、[x,y] の2要素配列でも受け付ける(エージェントが配列で返しがちなため)。
|
|
13
|
+
// zodのunion+transformで内部表現を{x,y}に正規化するので、呼び出し側(convertAnnotation等)は常に
|
|
14
|
+
// オブジェクト形を前提にでき、JSON Schema側(io: "input"扱い)には両方の形がunionとして出る。
|
|
15
|
+
const PointSchema = z
|
|
16
|
+
.union([z.object({ x: z.number(), y: z.number() }), z.tuple([z.number(), z.number()])])
|
|
17
|
+
.transform((v) => (Array.isArray(v) ? { x: v[0], y: v[1] } : v));
|
|
18
|
+
export const ArrowInputSchema = z.object({
|
|
19
|
+
type: z.literal("arrow"),
|
|
20
|
+
from: PointSchema.describe("矢印の付け根(細い側)。画像ピクセル・左上原点。{x,y}か[x,y]のどちらでも指定できる"),
|
|
21
|
+
to: PointSchema.describe("矢印の先(矢頭)。対象の中心ではなく、対象の文字に近い側の端を指すこと(手順1の知見)。{x,y}か[x,y]のどちらでも指定できる"),
|
|
22
|
+
color: z.string().optional().describe('色名(red/blue/green/yellow/orange/purple/pink/black/white/gray)か "#rrggbb"。省略時は赤'),
|
|
23
|
+
});
|
|
24
|
+
export const TextInputSchema = z.object({
|
|
25
|
+
type: z.literal("text"),
|
|
26
|
+
at: PointSchema.describe("文字ブロック左上。画像ピクセル・左上原点。対象に重ねないこと。{x,y}か[x,y]のどちらでも指定できる"),
|
|
27
|
+
text: z.string().min(1),
|
|
28
|
+
width: z.number().positive().optional().describe("折り返し幅(画像ピクセル)。省略時は折り返さない"),
|
|
29
|
+
color: z.string().optional(),
|
|
30
|
+
});
|
|
31
|
+
export const RectInputSchema = z.object({
|
|
32
|
+
type: z.literal("rect"),
|
|
33
|
+
x: z.number(),
|
|
34
|
+
y: z.number(),
|
|
35
|
+
w: z.number().positive(),
|
|
36
|
+
h: z.number().positive(),
|
|
37
|
+
color: z.string().optional(),
|
|
38
|
+
});
|
|
39
|
+
export const EllipseInputSchema = z.object({
|
|
40
|
+
type: z.literal("ellipse"),
|
|
41
|
+
x: z.number(),
|
|
42
|
+
y: z.number(),
|
|
43
|
+
w: z.number().positive(),
|
|
44
|
+
h: z.number().positive(),
|
|
45
|
+
color: z.string().optional(),
|
|
46
|
+
});
|
|
47
|
+
export const MosaicInputSchema = z.object({
|
|
48
|
+
type: z.literal("mosaic"),
|
|
49
|
+
x: z.number(),
|
|
50
|
+
y: z.number(),
|
|
51
|
+
w: z.number().positive(),
|
|
52
|
+
h: z.number().positive(),
|
|
53
|
+
});
|
|
54
|
+
export const NumberInputSchema = z.object({
|
|
55
|
+
type: z.literal("number"),
|
|
56
|
+
at: PointSchema.describe("番号スタンプの中心。画像ピクセル・左上原点。{x,y}か[x,y]のどちらでも指定できる"),
|
|
57
|
+
n: z.number().int().positive(),
|
|
58
|
+
color: z.string().optional(),
|
|
59
|
+
});
|
|
60
|
+
export const AnnotationInputSchema = z.discriminatedUnion("type", [
|
|
61
|
+
ArrowInputSchema,
|
|
62
|
+
TextInputSchema,
|
|
63
|
+
RectInputSchema,
|
|
64
|
+
EllipseInputSchema,
|
|
65
|
+
MosaicInputSchema,
|
|
66
|
+
NumberInputSchema,
|
|
67
|
+
]);
|
|
68
|
+
function colorJson(rgba) {
|
|
69
|
+
return { r: rgba.r, g: rgba.g, b: rgba.b, a: rgba.a };
|
|
70
|
+
}
|
|
71
|
+
/** 画像ピクセル座標(左上原点)→ ドキュメント座標(左下原点・pt・[x,y]配列)に変換する。 */
|
|
72
|
+
export function toDocPoint(px, py, geo) {
|
|
73
|
+
return [px / geo.scale, (geo.heightPx - py) / geo.scale];
|
|
74
|
+
}
|
|
75
|
+
function toDocLength(px, geo) {
|
|
76
|
+
return px / geo.scale;
|
|
77
|
+
}
|
|
78
|
+
/** 1件の簡易注釈入力を AnnotationArchive の封筒 {type,id,payload} へ変換する。 */
|
|
79
|
+
export function convertAnnotation(input, geo) {
|
|
80
|
+
const id = randomUUID();
|
|
81
|
+
switch (input.type) {
|
|
82
|
+
case "arrow":
|
|
83
|
+
return {
|
|
84
|
+
type: "arrow",
|
|
85
|
+
id,
|
|
86
|
+
payload: {
|
|
87
|
+
start: toDocPoint(input.from.x, input.from.y, geo),
|
|
88
|
+
end: toDocPoint(input.to.x, input.to.y, geo),
|
|
89
|
+
color: colorJson(resolveColor(input.color)),
|
|
90
|
+
sizeFactor: 1.0,
|
|
91
|
+
style: "fill",
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
case "text": {
|
|
95
|
+
const payload = {
|
|
96
|
+
topLeft: toDocPoint(input.at.x, input.at.y, geo),
|
|
97
|
+
string: input.text,
|
|
98
|
+
color: colorJson(resolveColor(input.color)),
|
|
99
|
+
sizeFactor: 1.0,
|
|
100
|
+
fontStyle: "standard",
|
|
101
|
+
};
|
|
102
|
+
if (input.width !== undefined) {
|
|
103
|
+
payload.wrapWidth = toDocLength(input.width, geo);
|
|
104
|
+
}
|
|
105
|
+
return { type: "text", id, payload };
|
|
106
|
+
}
|
|
107
|
+
case "rect":
|
|
108
|
+
case "ellipse":
|
|
109
|
+
return {
|
|
110
|
+
type: "shape",
|
|
111
|
+
id,
|
|
112
|
+
payload: {
|
|
113
|
+
kind: input.type,
|
|
114
|
+
start: toDocPoint(input.x, input.y, geo),
|
|
115
|
+
end: toDocPoint(input.x + input.w, input.y + input.h, geo),
|
|
116
|
+
color: colorJson(resolveColor(input.color)),
|
|
117
|
+
sizeFactor: 1.0,
|
|
118
|
+
lineStyle: "solid",
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
case "mosaic": {
|
|
122
|
+
// MosaicAnnotation.rect は CGRect = [[originX,originY],[width,height]](originは左下隅・pt)。
|
|
123
|
+
// 画像ピクセルの下端(y+h)がdoc空間では小さいy(=rectのorigin.y)になる。
|
|
124
|
+
const originX = toDocLength(input.x, geo);
|
|
125
|
+
const originY = (geo.heightPx - input.y - input.h) / geo.scale;
|
|
126
|
+
return {
|
|
127
|
+
type: "mosaic",
|
|
128
|
+
id,
|
|
129
|
+
payload: {
|
|
130
|
+
rect: [
|
|
131
|
+
[originX, originY],
|
|
132
|
+
[toDocLength(input.w, geo), toDocLength(input.h, geo)],
|
|
133
|
+
],
|
|
134
|
+
cellSize: 10,
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
case "number":
|
|
139
|
+
return {
|
|
140
|
+
type: "stamp",
|
|
141
|
+
id,
|
|
142
|
+
payload: {
|
|
143
|
+
center: toDocPoint(input.at.x, input.at.y, geo),
|
|
144
|
+
glyph: "number",
|
|
145
|
+
sizeFactor: 1.0,
|
|
146
|
+
number: input.n,
|
|
147
|
+
color: colorJson(resolveColor(input.color)),
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
export const DRAFT_MARKER_KEY = "fletchshotDraft";
|
|
153
|
+
export const SCHEMA_VERSION = 1;
|
|
154
|
+
/** annotations配列とジオメトリから、下書きPNGのComment(iTXt)に入れるJSON文字列を組み立てる。 */
|
|
155
|
+
export function buildDraftCommentJson(annotations, geo) {
|
|
156
|
+
const archive = {
|
|
157
|
+
[DRAFT_MARKER_KEY]: 1,
|
|
158
|
+
schemaVersion: SCHEMA_VERSION,
|
|
159
|
+
annotations: annotations.map((a) => convertAnnotation(a, geo)),
|
|
160
|
+
};
|
|
161
|
+
return JSON.stringify(archive);
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=annotations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annotations.js","sourceRoot":"","sources":["../../src/annotations.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,EAAE;AACF,8DAA8D;AAC9D,gFAAgF;AAChF,+EAA+E;AAC/E,EAAE;AACF,iDAAiD;AACjD,0CAA0C;AAE1C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAa,MAAM,aAAa,CAAC;AAEtD,8DAA8D;AAC9D,sEAAsE;AACtE,8DAA8D;AAC9D,MAAM,WAAW,GAAG,CAAC;KAClB,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAA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,EAAE,CAAC;QACrB,aAAa,EAAE,cAAc;QAC7B,WAAW,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;KAC/D,CAAC;IACF,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// `capture` ツールの実装本体。ウィンドウ単体・画面全体・遅延つき範囲(メニュー用)の3通りで
|
|
2
|
+
// `screencapture` を呼び、専用の保存先ディレクトリへPNGを書く。
|
|
3
|
+
//
|
|
4
|
+
// 参照: docs/plans/2026-11-12-FR-39-エージェント下書き.md 手順3の決め事「MCPのツール」1.capture、
|
|
5
|
+
// および手順1「途中で分かったこと」(ウィンドウ単体で撮る・矢頭は文字側の端・メニューは遅延撮影+
|
|
6
|
+
// 関係ない部分にモザイク)。
|
|
7
|
+
import { spawnSync } from "node:child_process";
|
|
8
|
+
import { mkdirSync, readFileSync, statSync } from "node:fs";
|
|
9
|
+
import { tmpdir } from "node:os";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { parseChunks, readIhdr, readScale } from "./png.js";
|
|
12
|
+
import { findWindows, listWindows } from "./windowList.js";
|
|
13
|
+
export function captureDir() {
|
|
14
|
+
const dir = join(tmpdir(), "fletchshot-mcp-captures");
|
|
15
|
+
mkdirSync(dir, { recursive: true });
|
|
16
|
+
return dir;
|
|
17
|
+
}
|
|
18
|
+
function newCapturePath() {
|
|
19
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "-");
|
|
20
|
+
const rand = Math.random().toString(36).slice(2, 8);
|
|
21
|
+
return join(captureDir(), `capture_${stamp}_${rand}.png`);
|
|
22
|
+
}
|
|
23
|
+
function runScreencapture(args) {
|
|
24
|
+
const result = spawnSync("screencapture", args, { encoding: "utf8", timeout: 30_000 });
|
|
25
|
+
if (result.status !== 0) {
|
|
26
|
+
throw new Error(`screencapture に失敗しました(終了コード ${result.status}): ${result.stderr || "(詳細なし)"}\n` +
|
|
27
|
+
"「画面収録」の許可(システム設定 > プライバシーとセキュリティ)がこのターミナル/プロセスに" +
|
|
28
|
+
"付与されているか確認してください。");
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function readCaptureMeta(path) {
|
|
32
|
+
const buf = readFileSync(path);
|
|
33
|
+
const chunks = parseChunks(buf);
|
|
34
|
+
const { width, height } = readIhdr(chunks);
|
|
35
|
+
const scale = readScale(chunks);
|
|
36
|
+
return { path, widthPx: width, heightPx: height, scale };
|
|
37
|
+
}
|
|
38
|
+
/** mode: "screen" */
|
|
39
|
+
export function captureScreen() {
|
|
40
|
+
const path = newCapturePath();
|
|
41
|
+
runScreencapture(["-x", path]);
|
|
42
|
+
return { status: "captured", meta: readCaptureMeta(path) };
|
|
43
|
+
}
|
|
44
|
+
/** mode: "window"(アプリ名/タイトルの部分一致で1件に絞れたときだけ撮る) */
|
|
45
|
+
export function captureWindowByMatch(app, title) {
|
|
46
|
+
const all = listWindows();
|
|
47
|
+
const matches = findWindows(all, app, title);
|
|
48
|
+
if (matches.length === 0) {
|
|
49
|
+
return { status: "no_match", candidates: all };
|
|
50
|
+
}
|
|
51
|
+
if (matches.length > 1) {
|
|
52
|
+
return { status: "ambiguous", candidates: matches };
|
|
53
|
+
}
|
|
54
|
+
const path = newCapturePath();
|
|
55
|
+
runScreencapture(["-x", "-o", "-l", String(matches[0].id), path]);
|
|
56
|
+
return { status: "captured", meta: readCaptureMeta(path) };
|
|
57
|
+
}
|
|
58
|
+
/** mode: "region"(メニュー撮影用。delaySeconds以内に対象を前面へ出してもらう) */
|
|
59
|
+
export function captureRegion(x, y, w, h, delaySeconds) {
|
|
60
|
+
const path = newCapturePath();
|
|
61
|
+
runScreencapture(["-x", "-T", String(delaySeconds), "-R", `${x},${y},${w},${h}`, path]);
|
|
62
|
+
return { status: "captured", meta: readCaptureMeta(path) };
|
|
63
|
+
}
|
|
64
|
+
/** 画像の大きさ(バイト)。大きすぎる場合にMCPのimage contentへ埋め込むかどうかの判断に使う。 */
|
|
65
|
+
export function fileSizeBytes(path) {
|
|
66
|
+
return statSync(path).size;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=capture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capture.js","sourceRoot":"","sources":["../../src/capture.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,2CAA2C;AAC3C,EAAE;AACF,0EAA0E;AAC1E,mDAAmD;AACnD,gBAAgB;AAEhB,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,WAAW,EAAmB,MAAM,iBAAiB,CAAC;AAE5E,MAAM,UAAU,UAAU;IACxB,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,yBAAyB,CAAC,CAAC;IACtD,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACpC,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,cAAc;IACrB,MAAM,KAAK,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IAC7D,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACpD,OAAO,IAAI,CAAC,UAAU,EAAE,EAAE,WAAW,KAAK,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-11-12-FR-39-エージェント下書き.md 手順3の決め事)。
|
|
3
|
+
// AnnotationArchive.swift の CodableColor は 0..1 の sRGB r/g/b/a。
|
|
4
|
+
export const DEFAULT_COLOR = { r: 1, g: 0, b: 0, a: 1 };
|
|
5
|
+
const NAMED_COLORS = {
|
|
6
|
+
red: { r: 1, g: 0, b: 0, a: 1 },
|
|
7
|
+
blue: { r: 0.1, g: 0.35, b: 0.95, a: 1 },
|
|
8
|
+
green: { r: 0.1, g: 0.7, b: 0.25, a: 1 },
|
|
9
|
+
yellow: { r: 1, g: 0.85, b: 0.1, a: 1 },
|
|
10
|
+
orange: { r: 1, g: 0.55, b: 0.1, a: 1 },
|
|
11
|
+
purple: { r: 0.6, g: 0.2, b: 0.9, a: 1 },
|
|
12
|
+
pink: { r: 1, g: 0.3, b: 0.6, a: 1 },
|
|
13
|
+
black: { r: 0, g: 0, b: 0, a: 1 },
|
|
14
|
+
white: { r: 1, g: 1, b: 1, a: 1 },
|
|
15
|
+
gray: { r: 0.5, g: 0.5, b: 0.5, a: 1 },
|
|
16
|
+
grey: { r: 0.5, g: 0.5, b: 0.5, a: 1 },
|
|
17
|
+
cyan: { r: 0.1, g: 0.8, b: 0.9, a: 1 },
|
|
18
|
+
magenta: { r: 0.9, g: 0.1, b: 0.8, a: 1 },
|
|
19
|
+
};
|
|
20
|
+
function parseHex(hex) {
|
|
21
|
+
const m = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.exec(hex);
|
|
22
|
+
if (!m)
|
|
23
|
+
return undefined;
|
|
24
|
+
let s = m[1];
|
|
25
|
+
if (s.length === 3 || s.length === 4) {
|
|
26
|
+
s = s
|
|
27
|
+
.split("")
|
|
28
|
+
.map((c) => c + c)
|
|
29
|
+
.join("");
|
|
30
|
+
}
|
|
31
|
+
const r = parseInt(s.slice(0, 2), 16) / 255;
|
|
32
|
+
const g = parseInt(s.slice(2, 4), 16) / 255;
|
|
33
|
+
const b = parseInt(s.slice(4, 6), 16) / 255;
|
|
34
|
+
const a = s.length >= 8 ? parseInt(s.slice(6, 8), 16) / 255 : 1;
|
|
35
|
+
return { r, g, b, a };
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 色名または #hex 文字列を RGBA(0..1) に解決する。未指定・未知の表記は既定の赤を返す。
|
|
39
|
+
*/
|
|
40
|
+
export function resolveColor(input) {
|
|
41
|
+
if (!input)
|
|
42
|
+
return DEFAULT_COLOR;
|
|
43
|
+
const trimmed = input.trim();
|
|
44
|
+
if (trimmed.startsWith("#")) {
|
|
45
|
+
return parseHex(trimmed) ?? DEFAULT_COLOR;
|
|
46
|
+
}
|
|
47
|
+
const named = NAMED_COLORS[trimmed.toLowerCase()];
|
|
48
|
+
return named ?? DEFAULT_COLOR;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=colors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colors.js","sourceRoot":"","sources":["../../src/colors.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,sDAAsD;AACtD,gEAAgE;AAShE,MAAM,CAAC,MAAM,aAAa,GAAS,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AAE9D,MAAM,YAAY,GAAyB;IACzC,GAAG,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;IAC/B,IAAI,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE;IACxC,KAAK,EAAE,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE;IACxC,MA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;IAC7B,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC5B,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,aAAa,CAAC;IAC5C,CAAC;IACD,MAAM,KAAK,GAAG,YAAY,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IAClD,OAAO,KAAK,IAAI,aAAa,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// `open_draft` ツールの実装本体。
|
|
2
|
+
//
|
|
3
|
+
// 流れ(docs/plans/2026-11-12-FR-39-エージェント下書き.md「下書きの形式v1」「MCPのツール」2.open_draft):
|
|
4
|
+
// 1. imagePathのPNGからpHYs(倍率)とIHDR(高さ)を読む
|
|
5
|
+
// 2. エージェントの簡易な注釈記述を doc 座標へ変換し、AnnotationArchive 封筒 + 目印キーのJSONを作る
|
|
6
|
+
// 3. ベース画像(注釈は焼かない)のバイト列へ、そのJSONをiTXt "Comment"として埋め込み、outputPathへ書く
|
|
7
|
+
// 4. `open -b app.fletchshot.FletchShot <outputPath>` でFletchShotを開く(バンドルIDで呼ぶ。
|
|
8
|
+
// 名前解決だと古いビルドに届くことがあるため——手順1で実機確認済みの不具合)
|
|
9
|
+
import { spawnSync } from "node:child_process";
|
|
10
|
+
import { dirname, extname, join, basename } from "node:path";
|
|
11
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
12
|
+
import { parseChunks, readIhdr, readScale, embedComment } from "./png.js";
|
|
13
|
+
import { buildDraftCommentJson } from "./annotations.js";
|
|
14
|
+
export const FLETCHSHOT_BUNDLE_ID = "app.fletchshot.FletchShot";
|
|
15
|
+
export function defaultDraftPath(imagePath) {
|
|
16
|
+
const dir = dirname(imagePath);
|
|
17
|
+
const ext = extname(imagePath) || ".png";
|
|
18
|
+
const base = basename(imagePath, ext);
|
|
19
|
+
return join(dir, `${base}_draft${ext}`);
|
|
20
|
+
}
|
|
21
|
+
export function readImageGeometry(imagePath) {
|
|
22
|
+
const buf = readFileSync(imagePath);
|
|
23
|
+
const chunks = parseChunks(buf);
|
|
24
|
+
const { width, height } = readIhdr(chunks);
|
|
25
|
+
const scale = readScale(chunks);
|
|
26
|
+
return { geo: { scale, heightPx: height }, widthPx: width, buf };
|
|
27
|
+
}
|
|
28
|
+
/** 下書きPNGを作って書き出す(openは呼ばない。テストしやすいよう分離)。 */
|
|
29
|
+
export function writeDraft(imagePath, annotations, outputPath) {
|
|
30
|
+
const { geo, widthPx, buf } = readImageGeometry(imagePath);
|
|
31
|
+
const commentJson = buildDraftCommentJson(annotations, geo);
|
|
32
|
+
const draftBytes = embedComment(buf, commentJson);
|
|
33
|
+
const draftPath = outputPath ?? defaultDraftPath(imagePath);
|
|
34
|
+
writeFileSync(draftPath, draftBytes);
|
|
35
|
+
return {
|
|
36
|
+
draftPath,
|
|
37
|
+
widthPx,
|
|
38
|
+
heightPx: geo.heightPx,
|
|
39
|
+
scale: geo.scale,
|
|
40
|
+
annotationCount: annotations.length,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** FletchShotをバンドルIDで開く(`open -b`)。失敗しても例外は投げず結果を返す(呼び出し側がメッセージ化)。 */
|
|
44
|
+
export function openInFletchShot(path) {
|
|
45
|
+
const result = spawnSync("open", ["-b", FLETCHSHOT_BUNDLE_ID, path], {
|
|
46
|
+
encoding: "utf8",
|
|
47
|
+
timeout: 15_000,
|
|
48
|
+
});
|
|
49
|
+
if (result.status !== 0) {
|
|
50
|
+
return { ok: false, stderr: result.stderr || `open終了コード ${result.status}` };
|
|
51
|
+
}
|
|
52
|
+
return { ok: true };
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=draft.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"draft.js","sourceRoot":"","sources":["../../src/draft.ts"],"names":[],"mappings":"AAAA,yBAAyB;AACzB,EAAE;AACF,+EAA+E;AAC/E,0CAA0C;AAC1C,qEAAqE;AACrE,sEAAsE;AACtE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