@trawlme/skills 1.3.0 → 1.3.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.
- package/README.md +2 -1
- package/package.json +1 -1
- package/skills/trawl-cli/SKILL.md +136 -14
- package/skills/trawl-scrap-account/SKILL.md +2 -2
- package/skills/trawl-scrap-banner/SKILL.md +9 -3
- package/skills/trawl-scrap-design/SKILL.md +13 -8
- package/skills/trawl-scrap-design/references/returndata-shapes.md +11 -6
- package/skills/trawl-scrap-local-test/SKILL.md +5 -1
- package/skills/trawl-scrap-local-test/references/headed-debug.md +2 -2
- package/skills/trawl-scrap-local-test/scripts/run-local.mjs +30 -6
package/README.md
CHANGED
|
@@ -15,6 +15,7 @@ Follows the [Anthropic Agent Skills](https://github.com/anthropics/skills) layou
|
|
|
15
15
|
| `trawl-scrap-design` | Best practices for writing the Puppeteer script body — selectors, returnData shape, params, validation, anti-patterns. |
|
|
16
16
|
| `trawl-scrap-account` | Authentication — Trawl-managed credentials, BYO-cookies (embedded and persisted flavours), session reuse. |
|
|
17
17
|
| `trawl-scrap-local-test` | Run a scrap locally with headed Chrome before publishing, mirroring the worker entry contract. |
|
|
18
|
+
| `trawl-scrap-banner` | Generate + upload a brand-aware 1200x630 banner image for a scrap. |
|
|
18
19
|
|
|
19
20
|
## Install
|
|
20
21
|
|
|
@@ -51,7 +52,7 @@ The CLI bundles the skills and keeps them in sync with the CLI version.
|
|
|
51
52
|
|
|
52
53
|
## Migrating from v0.1.x
|
|
53
54
|
|
|
54
|
-
In v0.1.x there was a single skill named `trawl`. v0.2.0
|
|
55
|
+
In v0.1.x there was a single skill named `trawl`. v0.2.0 split it into four focused skills; `trawl-scrap-banner` was added later, bringing the total to the five listed in the bundled skills table above. When you run `npx @trawlme/skills install` (or `update`), the installer detects the legacy `~/.claude/skills/trawl/` directory and removes it before installing the current set. No manual cleanup needed.
|
|
55
56
|
|
|
56
57
|
Restart Claude Code after the install for the new skills to be picked up.
|
|
57
58
|
|
package/package.json
CHANGED
|
@@ -25,16 +25,25 @@ The user must have `@trawlme/cli` installed:
|
|
|
25
25
|
npm install -g @trawlme/cli
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
And be authenticated.
|
|
28
|
+
And be authenticated. Auth paths:
|
|
29
29
|
|
|
30
|
-
1. **Interactive** — `trawl login` (prompts email/password, stores JWT
|
|
31
|
-
2. **Env var** — `export TRAWL_TOKEN=<jwt>` (overrides stored token, ideal for CI)
|
|
30
|
+
1. **Interactive** — `trawl login` (prompts email/password, stores JWT via `conf`; on macOS that's `~/Library/Preferences/trawl-cli-nodejs/`, **not** `~/.config/trawl-cli/` — Conf's `env-paths` dependency hardcodes `Library/Preferences` and ignores XDG. Override the location with `TRAWL_CONFIG_DIR`.)
|
|
31
|
+
2. **Env var** — `export TRAWL_TOKEN=<jwt>` (overrides stored token, ideal for CI; `trawl token` also resolves it — see MCP bridge below)
|
|
32
32
|
3. **Token flag** — `trawl login --token <jwt>`
|
|
33
|
+
4. **Email/password flags** — `trawl login -e <email> -p <password>` (non-interactive; `-p` on the command line is visible in process list/shell history — CI only, prefer the interactive password prompt otherwise)
|
|
33
34
|
|
|
34
35
|
Custom API base: `trawl login --url https://self-hosted.example.com`. Default is `https://api.trawl.me`.
|
|
35
36
|
|
|
36
37
|
If the user gets `Session expired or invalid. Run: trawl login`, their stored JWT is dead — re-run `trawl login`.
|
|
37
38
|
|
|
39
|
+
CI-relevant env vars. The first three are per-invocation session overrides — they take precedence over stored config without writing to disk (for normal commands; note `trawl login` itself still persists a token even when `TRAWL_TOKEN` is set):
|
|
40
|
+
- `TRAWL_TOKEN` — session JWT, takes precedence over `trawl login`'s stored token
|
|
41
|
+
- `TRAWL_API_URL` — API base URL, takes precedence over `trawl login --url`
|
|
42
|
+
- `TRAWL_TIMEOUT` — per-request fetch timeout in ms (default 30000)
|
|
43
|
+
- `DEBUG` — any truthy value prints the full error stack trace to stderr, same effect as the global `--debug` flag
|
|
44
|
+
|
|
45
|
+
`TRAWL_CONFIG_DIR` is different — it **redirects where the CLI reads and writes** its config file (so `trawl login` persists there). Point it at an ephemeral dir for hermetic runs, e.g. `TRAWL_CONFIG_DIR=$(mktemp -d)`.
|
|
46
|
+
|
|
38
47
|
## Core commands
|
|
39
48
|
|
|
40
49
|
All commands accept `--json` (where listed) for machine-readable or pipeable output.
|
|
@@ -47,8 +56,12 @@ trawl scraps list --json # JSON array
|
|
|
47
56
|
trawl scraps list --status failure # filter by last-run status
|
|
48
57
|
trawl scraps list --status success
|
|
49
58
|
trawl scraps list --status never # never run
|
|
59
|
+
trawl scraps list --limit 10 # cap output client-side
|
|
60
|
+
trawl scraps list --page 2 # single-page mode (one 50-row page)
|
|
50
61
|
```
|
|
51
62
|
|
|
63
|
+
> **Pagination:** `list` fetches **all** scraps by default (it auto-paginates internally at 200/page until a short page). `--page N` switches to single-page mode — one 50-row page, no auto-pagination. `--limit N` caps the output client-side. `--limit` and `--page` are mutually exclusive (usage error, exit 2). Because the default fetches everything, a `jq`-by-title lookup over `list --json` sees every scrap — no page-1 blind spot.
|
|
64
|
+
|
|
52
65
|
### Inspect a single scrap
|
|
53
66
|
|
|
54
67
|
```bash
|
|
@@ -57,6 +70,22 @@ trawl scraps get <id> --json # full scrap object
|
|
|
57
70
|
trawl scraps data <id> --json # last run output (the scraped data)
|
|
58
71
|
```
|
|
59
72
|
|
|
73
|
+
`data <id>` defaults to reading the **last persisted run** — read-only, no quota cost. Flags:
|
|
74
|
+
- `--fresh` — launches a **new** run instead (consumes execute quota, same cost as `scraps run`). Only reach for this when the caller explicitly needs current data.
|
|
75
|
+
- `--errors` — show failure diagnostics inline when the last run failed.
|
|
76
|
+
- `--json` — machine-readable output.
|
|
77
|
+
|
|
78
|
+
**Honest data states (since CLI 1.18.2):** `[]` is reserved for a genuine zero-item run. Every other outcome is a distinct error envelope instead of a silent empty array:
|
|
79
|
+
|
|
80
|
+
| State | Result |
|
|
81
|
+
|---|---|
|
|
82
|
+
| Genuine zero-item run (incl. a run with `statusDetail: 'empty'`) | `[]`, exit `0` |
|
|
83
|
+
| Scrap has never run | error, exit `4`, kind `not_found` — "Run it first... or pass --fresh" |
|
|
84
|
+
| Last run failed (`status: false` and not `empty`) | error, exit `1`, kind `run_failed` — points to `--errors` |
|
|
85
|
+
| Payload aged out of retention (server keeps only the newest row per scrap+status bucket) | error, exit `4`, kind `not_found` |
|
|
86
|
+
|
|
87
|
+
Before 1.18.2 all four states collapsed into the same `[]` / "No data yet." — never assume "no data" from an empty result without checking the exit code.
|
|
88
|
+
|
|
60
89
|
### Create a scrap
|
|
61
90
|
|
|
62
91
|
```bash
|
|
@@ -70,6 +99,8 @@ Flags:
|
|
|
70
99
|
- `-u, --url` — target URL (also exposed as `TRAWL.url` in the script)
|
|
71
100
|
- `-d, --description` — what the scrap does (used by wizard few-shot examples + future marketplace listing)
|
|
72
101
|
- `-r, --request` — the Puppeteer script body (must call `returnData(arr)`)
|
|
102
|
+
- `--tier tier0..tier4` — request a starting proxy tier (see Proxy tiers below)
|
|
103
|
+
- `--json` — output the full scrap object as JSON; a refused tier returns the standard error envelope + exit `1` instead (see Proxy tiers below)
|
|
73
104
|
|
|
74
105
|
For the script body, see the `trawl-scrap-design` skill.
|
|
75
106
|
|
|
@@ -83,12 +114,24 @@ trawl scraps update <id> --alert ops@example.com # email on failure
|
|
|
83
114
|
trawl scraps update <id> --no-alert # disable alerts
|
|
84
115
|
trawl scraps update <id> --autofix # enable AI Fix (auto-repair on failure) — @trawlme/cli@1.11.0+
|
|
85
116
|
trawl scraps update <id> --no-autofix # disable AI Fix
|
|
86
|
-
trawl scraps update <id> -p '{"
|
|
87
|
-
trawl scraps update <id> --params-file ./params.json # bulk params from file
|
|
117
|
+
trawl scraps update <id> -p '[{"TRAWL.page":"2"}]' # runtime params: JSON array of {"TRAWL.<name>":"<value>"} objects
|
|
118
|
+
trawl scraps update <id> --params-file ./params.json # bulk params from file (same array shape)
|
|
119
|
+
trawl scraps update <id> --tier tier2 # request a proxy tier
|
|
120
|
+
trawl scraps update <id> --force-tier tier4 # raise the tier CEILING past the auto-cap
|
|
121
|
+
trawl scraps update <id> --tier tier2 --json # full scrap JSON, or error envelope + exit 1 on refusal
|
|
88
122
|
```
|
|
89
123
|
|
|
90
124
|
> **GTM seed scraps:** always run `trawl scraps update <id> --autofix --cron '0 0 * * 0'` post-create (weekly schedule + AI Fix enabled).
|
|
91
125
|
|
|
126
|
+
### Proxy tiers
|
|
127
|
+
|
|
128
|
+
- `--tier tier0..tier4` (create + update) — requests a starting proxy tier. It's **clamped to tier3** if the target domain isn't allow-listed for tier4, even though the flag accepts `tier4` without error.
|
|
129
|
+
- Since CLI 1.18.2, **both `create` and `update`** read `_tierOverride` back from the server and render the same honest truth (previously only `update` echoed the clamp; `create` was silent): a clamp (`⚠ proxyTier requested tier4 → applied tier3`), an allowed ceiling raise (+ spend warning if any), or a refusal.
|
|
130
|
+
- **Old-server fallback (since CLI 1.18.2):** if a tier was requested but the response carries no `_tierOverride` at all, the CLI no longer echoes the requested value as if it were applied — it prints `⚠ Server did not confirm the tier change (older server) — verify with: trawl scraps get <id>` instead. Never assume the requested tier was honored on an unconfirmed response.
|
|
131
|
+
- `--force-tier tier0..tier4` (update only) — raises the tier **ceiling** past that auto-cap. History-gated: the server may refuse it (the CLI prints `✗ tier ceiling override refused: <reason>` and exits `1`) or it may cost more, depending on the scrap's run history.
|
|
132
|
+
- `--json` (create + update, since CLI 1.18.2): success returns the full scrap object including `_tierOverride`; a refused tier returns the standard error envelope on stdout and exits `1` — same outcome as human mode, just machine-readable.
|
|
133
|
+
- Either way, verify what tier a run actually used with `trawl scraps history <id>` / `trawl scraps run-info <hid>` (on servers released before mid-July 2026 the `history` list shows these columns blank — `run-info` always has them) — don't assume the requested tier was honored.
|
|
134
|
+
|
|
92
135
|
### Run / trigger / watch
|
|
93
136
|
|
|
94
137
|
- `trawl scraps run <id>` — synchronous run via the load endpoint, blocks until done
|
|
@@ -108,18 +151,34 @@ trawl scraps run-info <hid> # one run's detail by its history id
|
|
|
108
151
|
trawl scraps run-info <hid> --json
|
|
109
152
|
```
|
|
110
153
|
|
|
111
|
-
`doctor`/`autofix` (below) inspect the **last** run; `history` + `run-info` reach **any** run: list with `history`, then pass a run's `hid` to `run-info` for the full diagnosis. `run-info` hits `/api/historys/:hid`, which returns the proxy tier + `failureKind` to the scrap owner
|
|
154
|
+
`doctor`/`autofix` (below) inspect the **last** run; `history` + `run-info` reach **any** run: list with `history`, then pass a run's `hid` to `run-info` for the full diagnosis. `run-info` hits `/api/historys/:hid`, which returns the proxy tier + `failureKind` to the scrap owner, plus the error snapshot (`errorMessage`/selector context) that `history`'s embedded list never carries. (On servers released before mid-July 2026, `history` also shows the tier/failureKind columns blank — `run-info` always has them.)
|
|
112
155
|
|
|
113
156
|
### Delete
|
|
114
157
|
|
|
115
158
|
```bash
|
|
116
|
-
trawl scraps
|
|
117
|
-
trawl scraps
|
|
159
|
+
trawl scraps delete <id> # prompts for confirmation
|
|
160
|
+
trawl scraps delete <id> --force # no prompt, useful in scripts
|
|
161
|
+
trawl scraps rm <id> # `rm` is an alias for `delete`, same flags
|
|
118
162
|
```
|
|
119
163
|
|
|
120
164
|
## Scrap accounts
|
|
121
165
|
|
|
122
|
-
For per-scrap authentication, see the `trawl-scrap-account` skill. CLI commands: `trawl scraps account set/status/clear-session/delete
|
|
166
|
+
For per-scrap authentication, see the `trawl-scrap-account` skill. CLI commands: `trawl scraps account set/status/clear-session/delete`, plus `trawl scraps account session set <id>` (upload BYO-cookies).
|
|
167
|
+
|
|
168
|
+
## MCP bridge
|
|
169
|
+
|
|
170
|
+
`trawl token` prints the stored session JWT to **stdout** (any advisory text, e.g. expiry, goes to stderr — safe to capture stdout alone). Since CLI 1.18.2 it resolves `TRAWL_TOKEN` before the stored config token (same precedence every other token consumer uses), so it works headless in CI/agents without a prior `trawl login`: `TRAWL_TOKEN=<jwt> trawl token` prints straight through. A missing or expired token now exits `3` with kind `auth` (previously exit `1`, kind `unknown` — indistinguishable from an arbitrary bug).
|
|
171
|
+
|
|
172
|
+
The session JWT authenticates two different ways depending on the endpoint:
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
# MCP endpoint — accepts the session JWT as a Bearer token:
|
|
176
|
+
curl -H "Authorization: Bearer $(trawl token)" https://api.trawl.me/api/mcp
|
|
177
|
+
|
|
178
|
+
# Raw REST (/api/scraps, etc.) — the JWT strategy is COOKIE-ONLY (reads the TOKEN cookie).
|
|
179
|
+
# Bearer is NOT accepted here; pass the JWT as the TOKEN cookie instead:
|
|
180
|
+
curl -H "Cookie: TOKEN=$(trawl token)" https://api.trawl.me/api/scraps
|
|
181
|
+
```
|
|
123
182
|
|
|
124
183
|
## Common patterns
|
|
125
184
|
|
|
@@ -129,6 +188,7 @@ ID=$(trawl scraps list --json | jq -r '.[] | select(.title=="X") | ._id')
|
|
|
129
188
|
trawl scraps run "$ID" --watch
|
|
130
189
|
trawl scraps data "$ID" --json
|
|
131
190
|
```
|
|
191
|
+
> `list --json` auto-paginates, so this lookup searches all scraps — no page-1 blind spot.
|
|
132
192
|
|
|
133
193
|
**"Why did this scrap fail?"**
|
|
134
194
|
```bash
|
|
@@ -155,6 +215,13 @@ trawl scraps update <id> -r '<new script>'
|
|
|
155
215
|
trawl scraps run <id> --watch
|
|
156
216
|
```
|
|
157
217
|
|
|
218
|
+
## Other commands
|
|
219
|
+
|
|
220
|
+
- `trawl scraps banner <id> -f <path>` — upload a banner image (jpg/png/webp) for a scrap; see the `trawl-scrap-banner` skill for the full generate + upload pipeline
|
|
221
|
+
- `trawl logout` — clear stored credentials
|
|
222
|
+
- `trawl skills list/install/uninstall/update` — manage the bundled Claude Code skills (this package)
|
|
223
|
+
- `trawl telemetry` — inspect/toggle usage telemetry (`TRAWL_TELEMETRY=0` / `DO_NOT_TRACK=1` env overrides also work)
|
|
224
|
+
|
|
158
225
|
## Output shapes (JSON)
|
|
159
226
|
|
|
160
227
|
Scrap object shape:
|
|
@@ -167,15 +234,38 @@ Scrap object shape:
|
|
|
167
234
|
"url": "https://...",
|
|
168
235
|
"request": "var page = ...",
|
|
169
236
|
"scrapper": "puppeteer",
|
|
170
|
-
"cron": "0 9 * * *"
|
|
171
|
-
"
|
|
172
|
-
"
|
|
237
|
+
"cron": "0 9 * * *",
|
|
238
|
+
"autoFix": false,
|
|
239
|
+
"params": [{"TRAWL.paramName": "value"}],
|
|
240
|
+
"history": [
|
|
241
|
+
{
|
|
242
|
+
"_id": "...",
|
|
243
|
+
"status": true,
|
|
244
|
+
"statusDetail": "success",
|
|
245
|
+
"time": 4200,
|
|
246
|
+
"proxyTier": "tier1",
|
|
247
|
+
"failureKind": null,
|
|
248
|
+
"blockType": null,
|
|
249
|
+
"createdAt": "..."
|
|
250
|
+
}
|
|
251
|
+
],
|
|
173
252
|
"createdAt": "...",
|
|
174
|
-
"updatedAt": "..."
|
|
253
|
+
"updatedAt": "...",
|
|
254
|
+
"_tierOverride": { "requestedMaxTier": "tier4", "effectiveMaxTier": "tier3", "refused": false, "reason": "...", "provider": "...", "warning": null }
|
|
175
255
|
}
|
|
176
256
|
```
|
|
177
257
|
|
|
178
|
-
`
|
|
258
|
+
There is **no `lastRun` field** — that never existed. Last-run status/timing/error all derive from `history[0]` (newest first). The embedded row shape differs by command:
|
|
259
|
+
- `trawl scraps get <id>` — up to 100 rows, each with `status`, `statusDetail`, `time`, `proxyTier`, `failureKind`, `blockType`, `createdAt`
|
|
260
|
+
- `trawl scraps list` — only the single newest row per scrap, with just `status` / `statusDetail` / `createdAt` (no `time`/`proxyTier`/`failureKind`/`blockType` — those come back `undefined`, not `null`); fetch `get <id>` if you need the triage fields
|
|
261
|
+
- `status` — tri-state: `true` (success) / `false` (failure) / `null` (in-flight, no result yet)
|
|
262
|
+
- `statusDetail` — `'success' | 'error' | 'empty' | 'regression' | null` — the fine-grained outcome (`empty` = ran clean but returned 0 items; `regression` = item count dropped sharply vs. history)
|
|
263
|
+
- `proxyTier` / `failureKind` / `blockType` — owner-safe triage fields (not stripped like the admin-only proxy vendor/cost internals), present on `get`'s rows (and therefore on `history`, which reads the same endpoint); never on `list`'s rows. Servers released before mid-July 2026 leave them blank — `run-info <hid>` is always authoritative
|
|
264
|
+
- Full error detail (`errorSnapshot`: `errorMessage`, `selector`, `emptyContext`) is **not** embedded on either — fetch it via `trawl scraps run-info <hid>` or `trawl scraps doctor <id>`
|
|
265
|
+
|
|
266
|
+
`_tierOverride` is present only on `create`/`update` responses when a tier was requested (see Proxy tiers above) — absent otherwise.
|
|
267
|
+
|
|
268
|
+
`trawl scraps data <id> --json` returns the array passed to `returnData(...)` — see the honest data states above for what a non-array outcome means.
|
|
179
269
|
|
|
180
270
|
## Errors to recognize
|
|
181
271
|
|
|
@@ -184,9 +274,41 @@ Scrap object shape:
|
|
|
184
274
|
- HTTP 403 → user doesn't own the scrap
|
|
185
275
|
- HTTP 404 → wrong scrap ID
|
|
186
276
|
- HTTP 422 on create/update → missing required field or invalid cron expression
|
|
277
|
+
- HTTP 402 → quota/billing limit hit; message may carry `— upgrade: <url>` when the server provides one (since CLI 1.18.0)
|
|
278
|
+
- HTTP 429 → rate-limited; message may carry `(retry after <N>s)` when the server sends a `Retry-After` header (since CLI 1.18.0)
|
|
279
|
+
|
|
280
|
+
### Exit codes
|
|
281
|
+
|
|
282
|
+
Every command uses these exit codes — check `$?` instead of parsing stderr text:
|
|
283
|
+
|
|
284
|
+
| Code | Meaning |
|
|
285
|
+
|---|---|
|
|
286
|
+
| `0` | success |
|
|
287
|
+
| `1` | unmapped API error (HTTP status other than 401/404) or an unhandled bug — also `scraps data`'s "last run failed" state (kind `run_failed`) and a refused tier override (kind `unknown`) |
|
|
288
|
+
| `2` | usage error — invalid flag/value or malformed input (bad ObjectId, invalid `--tier` value, malformed `-p` JSON, missing file, `--limit`+`--page` conflict) **and, since CLI 1.18.2, commander parse errors** (unknown option/command, missing required arg — previously exit `1`) |
|
|
289
|
+
| `3` | auth error — server **401** (token expired/invalid) **or no stored token at all** (since CLI 1.18.2 — previously exit `1`, kind `unknown`) |
|
|
290
|
+
| `4` | not found — 404, or (for `scraps data`) never-ran / retention-aged-out |
|
|
291
|
+
| `5` | network error (unreachable API, timeout) |
|
|
292
|
+
|
|
293
|
+
Two edges to know:
|
|
294
|
+
- **No stored token at all** now exits `3` with kind `auth` (`Not logged in. Run: trawl login`) — the same path a real 401 takes. Before CLI 1.18.2 this was a generic exit `1`, kind `unknown`, indistinguishable from an arbitrary bug. `trawl token` follows the same rule.
|
|
295
|
+
- **Unknown flags / missing required args** now exit `2` (usage), same bucket as bad flag *values* — before CLI 1.18.2 commander caught these before the command ran and they fell through to exit `1`.
|
|
296
|
+
|
|
297
|
+
### `--json` failure envelope
|
|
298
|
+
|
|
299
|
+
When a command fails **after argument parsing** with `--json` set, the error goes to **stdout** (not stderr) as the JSON payload itself, so you don't need to branch on stream:
|
|
300
|
+
|
|
301
|
+
```json
|
|
302
|
+
{"error":{"message":"Session expired or invalid. Run: trawl login","kind":"auth","status":401}}
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
`kind` is one of `auth` / `not_found` / `api` / `network` / `usage` / `unknown`, plus `run_failed` (`scraps data`-specific, not part of the shared classifier). `status` is only present for HTTP-backed errors.
|
|
306
|
+
|
|
307
|
+
Since CLI 1.18.2, commander-level parse errors (unknown flag, missing required arg) **also** emit the envelope — `{"error":{"message":"...","kind":"usage"}}` (no `status` field) — whenever `--json` appears anywhere on the command line (scanned from raw argv, since parsing fails before any command's own `--json` flag can be read). Exit code `2`. Before 1.18.2 these always bypassed the envelope: empty stdout, a plain-text error on stderr, exit `1`.
|
|
187
308
|
|
|
188
309
|
## What this skill does NOT do
|
|
189
310
|
|
|
190
311
|
- Script body → `trawl-scrap-design`
|
|
191
312
|
- Authentication / session injection → `trawl-scrap-account`
|
|
192
313
|
- Local debugging runs → `trawl-scrap-local-test`
|
|
314
|
+
- Banner image generation + composition pipeline → `trawl-scrap-banner` (this skill only lists the raw `trawl scraps banner` upload command)
|
|
@@ -5,7 +5,7 @@ description: Use when scraping a site that requires authentication. Triggers on
|
|
|
5
5
|
|
|
6
6
|
# Trawl Scrap Account
|
|
7
7
|
|
|
8
|
-
Use when the target site requires authentication. Covers three flows: Trawl-managed credentials (
|
|
8
|
+
Use when the target site requires authentication. Covers three flows: Trawl-managed credentials (server-stored, still recommended for plain username/password logins), BYO-cookies embedded in the script (flavour A), and BYO-cookies persisted via the Trawl API (flavour B).
|
|
9
9
|
|
|
10
10
|
## The worker boundary
|
|
11
11
|
|
|
@@ -21,7 +21,7 @@ Injecting cookies does not change the worker's fingerprint policy.
|
|
|
21
21
|
|
|
22
22
|
3. **MFA, SSO, OAuth, or you don't want to hand credentials to Trawl** → use **Flavour B — Persisted BYO-cookies**. Export cookies from a logged-in browser session, push them into `TRAWL.account.session.cookies` via UI, CLI, or API, and the script reads them back before navigation. Cookies are encrypted at rest.
|
|
23
23
|
|
|
24
|
-
## Trawl-managed credentials (
|
|
24
|
+
## Trawl-managed credentials (server-stored, still supported)
|
|
25
25
|
|
|
26
26
|
The worker injects the account credentials under `TRAWL.account`:
|
|
27
27
|
|
|
@@ -27,13 +27,13 @@ Search Wikimedia Commons for the official brand SVG. Sanitize `siteName` first
|
|
|
27
27
|
|
|
28
28
|
```bash
|
|
29
29
|
# Canonical Commons API (not Wikipedia) — broadest logo coverage
|
|
30
|
-
SITE_TITLE="${
|
|
30
|
+
SITE_TITLE="$(printf '%s' "$siteName" | awk '{print toupper(substr($0,1,1)) substr($0,2)}')_logo.svg" # capitalize first letter: ebay → Ebay_logo.svg (portable — ${siteName^} is Bash-4-only and errors with "bad substitution" (exit 1) on macOS's Bash 3.2)
|
|
31
31
|
curl -s "https://commons.wikimedia.org/w/api.php?action=query&titles=File:${SITE_TITLE}&prop=imageinfo&iiprop=url&format=json" \
|
|
32
32
|
-H "User-Agent: Mozilla/5.0" | jq -r '.query.pages | to_entries[0].value.imageinfo[0].url // empty' \
|
|
33
33
|
> /tmp/${siteName}-logo-url.txt
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
The
|
|
36
|
+
The capitalize-first-letter heuristic (`Ebay_logo.svg`) fails for compound brands. Use the table below first:
|
|
37
37
|
|
|
38
38
|
| siteName | Wikimedia file |
|
|
39
39
|
|---|---|
|
|
@@ -50,7 +50,7 @@ The `${siteName^}_logo.svg` heuristic (capitalize first letter) fails for compou
|
|
|
50
50
|
| tiktok | `TikTok_logo.svg` |
|
|
51
51
|
| booking | `Booking.com_logo.svg` |
|
|
52
52
|
|
|
53
|
-
If the brand is not in the table, try the
|
|
53
|
+
If the brand is not in the table, try the capitalize-first-letter heuristic above, then PNG fallback via thumb endpoint: `https://upload.wikimedia.org/wikipedia/commons/thumb/.../1200px-....png`
|
|
54
54
|
|
|
55
55
|
```bash
|
|
56
56
|
# Download
|
|
@@ -95,12 +95,18 @@ Linux / CI: replace with `google-chrome` or `chromium-browser` (same flags). On
|
|
|
95
95
|
|
|
96
96
|
### 5. Upload
|
|
97
97
|
|
|
98
|
+
Requires an authenticated CLI session first — `trawl login` (or `TRAWL_TOKEN` env / `trawl login --token <jwt>`). Not logged in at all → exit `3` (kind `auth`, since CLI 1.18.2 — was exit `1`); an expired/invalid token → also exit `3` (server 401).
|
|
99
|
+
|
|
98
100
|
```bash
|
|
99
101
|
trawl scraps banner ${scrapId} -f /tmp/${siteName}-banner.png
|
|
100
102
|
```
|
|
101
103
|
|
|
104
|
+
`-f/--file` also accepts `.jpg` and `.webp`, not just `.png` — webp gives smaller uploads for the same visual quality if size matters.
|
|
105
|
+
|
|
102
106
|
CLI confirms upload. Banner is immediately visible on trawl.me.
|
|
103
107
|
|
|
108
|
+
**Failure detection:** `banner` has **no `--json` mode** — the exit code is the only machine-readable signal. `0` = uploaded; non-zero = failed: `1` other/unmapped error, `2` malformed `scrapId` (not a 24-char hex ObjectId — usage error), `3` not logged in / expired-or-invalid token (401), `4` wrong `scrapId` (404), `5` network. Check `$?`, don't parse stdout for success/failure.
|
|
109
|
+
|
|
104
110
|
## Conventions
|
|
105
111
|
|
|
106
112
|
- Logo width **360px** on 1200x630 canvas (~30%). Larger overwhelms; smaller loses recognition.
|
|
@@ -9,7 +9,7 @@ Use when writing the Puppeteer script body that runs on a Trawl worker.
|
|
|
9
9
|
|
|
10
10
|
## The worker boundary
|
|
11
11
|
|
|
12
|
-
The worker handles fingerprinting, proxy escalation, AI Fix, and
|
|
12
|
+
The worker handles fingerprinting, proxy escalation, AI Fix, and run-outcome classification (`statusDetail`: success/error/empty/regression). Your script handles selectors, returnData shape, params, and graceful failure. See `references/anti-patterns.md`.
|
|
13
13
|
|
|
14
14
|
> **Don't add stealth in your script.** Trawl's worker handles fingerprinting, proxy rotation, and bot-detection countermeasures centrally. Adding stealth plugins, UA spoofing, viewport randomisation, or aggressive jitter in your script duplicates worker policy and causes drift. The worker's policy evolves; your script's hardcoded tricks won't.
|
|
15
15
|
|
|
@@ -22,7 +22,7 @@ Selector priority (most to least resilient):
|
|
|
22
22
|
3. Stable class (short, non-generated, meaningful name)
|
|
23
23
|
4. XPath with text anchor — use when no attribute is reliable
|
|
24
24
|
|
|
25
|
-
**One named selector per logical field.** Declare as constants at the top with a comment explaining the choice — AI Fix uses that context to pick a replacement when the selector breaks.
|
|
25
|
+
**One named selector per logical field.** Declare as constants at the top with a comment explaining the choice — AI Fix uses that context to pick a replacement when the selector breaks. AI Fix is toggled per-scrap with `trawl scraps update <id> --autofix` / `--no-autofix`; inspect what it actually did with `trawl scraps doctor <id> --autofix` (last-run diagnosis + autofix outcome) or `trawl scraps autofix <id>` (decision, diff, dry-run, knowledge) — see the `trawl-cli` skill.
|
|
26
26
|
|
|
27
27
|
```js
|
|
28
28
|
// data-testid is stable — the engineering team committed to never removing it
|
|
@@ -81,15 +81,15 @@ returnData([
|
|
|
81
81
|
## Params
|
|
82
82
|
|
|
83
83
|
- **`TRAWL.url`** — the target URL, set by the scrap schedule. Treat as immutable; never override it.
|
|
84
|
-
- **`TRAWL.<custom>`** — any custom parameter defined in Settings → Parameters.
|
|
85
|
-
- **`RANDOM(...)`** — a helper that returns a random value from a list (see Trawl params docs).
|
|
86
|
-
- **`DATE(±N, unit, format)`** — a date helper that returns a formatted date offset from now.
|
|
84
|
+
- **`TRAWL.<custom>`** — any custom parameter defined in Settings → Parameters (UI), or provisioned via the CLI: `trawl scraps update <id> -p/--params '[{"TRAWL.<name>":"<value>"}]'` (JSON array) or `--params-file <path>` for bulk — see the `trawl-cli` skill.
|
|
85
|
+
- **`RANDOM(...)`** — a helper that returns a random value from a list (see Trawl params docs). *Signature not independently re-verified against the worker runtime as part of this pass — treat as provisional.*
|
|
86
|
+
- **`DATE(±N, unit, format)`** — a date helper that returns a formatted date offset from now. *Signature not independently re-verified against the worker runtime as part of this pass — treat as provisional.*
|
|
87
87
|
|
|
88
88
|
Validate inputs early — throw before any network call if a required param is missing.
|
|
89
89
|
|
|
90
90
|
```js
|
|
91
91
|
const { url, category } = TRAWL;
|
|
92
|
-
if (!category) throw new Error('Missing required param: category (set in Settings → Parameters)');
|
|
92
|
+
if (!category) throw new Error('Missing required param: category (set in Settings → Parameters, or `trawl scraps update <id> -p \'[{"TRAWL.category":"value"}]\'`)');
|
|
93
93
|
|
|
94
94
|
await page.goto(url, { waitUntil: 'domcontentloaded' });
|
|
95
95
|
```
|
|
@@ -120,7 +120,12 @@ try {
|
|
|
120
120
|
|
|
121
121
|
## Hard anti-bot sites
|
|
122
122
|
|
|
123
|
-
The platform auto-escalates proxy tiers when a run comes back empty — you usually don't manage tiers at all. For a site you *know* is heavily protected,
|
|
123
|
+
The platform auto-escalates proxy tiers when a run comes back empty — you usually don't manage tiers at all. For a site you *know* is heavily protected, there are two CLI knobs (see the `trawl-cli` skill for full flag docs):
|
|
124
|
+
|
|
125
|
+
- `trawl scraps update <id> --tier tier0..tier4` — requests a starting tier so the first run doesn't waste a cycle. **It's clamped to tier3 for domains that aren't allow-listed for tier4** — requesting `tier4` does not error, it just gets capped. Since CLI 1.18.2, both `create` and `update` echo the clamp (`⚠ proxyTier requested tier4 → applied tier3`); on an older server that doesn't confirm the change, the CLI warns instead of pretending the request was applied.
|
|
126
|
+
- `trawl scraps update <id> --force-tier tier0..tier4` — raises the tier **ceiling** past that auto-cap. History-gated: the server may refuse it (CLI exits `1`) or it may cost more, depending on the scrap's run history.
|
|
127
|
+
|
|
128
|
+
Don't assume the requested tier was honored — verify with `trawl scraps history <id>` / `trawl scraps run-info <hid>` after a run. Don't try to outsmart protection in your script — return what you can and let the platform escalate.
|
|
124
129
|
|
|
125
130
|
## Anti-patterns (don't do this)
|
|
126
131
|
|
|
@@ -142,7 +147,7 @@ Some pages hide data behind real UI interactions — scroll, hover, click, form
|
|
|
142
147
|
|
|
143
148
|
- *Trawl Scraping docs (in-app help center)* — selector basics, `returnData`, scrap lifecycle.
|
|
144
149
|
- *Trawl Scraping Advanced docs* — proxy tiers, escalation triggers, rate-limit guidance.
|
|
145
|
-
- *Trawl Data Quality docs* — `
|
|
150
|
+
- *Trawl Data Quality docs* — reading run outcomes: `history[].status` is tri-state (`true`/`false`/`null`); `history[].statusDetail` is the fine-grained enum `success` / `error` / `empty` / `regression` (`empty` = ran clean but `returnData([])`; `regression` = item count dropped sharply vs. prior runs). There is no `validation_failed` status — schema validation (`checkSchema`) was decommissioned.
|
|
146
151
|
- *Trawl AI Features docs* — AI Fix quotas, how selector comments improve AI Fix accuracy.
|
|
147
152
|
- *Trawl Schedule + Parameters docs* — `TRAWL.<custom>` params, `RANDOM(...)` and `DATE(...)` helpers.
|
|
148
153
|
|
|
@@ -28,13 +28,13 @@ Return a flat object per item. Nest only when source data is genuinely nested
|
|
|
28
28
|
|
|
29
29
|
## null vs omission
|
|
30
30
|
|
|
31
|
-
Return `null` for absent optional fields. Never omit the key —
|
|
31
|
+
Return `null` for absent optional fields. Never omit the key — downstream consumers (the frontend table, exports, any consumer script) expect every item to carry the same key set; omitting a key produces ragged objects that silently break column-based rendering.
|
|
32
32
|
|
|
33
33
|
```js
|
|
34
34
|
// Good
|
|
35
35
|
{ title: 'Widget Pro', discount_pct: null, badge: null }
|
|
36
36
|
|
|
37
|
-
// Bad — key omitted,
|
|
37
|
+
// Bad — key omitted, produces a ragged object across the returned array
|
|
38
38
|
{ title: 'Widget Pro' }
|
|
39
39
|
```
|
|
40
40
|
|
|
@@ -84,8 +84,13 @@ returnData(allItems); // single call with all pages merged
|
|
|
84
84
|
|
|
85
85
|
---
|
|
86
86
|
|
|
87
|
-
##
|
|
87
|
+
## How returnData shape affects the run outcome
|
|
88
88
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
-
|
|
89
|
+
Each run gets one `history` row with `status` (tri-state `true`/`false`/`null`) and a finer `statusDetail` enum: `success` / `error` / `empty` / `regression`. There is no schema-validation status — the platform does not enforce a JSON Schema against your items, so a "wrong shape" (missing key, wrong type) never fails the run on its own. What actually flips `statusDetail`:
|
|
90
|
+
|
|
91
|
+
- **`success`** — `returnData(arr)` called with at least one item.
|
|
92
|
+
- **`empty`** — an explicit `returnData([])` — ran clean but returned zero items. Usually means a selector broke; see `references/anti-patterns.md`. Never calling `returnData` at all is NOT `empty`: the run persists as `success` with a `null` payload, which `trawl scraps data` later reports as a `not_found` error (it looks like the payload aged out of retention). Always call `returnData`, even with `[]`.
|
|
93
|
+
- **`error`** — the script threw. Throw only for structural failures (see the Resilience section in `SKILL.md`) — a per-field `try/catch` that degrades a field to `null` does NOT produce `error`, it stays `success` with that field `null`.
|
|
94
|
+
- **`regression`** — item count dropped sharply vs. recent history, computed server-side after a successful run.
|
|
95
|
+
|
|
96
|
+
Ragged objects (an omitted key on some items) don't get their own status — they just make the returned array inconsistent for whatever consumes it downstream. Keep every item's key set identical (`null` for absent values) so `success` runs are actually usable.
|
|
@@ -19,7 +19,10 @@ Paths below assume the default install location (`~/.claude/skills/`); adjust if
|
|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
21
|
# Install puppeteer-core once (it's a peer dependency, not bundled with the skill).
|
|
22
|
-
|
|
22
|
+
# Must be installed IN the skill directory — the harness does a bare ESM
|
|
23
|
+
# `import('puppeteer-core')` which resolves relative to the skill dir, not
|
|
24
|
+
# global/CWD/NODE_PATH, so a global install won't satisfy it.
|
|
25
|
+
cd ~/.claude/skills/trawl-scrap-local-test && npm install puppeteer-core
|
|
23
26
|
|
|
24
27
|
# Run a scrap locally:
|
|
25
28
|
node ~/.claude/skills/trawl-scrap-local-test/scripts/run-local.mjs path/to/scrap.js \
|
|
@@ -57,6 +60,7 @@ No changes to the script body are needed to run it locally.
|
|
|
57
60
|
- `--remote` — connects to an existing Chrome at `http://127.0.0.1:9222` (instead of launching a fresh one). Useful for MFA flows — see `references/headed-debug.md`.
|
|
58
61
|
- `--headless` — launches Chrome headlessly (no window). Default is headed (`headless: false`) for interactive debugging.
|
|
59
62
|
- `--chrome=<path>` — path to a Chrome executable. Auto-detected on macOS and Linux when omitted; pass explicitly if Chrome lives in a non-standard location or you want to use Chromium.
|
|
63
|
+
- `--slowMo=<ms>` — delay between Puppeteer actions, in ms. Default is 250 in headed mode, 0 in headless. Lower for speed, higher to watch each action.
|
|
60
64
|
- `--help` — prints usage.
|
|
61
65
|
|
|
62
66
|
## Recommended workflow
|
|
@@ -4,7 +4,7 @@ Advanced debugging flags and techniques for `run-local.mjs`.
|
|
|
4
4
|
|
|
5
5
|
## Default flags
|
|
6
6
|
|
|
7
|
-
The harness launches Chrome with `headless: false`, `slowMo: 250`, `devtools: true`. Tune `slowMo`
|
|
7
|
+
The harness launches Chrome with `headless: false`, `slowMo: 250`, `devtools: true`. Tune `slowMo` with the `--slowMo=<ms>` flag, e.g. `run-local.mjs scrap.js --slowMo=500` — lower is faster, higher lets you watch each action. Defaults to `0` automatically under `--headless`.
|
|
8
8
|
|
|
9
9
|
## Pause inside page.evaluate
|
|
10
10
|
|
|
@@ -33,7 +33,7 @@ Log in manually in that Chrome window (complete MFA, solve CAPTCHA, etc.). Then
|
|
|
33
33
|
node run-local.mjs scrap.js --remote
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
The harness calls `puppeteer.connect({ browserURL: 'http://127.0.0.1:9222' })`
|
|
36
|
+
The harness only calls `puppeteer.connect({ browserURL: 'http://127.0.0.1:9222' })` when `--remote` is passed (otherwise it launches a fresh browser). Only `browser` is injected as a global — not `page` — so the script body itself is responsible for calling `browser.newPage()`. Under `--remote` the harness calls `browser.disconnect()` when done instead of `browser.close()`, so the manually-launched Chrome instance stays open.
|
|
37
37
|
|
|
38
38
|
## Intermediate snapshots
|
|
39
39
|
|
|
@@ -19,13 +19,14 @@ Flags:
|
|
|
19
19
|
--remote connect to existing Chrome at 127.0.0.1:9222
|
|
20
20
|
--headless launch Chrome in headless mode (no window)
|
|
21
21
|
--chrome=<path> path to Chrome executable (auto-detected if omitted)
|
|
22
|
+
--slowMo=<ms> delay between Puppeteer actions, in ms (default: 250 headed, 0 headless)
|
|
22
23
|
--help this message
|
|
23
24
|
`);
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
if (args.length === 0 || args.includes('--help')) {
|
|
27
28
|
help();
|
|
28
|
-
process.exit(args.length === 0 ?
|
|
29
|
+
process.exit(args.length === 0 ? 2 : 0);
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
const positional = args.filter((a) => !a.startsWith('--'));
|
|
@@ -42,10 +43,15 @@ const scrapPath = positional[0];
|
|
|
42
43
|
if (!scrapPath) {
|
|
43
44
|
console.error('Missing scrap file argument');
|
|
44
45
|
help();
|
|
45
|
-
process.exit(
|
|
46
|
+
process.exit(2);
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
const
|
|
49
|
+
const resolvedScrapPath = resolve(scrapPath);
|
|
50
|
+
if (!existsSync(resolvedScrapPath)) {
|
|
51
|
+
console.error(`Scrap file not found: ${scrapPath}`);
|
|
52
|
+
process.exit(2);
|
|
53
|
+
}
|
|
54
|
+
const scrapBody = readFileSync(resolvedScrapPath, 'utf8');
|
|
49
55
|
|
|
50
56
|
const { TRAWL, account } = buildContext(flags);
|
|
51
57
|
|
|
@@ -53,7 +59,9 @@ let puppeteer;
|
|
|
53
59
|
try {
|
|
54
60
|
puppeteer = await import('puppeteer-core');
|
|
55
61
|
} catch {
|
|
56
|
-
console.error(
|
|
62
|
+
console.error(
|
|
63
|
+
'puppeteer-core not installed. Run: cd ~/.claude/skills/trawl-scrap-local-test && npm install puppeteer-core'
|
|
64
|
+
);
|
|
57
65
|
process.exit(1);
|
|
58
66
|
}
|
|
59
67
|
|
|
@@ -77,7 +85,7 @@ if (flags.remote) {
|
|
|
77
85
|
if (typeof flags.chrome === 'string') {
|
|
78
86
|
if (!existsSync(flags.chrome)) {
|
|
79
87
|
console.error(`Chrome not found at: ${flags.chrome}`);
|
|
80
|
-
process.exit(
|
|
88
|
+
process.exit(2);
|
|
81
89
|
}
|
|
82
90
|
executablePath = flags.chrome;
|
|
83
91
|
} else {
|
|
@@ -88,10 +96,26 @@ if (flags.remote) {
|
|
|
88
96
|
}
|
|
89
97
|
}
|
|
90
98
|
|
|
99
|
+
const slowMoDefault = flags.headless ? 0 : 250;
|
|
100
|
+
let slowMo = slowMoDefault;
|
|
101
|
+
if (flags.slowMo !== undefined) {
|
|
102
|
+
// `--slowMo` with no `=value` parses to boolean `true` — that's a usage error,
|
|
103
|
+
// not `Number(true) === 1`.
|
|
104
|
+
if (flags.slowMo === true) {
|
|
105
|
+
console.error('--slowMo requires a value, e.g. --slowMo=250');
|
|
106
|
+
process.exit(2);
|
|
107
|
+
}
|
|
108
|
+
slowMo = Number(flags.slowMo);
|
|
109
|
+
if (Number.isNaN(slowMo)) {
|
|
110
|
+
console.error(`Invalid --slowMo value: ${flags.slowMo} (must be a number)`);
|
|
111
|
+
process.exit(2);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
91
115
|
browser = await puppeteer.default.launch({
|
|
92
116
|
executablePath,
|
|
93
117
|
headless: !!flags.headless,
|
|
94
|
-
slowMo
|
|
118
|
+
slowMo,
|
|
95
119
|
devtools: !flags.headless,
|
|
96
120
|
args: ['--no-sandbox'],
|
|
97
121
|
});
|