mercury-agent 0.5.0 → 0.5.2

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.
Files changed (125) hide show
  1. package/README.md +452 -451
  2. package/container/Dockerfile +127 -127
  3. package/container/Dockerfile.base +109 -109
  4. package/container/Dockerfile.power +17 -17
  5. package/container/agent-package.json +8 -8
  6. package/container/build.sh +54 -54
  7. package/docs/ROADMAP.md +3 -4
  8. package/docs/archive/summarization/2026-07-02-recent-dev-summary.md +71 -0
  9. package/docs/auth/dashboard.md +28 -28
  10. package/docs/auth/overview.md +109 -109
  11. package/docs/auth/whatsapp.md +173 -173
  12. package/docs/authoring-profiles.md +174 -174
  13. package/docs/configuration.md +54 -54
  14. package/docs/container-lifecycle.md +349 -349
  15. package/docs/{bugs/bwrap-privileged-linux-docker.md → debug/major/2026-07-02-bwrap-privileged-linux-docker.md} +21 -1
  16. package/docs/{bugs/e2big-prompt-delivery-fix.md → debug/major/2026-07-02-e2big-prompt-delivery-fix.md} +27 -1
  17. package/docs/{bugs/registry-pull-no-local-fallback.md → debug/major/2026-07-02-registry-pull-no-local-fallback.md} +27 -1
  18. package/docs/debug/summarization/2026-07-02-common-bug-patterns.md +72 -0
  19. package/docs/deployment.md +199 -199
  20. package/docs/extensions.md +375 -375
  21. package/docs/graceful-shutdown.md +62 -62
  22. package/docs/kb-distillation.md +77 -77
  23. package/docs/media/overview.md +140 -140
  24. package/docs/media/whatsapp.md +171 -171
  25. package/docs/memory.md +137 -137
  26. package/docs/permissions.md +217 -217
  27. package/docs/pipeline.md +228 -228
  28. package/docs/prd-chat-memory.md +76 -76
  29. package/docs/prd-config-load.md +82 -82
  30. package/docs/rate-limiting.md +229 -229
  31. package/docs/runbooks/publish-checklist.md +9 -1
  32. package/docs/scheduler.md +288 -288
  33. package/docs/setup-discord.md +100 -100
  34. package/docs/setup-slack.md +119 -119
  35. package/docs/setup-whatsapp.md +94 -94
  36. package/docs/subagents.md +166 -166
  37. package/docs/web-search.md +62 -62
  38. package/examples/extensions/README.md +12 -12
  39. package/examples/extensions/charts/index.ts +13 -13
  40. package/examples/extensions/charts/skill/SKILL.md +98 -98
  41. package/examples/extensions/gws/README.md +52 -52
  42. package/examples/extensions/gws/skill/SKILL.md +57 -57
  43. package/examples/extensions/gws/skill/references/calendar.md +101 -101
  44. package/examples/extensions/gws/skill/references/docs.md +65 -65
  45. package/examples/extensions/gws/skill/references/drive.md +79 -79
  46. package/examples/extensions/gws/skill/references/gmail.md +85 -85
  47. package/examples/extensions/gws/skill/references/sheets.md +60 -60
  48. package/examples/extensions/napkin/skill/SKILL.md +728 -728
  49. package/examples/extensions/pdf/skill/LICENSE.txt +30 -30
  50. package/examples/extensions/pdf/skill/SKILL.md +314 -314
  51. package/examples/extensions/pdf/skill/forms.md +294 -294
  52. package/examples/extensions/pdf/skill/reference.md +611 -611
  53. package/examples/extensions/pdf/skill/scripts/check_bounding_boxes.py +65 -65
  54. package/examples/extensions/pdf/skill/scripts/check_fillable_fields.py +11 -11
  55. package/examples/extensions/pdf/skill/scripts/convert_pdf_to_images.py +33 -33
  56. package/examples/extensions/pdf/skill/scripts/create_validation_image.py +37 -37
  57. package/examples/extensions/pdf/skill/scripts/extract_form_field_info.py +122 -122
  58. package/examples/extensions/pdf/skill/scripts/extract_form_structure.py +115 -115
  59. package/examples/extensions/pdf/skill/scripts/fill_fillable_fields.py +98 -98
  60. package/examples/extensions/pdf/skill/scripts/fill_pdf_form_with_annotations.py +107 -107
  61. package/examples/extensions/permission-guard/index.ts +65 -65
  62. package/examples/extensions/pinchtab/skill/SKILL.md +224 -224
  63. package/examples/extensions/pinchtab/skill/TRUST.md +69 -69
  64. package/examples/extensions/pinchtab/skill/references/api.md +297 -297
  65. package/examples/extensions/pinchtab/skill/references/env.md +45 -45
  66. package/examples/extensions/pinchtab/skill/references/profiles.md +107 -107
  67. package/examples/extensions/tradestation/host/refresh.ts +102 -102
  68. package/examples/extensions/tradestation/index.ts +153 -153
  69. package/examples/extensions/tradestation/skill/SKILL.md +67 -67
  70. package/examples/extensions/voice-synth/index.ts +94 -94
  71. package/examples/extensions/voice-synth/skill/SKILL.md +38 -38
  72. package/examples/extensions/voice-transcribe/requirements.txt +8 -8
  73. package/examples/extensions/voice-transcribe/scripts/transcribe.py +179 -179
  74. package/examples/extensions/voice-transcribe/skill/SKILL.md +53 -53
  75. package/examples/extensions/yahoo-mail/cli/package.json +13 -13
  76. package/examples/extensions/yahoo-mail/skill/SKILL.md +78 -78
  77. package/package.json +106 -106
  78. package/resources/agents/explore.md +50 -50
  79. package/resources/agents/worker.md +24 -24
  80. package/resources/connection-env-vars.json +25 -25
  81. package/resources/pi-extensions/subagent/agents.ts +126 -126
  82. package/resources/pi-extensions/subagent/index.ts +964 -964
  83. package/resources/profiles/coding/AGENTS.md +43 -43
  84. package/resources/profiles/coding/mercury-profile.yaml +15 -15
  85. package/resources/profiles/general/AGENTS.md +31 -31
  86. package/resources/profiles/general/mercury-profile.yaml +15 -15
  87. package/resources/profiles/research/AGENTS.md +40 -40
  88. package/resources/profiles/research/mercury-profile.yaml +15 -15
  89. package/resources/skills/config/SKILL.md +25 -25
  90. package/resources/skills/context/SKILL.md +33 -33
  91. package/resources/skills/conversation-recap/SKILL.md +19 -19
  92. package/resources/skills/mutes/SKILL.md +31 -31
  93. package/resources/skills/permissions/SKILL.md +19 -19
  94. package/resources/skills/preferences/SKILL.md +31 -31
  95. package/resources/skills/recall/SKILL.md +24 -24
  96. package/resources/skills/roles/SKILL.md +18 -18
  97. package/resources/skills/spaces/SKILL.md +18 -18
  98. package/resources/skills/tasks/SKILL.md +45 -45
  99. package/resources/templates/AGENTS.md +157 -157
  100. package/resources/templates/env.template +38 -38
  101. package/resources/templates/mercury.example.yaml +99 -99
  102. package/src/agent/container-entry.ts +1 -1
  103. package/src/agent/container-runner.ts +1345 -1346
  104. package/src/cli/mercury.ts +39 -7
  105. package/src/cli/mrctl.ts +636 -636
  106. package/src/config-file.ts +540 -540
  107. package/src/config.ts +339 -339
  108. package/src/core/api.ts +125 -125
  109. package/src/core/caller-token.ts +101 -101
  110. package/src/core/permissions.ts +228 -228
  111. package/src/core/profiles.ts +271 -271
  112. package/src/core/routes/capability.ts +70 -70
  113. package/src/core/routes/index.ts +15 -15
  114. package/src/core/runtime.ts +1530 -1530
  115. package/src/dashboard/index.html +729 -729
  116. package/src/extensions/api.ts +273 -273
  117. package/src/extensions/loader.ts +286 -286
  118. package/src/extensions/types.ts +517 -517
  119. package/src/main.ts +605 -605
  120. package/docs/pending-updates/applicative-profiles.md +0 -15
  121. package/docs/pending-updates/caller-bound-capability-token.md +0 -15
  122. package/docs/pending-updates/dm-auto-space.md +0 -15
  123. /package/docs/archive/{2026-07-01-applicative-profiles.md → applicative-profiles/2026-07-01-applicative-profiles.md} +0 -0
  124. /package/docs/archive/{2026-07-01-caller-bound-capability-token.md → applicative-profiles/2026-07-01-caller-bound-capability-token.md} +0 -0
  125. /package/docs/archive/{2026-07-01-dm-auto-space.md → applicative-profiles/2026-07-01-dm-auto-space.md} +0 -0
@@ -1,297 +1,297 @@
1
- # Pinchtab API Reference
2
-
3
- Base URL for all examples: `http://localhost:9867`
4
-
5
- > **CLI alternative:** All endpoints have CLI equivalents. Use `pinchtab help` for the full list. Examples are shown as `# CLI:` comments below.
6
-
7
- ## Navigate
8
-
9
- ```bash
10
- # CLI: pinchtab nav https://example.com [--new-tab] [--block-images]
11
- curl -X POST /navigate \
12
- -H 'Content-Type: application/json' \
13
- -d '{"url": "https://example.com"}'
14
-
15
- # With options: custom timeout, block images, open in new tab
16
- curl -X POST /navigate \
17
- -H 'Content-Type: application/json' \
18
- -d '{"url": "https://example.com", "timeout": 60, "blockImages": true, "newTab": true}'
19
- ```
20
-
21
- ## Snapshot (accessibility tree)
22
-
23
- ```bash
24
- # CLI: pinchtab snap [-i] [-c] [-d] [-s main] [--max-tokens 2000]
25
- # Full tree
26
- curl /snapshot
27
-
28
- # Interactive elements only (buttons, links, inputs) — much smaller
29
- curl "/snapshot?filter=interactive"
30
-
31
- # Limit depth
32
- curl "/snapshot?depth=5"
33
-
34
- # Smart diff — only changes since last snapshot (massive token savings)
35
- curl "/snapshot?diff=true"
36
-
37
- # Text format — indented tree, ~40-60% fewer tokens than JSON
38
- curl "/snapshot?format=text"
39
-
40
- # Compact format — one-line-per-node, 56-64% fewer tokens than JSON (recommended)
41
- curl "/snapshot?format=compact"
42
-
43
- # YAML format
44
- curl "/snapshot?format=yaml"
45
-
46
- # Scope to CSS selector (e.g. main content only)
47
- curl "/snapshot?selector=main"
48
-
49
- # Truncate to ~N tokens
50
- curl "/snapshot?maxTokens=2000"
51
-
52
- # Combine for maximum efficiency
53
- curl "/snapshot?format=compact&selector=main&maxTokens=2000&filter=interactive"
54
-
55
- # Disable animations before capture
56
- curl "/snapshot?noAnimations=true"
57
-
58
- # Write to file
59
- curl "/snapshot?output=file&path=/tmp/snapshot.json"
60
- ```
61
-
62
- Returns flat JSON array of nodes with `ref`, `role`, `name`, `depth`, `value`, `nodeId`.
63
-
64
- **Token optimization**: Use `?format=compact` for best token efficiency. Add `?filter=interactive` for action-oriented tasks (~75% fewer nodes). Use `?selector=main` to scope to relevant content. Use `?maxTokens=2000` to cap output. Use `?diff=true` on multi-step workflows to see only changes. Combine all params freely.
65
-
66
- ## Act on elements
67
-
68
- ```bash
69
- # CLI: pinchtab click e5 / pinchtab type e12 hello / pinchtab press Enter
70
- # Click by ref
71
- curl -X POST /action -H 'Content-Type: application/json' \
72
- -d '{"kind": "click", "ref": "e5"}'
73
-
74
- # Type into focused element (click first, then type)
75
- curl -X POST /action -H 'Content-Type: application/json' \
76
- -d '{"kind": "click", "ref": "e12"}'
77
- curl -X POST /action -H 'Content-Type: application/json' \
78
- -d '{"kind": "type", "ref": "e12", "text": "hello world"}'
79
-
80
- # Press a key
81
- curl -X POST /action -H 'Content-Type: application/json' \
82
- -d '{"kind": "press", "key": "Enter"}'
83
-
84
- # Focus an element
85
- curl -X POST /action -H 'Content-Type: application/json' \
86
- -d '{"kind": "focus", "ref": "e3"}'
87
-
88
- # Fill (set value directly, no keystrokes)
89
- curl -X POST /action -H 'Content-Type: application/json' \
90
- -d '{"kind": "fill", "selector": "#email", "text": "user@example.com"}'
91
-
92
- # Hover (trigger dropdowns/tooltips)
93
- curl -X POST /action -H 'Content-Type: application/json' \
94
- -d '{"kind": "hover", "ref": "e8"}'
95
-
96
- # Select dropdown option (by value or visible text)
97
- curl -X POST /action -H 'Content-Type: application/json' \
98
- -d '{"kind": "select", "ref": "e10", "value": "option2"}'
99
-
100
- # Scroll to element
101
- curl -X POST /action -H 'Content-Type: application/json' \
102
- -d '{"kind": "scroll", "ref": "e20"}'
103
-
104
- # Scroll by pixels (infinite scroll pages)
105
- curl -X POST /action -H 'Content-Type: application/json' \
106
- -d '{"kind": "scroll", "scrollY": 800}'
107
-
108
- # Click and wait for navigation (link clicks)
109
- curl -X POST /action -H 'Content-Type: application/json' \
110
- -d '{"kind": "click", "ref": "e5", "waitNav": true}'
111
- ```
112
-
113
- ## Batch actions
114
-
115
- ```bash
116
- # Execute multiple actions in sequence
117
- curl -X POST /actions -H 'Content-Type: application/json' \
118
- -d '{"actions":[{"kind":"click","ref":"e3"},{"kind":"type","ref":"e3","text":"hello"},{"kind":"press","key":"Enter"}]}'
119
-
120
- # Stop on first error (default: false)
121
- curl -X POST /actions -H 'Content-Type: application/json' \
122
- -d '{"tabId":"TARGET_ID","actions":[...],"stopOnError":true}'
123
- ```
124
-
125
- ## Extract text
126
-
127
- ```bash
128
- # CLI: pinchtab text [--raw]
129
- # Readability mode (default) — strips nav/footer/ads
130
- curl /text
131
-
132
- # Raw innerText
133
- curl "/text?mode=raw"
134
- ```
135
-
136
- Returns `{url, title, text}`. Cheapest option (~1K tokens for most pages).
137
-
138
- ## PDF export
139
-
140
- ```bash
141
- # CLI: pinchtab pdf --tab TAB_ID [-o file.pdf] [--landscape] [--scale 0.8]
142
- # Returns base64 JSON
143
- curl "/tabs/TAB_ID/pdf"
144
-
145
- # Raw PDF bytes
146
- curl "/tabs/TAB_ID/pdf?raw=true" -o page.pdf
147
-
148
- # Save to disk
149
- curl "/tabs/TAB_ID/pdf?output=file&path=/tmp/page.pdf"
150
-
151
- # Landscape with custom scale
152
- curl "/tabs/TAB_ID/pdf?landscape=true&scale=0.8&raw=true" -o page.pdf
153
-
154
- # Custom paper size (Letter: 8.5x11, A4: 8.27x11.69)
155
- curl "/tabs/TAB_ID/pdf?paperWidth=8.5&paperHeight=11&marginTop=0.5&marginLeft=0.5&raw=true" -o custom.pdf
156
-
157
- # Export specific pages
158
- curl "/tabs/TAB_ID/pdf?pageRanges=1-5&raw=true" -o pages.pdf
159
-
160
- # With header/footer
161
- curl "/tabs/TAB_ID/pdf?displayHeaderFooter=true&headerTemplate=%3Cspan%20class=title%3E%3C/span%3E&raw=true" -o header.pdf
162
-
163
- # Accessible PDF with document outline
164
- curl "/tabs/TAB_ID/pdf?generateTaggedPDF=true&generateDocumentOutline=true&raw=true" -o accessible.pdf
165
-
166
- # Honor CSS page size
167
- curl "/tabs/TAB_ID/pdf?preferCSSPageSize=true&raw=true" -o css-sized.pdf
168
- ```
169
-
170
- **Query Parameters:**
171
-
172
- | Param | Type | Default | Description |
173
- |-------|------|---------|-------------|
174
- | `paperWidth` | float | 8.5 | Paper width in inches |
175
- | `paperHeight` | float | 11.0 | Paper height in inches |
176
- | `landscape` | bool | false | Landscape orientation |
177
- | `marginTop` | float | 0.4 | Top margin in inches |
178
- | `marginBottom` | float | 0.4 | Bottom margin in inches |
179
- | `marginLeft` | float | 0.4 | Left margin in inches |
180
- | `marginRight` | float | 0.4 | Right margin in inches |
181
- | `scale` | float | 1.0 | Print scale (0.1–2.0) |
182
- | `pageRanges` | string | all | Pages to export (e.g., `1-3,5`) |
183
- | `displayHeaderFooter` | bool | false | Show header and footer |
184
- | `headerTemplate` | string | — | HTML template for header |
185
- | `footerTemplate` | string | — | HTML template for footer |
186
- | `preferCSSPageSize` | bool | false | Honor CSS `@page` size |
187
- | `generateTaggedPDF` | bool | false | Generate accessible/tagged PDF |
188
- | `generateDocumentOutline` | bool | false | Embed document outline |
189
- | `output` | string | JSON | `file` to save to disk, default returns base64 |
190
- | `path` | string | auto | Custom file path (with `output=file`) |
191
- | `raw` | bool | false | Return raw PDF bytes instead of JSON |
192
-
193
- Wraps `Page.printToPDF`. Prints background graphics by default.
194
-
195
- ## Download files
196
-
197
- ```bash
198
- # Returns base64 JSON by default (uses browser session/cookies/stealth)
199
- curl "/download?url=https://site.com/report.pdf"
200
-
201
- # Raw bytes (pipe to file)
202
- curl "/download?url=https://site.com/image.jpg&raw=true" -o image.jpg
203
-
204
- # Save directly to disk
205
- curl "/download?url=https://site.com/export.csv&output=file&path=/tmp/export.csv"
206
- ```
207
-
208
- ## Upload files
209
-
210
- ```bash
211
- # Upload a local file to a file input
212
- curl -X POST "/upload?tabId=TAB_ID" -H "Content-Type: application/json" \
213
- -d '{"selector": "input[type=file]", "paths": ["/tmp/photo.jpg"]}'
214
-
215
- # Upload base64-encoded data
216
- curl -X POST /upload -H "Content-Type: application/json" \
217
- -d '{"selector": "#avatar-input", "files": ["data:image/png;base64,iVBOR..."]}'
218
- ```
219
-
220
- Sets files on `<input type=file>` elements via CDP. Fires `change` events. Selector defaults to `input[type=file]` if omitted.
221
-
222
- ## Screenshot
223
-
224
- ```bash
225
- # CLI: pinchtab ss [-o file.jpg] [-q 80]
226
- curl "/screenshot?raw=true" -o screenshot.jpg
227
- curl "/screenshot?raw=true&quality=50" -o screenshot.jpg
228
- ```
229
-
230
- ## Evaluate JavaScript
231
-
232
- ```bash
233
- # CLI: pinchtab eval "document.title"
234
- curl -X POST /evaluate -H 'Content-Type: application/json' \
235
- -d '{"expression": "document.title"}'
236
- ```
237
-
238
- ## Tab management
239
-
240
- ```bash
241
- # CLI: pinchtab tabs / pinchtab tabs new <url> / pinchtab tabs close <id>
242
- # List tabs
243
- curl /tabs
244
-
245
- # Open new tab
246
- curl -X POST /tab -H 'Content-Type: application/json' \
247
- -d '{"action": "new", "url": "https://example.com"}'
248
-
249
- # Close tab
250
- curl -X POST /tab -H 'Content-Type: application/json' \
251
- -d '{"action": "close", "tabId": "TARGET_ID"}'
252
- ```
253
-
254
- Multi-tab: pass `?tabId=TARGET_ID` to snapshot/screenshot/text, or `"tabId"` in POST body.
255
-
256
- ## Tab locking (multi-agent)
257
-
258
- ```bash
259
- # Lock a tab (default 30s timeout, max 5min)
260
- curl -X POST /tab/lock -H 'Content-Type: application/json' \
261
- -d '{"tabId": "TARGET_ID", "owner": "agent-1", "timeoutSec": 60}'
262
-
263
- # Unlock
264
- curl -X POST /tab/unlock -H 'Content-Type: application/json' \
265
- -d '{"tabId": "TARGET_ID", "owner": "agent-1"}'
266
- ```
267
-
268
- Locked tabs show `owner` and `lockedUntil` in `/tabs`. Returns 409 on conflict.
269
-
270
- ## Cookies
271
-
272
- ```bash
273
- # Get cookies for current page
274
- curl /cookies
275
-
276
- # Set cookies
277
- curl -X POST /cookies -H 'Content-Type: application/json' \
278
- -d '{"url":"https://example.com","cookies":[{"name":"session","value":"abc123"}]}'
279
- ```
280
-
281
- ## Stealth
282
-
283
- ```bash
284
- # Check stealth status and score
285
- curl /stealth/status
286
-
287
- # Rotate browser fingerprint
288
- curl -X POST /fingerprint/rotate -H 'Content-Type: application/json' \
289
- -d '{"os":"windows"}'
290
- # os: "windows", "mac", or omit for random
291
- ```
292
-
293
- ## Health check
294
-
295
- ```bash
296
- curl /health
297
- ```
1
+ # Pinchtab API Reference
2
+
3
+ Base URL for all examples: `http://localhost:9867`
4
+
5
+ > **CLI alternative:** All endpoints have CLI equivalents. Use `pinchtab help` for the full list. Examples are shown as `# CLI:` comments below.
6
+
7
+ ## Navigate
8
+
9
+ ```bash
10
+ # CLI: pinchtab nav https://example.com [--new-tab] [--block-images]
11
+ curl -X POST /navigate \
12
+ -H 'Content-Type: application/json' \
13
+ -d '{"url": "https://example.com"}'
14
+
15
+ # With options: custom timeout, block images, open in new tab
16
+ curl -X POST /navigate \
17
+ -H 'Content-Type: application/json' \
18
+ -d '{"url": "https://example.com", "timeout": 60, "blockImages": true, "newTab": true}'
19
+ ```
20
+
21
+ ## Snapshot (accessibility tree)
22
+
23
+ ```bash
24
+ # CLI: pinchtab snap [-i] [-c] [-d] [-s main] [--max-tokens 2000]
25
+ # Full tree
26
+ curl /snapshot
27
+
28
+ # Interactive elements only (buttons, links, inputs) — much smaller
29
+ curl "/snapshot?filter=interactive"
30
+
31
+ # Limit depth
32
+ curl "/snapshot?depth=5"
33
+
34
+ # Smart diff — only changes since last snapshot (massive token savings)
35
+ curl "/snapshot?diff=true"
36
+
37
+ # Text format — indented tree, ~40-60% fewer tokens than JSON
38
+ curl "/snapshot?format=text"
39
+
40
+ # Compact format — one-line-per-node, 56-64% fewer tokens than JSON (recommended)
41
+ curl "/snapshot?format=compact"
42
+
43
+ # YAML format
44
+ curl "/snapshot?format=yaml"
45
+
46
+ # Scope to CSS selector (e.g. main content only)
47
+ curl "/snapshot?selector=main"
48
+
49
+ # Truncate to ~N tokens
50
+ curl "/snapshot?maxTokens=2000"
51
+
52
+ # Combine for maximum efficiency
53
+ curl "/snapshot?format=compact&selector=main&maxTokens=2000&filter=interactive"
54
+
55
+ # Disable animations before capture
56
+ curl "/snapshot?noAnimations=true"
57
+
58
+ # Write to file
59
+ curl "/snapshot?output=file&path=/tmp/snapshot.json"
60
+ ```
61
+
62
+ Returns flat JSON array of nodes with `ref`, `role`, `name`, `depth`, `value`, `nodeId`.
63
+
64
+ **Token optimization**: Use `?format=compact` for best token efficiency. Add `?filter=interactive` for action-oriented tasks (~75% fewer nodes). Use `?selector=main` to scope to relevant content. Use `?maxTokens=2000` to cap output. Use `?diff=true` on multi-step workflows to see only changes. Combine all params freely.
65
+
66
+ ## Act on elements
67
+
68
+ ```bash
69
+ # CLI: pinchtab click e5 / pinchtab type e12 hello / pinchtab press Enter
70
+ # Click by ref
71
+ curl -X POST /action -H 'Content-Type: application/json' \
72
+ -d '{"kind": "click", "ref": "e5"}'
73
+
74
+ # Type into focused element (click first, then type)
75
+ curl -X POST /action -H 'Content-Type: application/json' \
76
+ -d '{"kind": "click", "ref": "e12"}'
77
+ curl -X POST /action -H 'Content-Type: application/json' \
78
+ -d '{"kind": "type", "ref": "e12", "text": "hello world"}'
79
+
80
+ # Press a key
81
+ curl -X POST /action -H 'Content-Type: application/json' \
82
+ -d '{"kind": "press", "key": "Enter"}'
83
+
84
+ # Focus an element
85
+ curl -X POST /action -H 'Content-Type: application/json' \
86
+ -d '{"kind": "focus", "ref": "e3"}'
87
+
88
+ # Fill (set value directly, no keystrokes)
89
+ curl -X POST /action -H 'Content-Type: application/json' \
90
+ -d '{"kind": "fill", "selector": "#email", "text": "user@example.com"}'
91
+
92
+ # Hover (trigger dropdowns/tooltips)
93
+ curl -X POST /action -H 'Content-Type: application/json' \
94
+ -d '{"kind": "hover", "ref": "e8"}'
95
+
96
+ # Select dropdown option (by value or visible text)
97
+ curl -X POST /action -H 'Content-Type: application/json' \
98
+ -d '{"kind": "select", "ref": "e10", "value": "option2"}'
99
+
100
+ # Scroll to element
101
+ curl -X POST /action -H 'Content-Type: application/json' \
102
+ -d '{"kind": "scroll", "ref": "e20"}'
103
+
104
+ # Scroll by pixels (infinite scroll pages)
105
+ curl -X POST /action -H 'Content-Type: application/json' \
106
+ -d '{"kind": "scroll", "scrollY": 800}'
107
+
108
+ # Click and wait for navigation (link clicks)
109
+ curl -X POST /action -H 'Content-Type: application/json' \
110
+ -d '{"kind": "click", "ref": "e5", "waitNav": true}'
111
+ ```
112
+
113
+ ## Batch actions
114
+
115
+ ```bash
116
+ # Execute multiple actions in sequence
117
+ curl -X POST /actions -H 'Content-Type: application/json' \
118
+ -d '{"actions":[{"kind":"click","ref":"e3"},{"kind":"type","ref":"e3","text":"hello"},{"kind":"press","key":"Enter"}]}'
119
+
120
+ # Stop on first error (default: false)
121
+ curl -X POST /actions -H 'Content-Type: application/json' \
122
+ -d '{"tabId":"TARGET_ID","actions":[...],"stopOnError":true}'
123
+ ```
124
+
125
+ ## Extract text
126
+
127
+ ```bash
128
+ # CLI: pinchtab text [--raw]
129
+ # Readability mode (default) — strips nav/footer/ads
130
+ curl /text
131
+
132
+ # Raw innerText
133
+ curl "/text?mode=raw"
134
+ ```
135
+
136
+ Returns `{url, title, text}`. Cheapest option (~1K tokens for most pages).
137
+
138
+ ## PDF export
139
+
140
+ ```bash
141
+ # CLI: pinchtab pdf --tab TAB_ID [-o file.pdf] [--landscape] [--scale 0.8]
142
+ # Returns base64 JSON
143
+ curl "/tabs/TAB_ID/pdf"
144
+
145
+ # Raw PDF bytes
146
+ curl "/tabs/TAB_ID/pdf?raw=true" -o page.pdf
147
+
148
+ # Save to disk
149
+ curl "/tabs/TAB_ID/pdf?output=file&path=/tmp/page.pdf"
150
+
151
+ # Landscape with custom scale
152
+ curl "/tabs/TAB_ID/pdf?landscape=true&scale=0.8&raw=true" -o page.pdf
153
+
154
+ # Custom paper size (Letter: 8.5x11, A4: 8.27x11.69)
155
+ curl "/tabs/TAB_ID/pdf?paperWidth=8.5&paperHeight=11&marginTop=0.5&marginLeft=0.5&raw=true" -o custom.pdf
156
+
157
+ # Export specific pages
158
+ curl "/tabs/TAB_ID/pdf?pageRanges=1-5&raw=true" -o pages.pdf
159
+
160
+ # With header/footer
161
+ curl "/tabs/TAB_ID/pdf?displayHeaderFooter=true&headerTemplate=%3Cspan%20class=title%3E%3C/span%3E&raw=true" -o header.pdf
162
+
163
+ # Accessible PDF with document outline
164
+ curl "/tabs/TAB_ID/pdf?generateTaggedPDF=true&generateDocumentOutline=true&raw=true" -o accessible.pdf
165
+
166
+ # Honor CSS page size
167
+ curl "/tabs/TAB_ID/pdf?preferCSSPageSize=true&raw=true" -o css-sized.pdf
168
+ ```
169
+
170
+ **Query Parameters:**
171
+
172
+ | Param | Type | Default | Description |
173
+ |-------|------|---------|-------------|
174
+ | `paperWidth` | float | 8.5 | Paper width in inches |
175
+ | `paperHeight` | float | 11.0 | Paper height in inches |
176
+ | `landscape` | bool | false | Landscape orientation |
177
+ | `marginTop` | float | 0.4 | Top margin in inches |
178
+ | `marginBottom` | float | 0.4 | Bottom margin in inches |
179
+ | `marginLeft` | float | 0.4 | Left margin in inches |
180
+ | `marginRight` | float | 0.4 | Right margin in inches |
181
+ | `scale` | float | 1.0 | Print scale (0.1–2.0) |
182
+ | `pageRanges` | string | all | Pages to export (e.g., `1-3,5`) |
183
+ | `displayHeaderFooter` | bool | false | Show header and footer |
184
+ | `headerTemplate` | string | — | HTML template for header |
185
+ | `footerTemplate` | string | — | HTML template for footer |
186
+ | `preferCSSPageSize` | bool | false | Honor CSS `@page` size |
187
+ | `generateTaggedPDF` | bool | false | Generate accessible/tagged PDF |
188
+ | `generateDocumentOutline` | bool | false | Embed document outline |
189
+ | `output` | string | JSON | `file` to save to disk, default returns base64 |
190
+ | `path` | string | auto | Custom file path (with `output=file`) |
191
+ | `raw` | bool | false | Return raw PDF bytes instead of JSON |
192
+
193
+ Wraps `Page.printToPDF`. Prints background graphics by default.
194
+
195
+ ## Download files
196
+
197
+ ```bash
198
+ # Returns base64 JSON by default (uses browser session/cookies/stealth)
199
+ curl "/download?url=https://site.com/report.pdf"
200
+
201
+ # Raw bytes (pipe to file)
202
+ curl "/download?url=https://site.com/image.jpg&raw=true" -o image.jpg
203
+
204
+ # Save directly to disk
205
+ curl "/download?url=https://site.com/export.csv&output=file&path=/tmp/export.csv"
206
+ ```
207
+
208
+ ## Upload files
209
+
210
+ ```bash
211
+ # Upload a local file to a file input
212
+ curl -X POST "/upload?tabId=TAB_ID" -H "Content-Type: application/json" \
213
+ -d '{"selector": "input[type=file]", "paths": ["/tmp/photo.jpg"]}'
214
+
215
+ # Upload base64-encoded data
216
+ curl -X POST /upload -H "Content-Type: application/json" \
217
+ -d '{"selector": "#avatar-input", "files": ["data:image/png;base64,iVBOR..."]}'
218
+ ```
219
+
220
+ Sets files on `<input type=file>` elements via CDP. Fires `change` events. Selector defaults to `input[type=file]` if omitted.
221
+
222
+ ## Screenshot
223
+
224
+ ```bash
225
+ # CLI: pinchtab ss [-o file.jpg] [-q 80]
226
+ curl "/screenshot?raw=true" -o screenshot.jpg
227
+ curl "/screenshot?raw=true&quality=50" -o screenshot.jpg
228
+ ```
229
+
230
+ ## Evaluate JavaScript
231
+
232
+ ```bash
233
+ # CLI: pinchtab eval "document.title"
234
+ curl -X POST /evaluate -H 'Content-Type: application/json' \
235
+ -d '{"expression": "document.title"}'
236
+ ```
237
+
238
+ ## Tab management
239
+
240
+ ```bash
241
+ # CLI: pinchtab tabs / pinchtab tabs new <url> / pinchtab tabs close <id>
242
+ # List tabs
243
+ curl /tabs
244
+
245
+ # Open new tab
246
+ curl -X POST /tab -H 'Content-Type: application/json' \
247
+ -d '{"action": "new", "url": "https://example.com"}'
248
+
249
+ # Close tab
250
+ curl -X POST /tab -H 'Content-Type: application/json' \
251
+ -d '{"action": "close", "tabId": "TARGET_ID"}'
252
+ ```
253
+
254
+ Multi-tab: pass `?tabId=TARGET_ID` to snapshot/screenshot/text, or `"tabId"` in POST body.
255
+
256
+ ## Tab locking (multi-agent)
257
+
258
+ ```bash
259
+ # Lock a tab (default 30s timeout, max 5min)
260
+ curl -X POST /tab/lock -H 'Content-Type: application/json' \
261
+ -d '{"tabId": "TARGET_ID", "owner": "agent-1", "timeoutSec": 60}'
262
+
263
+ # Unlock
264
+ curl -X POST /tab/unlock -H 'Content-Type: application/json' \
265
+ -d '{"tabId": "TARGET_ID", "owner": "agent-1"}'
266
+ ```
267
+
268
+ Locked tabs show `owner` and `lockedUntil` in `/tabs`. Returns 409 on conflict.
269
+
270
+ ## Cookies
271
+
272
+ ```bash
273
+ # Get cookies for current page
274
+ curl /cookies
275
+
276
+ # Set cookies
277
+ curl -X POST /cookies -H 'Content-Type: application/json' \
278
+ -d '{"url":"https://example.com","cookies":[{"name":"session","value":"abc123"}]}'
279
+ ```
280
+
281
+ ## Stealth
282
+
283
+ ```bash
284
+ # Check stealth status and score
285
+ curl /stealth/status
286
+
287
+ # Rotate browser fingerprint
288
+ curl -X POST /fingerprint/rotate -H 'Content-Type: application/json' \
289
+ -d '{"os":"windows"}'
290
+ # os: "windows", "mac", or omit for random
291
+ ```
292
+
293
+ ## Health check
294
+
295
+ ```bash
296
+ curl /health
297
+ ```