@trawlme/skills 1.2.4 → 1.3.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trawlme/skills",
3
- "version": "1.2.4",
3
+ "version": "1.3.1",
4
4
  "description": "Claude Code skills for the Trawl CLI — teaches Claude how to manage scraps via @trawlme/cli",
5
5
  "type": "module",
6
6
  "bin": {
@@ -35,6 +35,13 @@ Custom API base: `trawl login --url https://self-hosted.example.com`. Default is
35
35
 
36
36
  If the user gets `Session expired or invalid. Run: trawl login`, their stored JWT is dead — re-run `trawl login`.
37
37
 
38
+ 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):
39
+ - `TRAWL_TOKEN` — session JWT, takes precedence over `trawl login`'s stored token
40
+ - `TRAWL_API_URL` — API base URL, takes precedence over `trawl login --url`
41
+ - `TRAWL_TIMEOUT` — per-request fetch timeout in ms (default 30000)
42
+
43
+ `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)`.
44
+
38
45
  ## Core commands
39
46
 
40
47
  All commands accept `--json` (where listed) for machine-readable or pipeable output.
@@ -47,8 +54,12 @@ trawl scraps list --json # JSON array
47
54
  trawl scraps list --status failure # filter by last-run status
48
55
  trawl scraps list --status success
49
56
  trawl scraps list --status never # never run
57
+ trawl scraps list --limit 10 # cap output client-side
58
+ trawl scraps list --page 2 # single-page mode (one 50-row page)
50
59
  ```
51
60
 
61
+ > **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.
62
+
52
63
  ### Inspect a single scrap
53
64
 
54
65
  ```bash
@@ -57,6 +68,11 @@ trawl scraps get <id> --json # full scrap object
57
68
  trawl scraps data <id> --json # last run output (the scraped data)
58
69
  ```
59
70
 
71
+ `data <id>` defaults to reading the **last persisted run** — read-only, no quota cost. Flags:
72
+ - `--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.
73
+ - `--errors` — show failure diagnostics inline when the last run failed.
74
+ - `--json` — machine-readable output.
75
+
60
76
  ### Create a scrap
61
77
 
62
78
  ```bash
@@ -70,6 +86,7 @@ Flags:
70
86
  - `-u, --url` — target URL (also exposed as `TRAWL.url` in the script)
71
87
  - `-d, --description` — what the scrap does (used by wizard few-shot examples + future marketplace listing)
72
88
  - `-r, --request` — the Puppeteer script body (must call `returnData(arr)`)
89
+ - `--tier tier0..tier4` — request a starting proxy tier (see Proxy tiers below)
73
90
 
74
91
  For the script body, see the `trawl-scrap-design` skill.
75
92
 
@@ -83,30 +100,68 @@ trawl scraps update <id> --alert ops@example.com # email on failure
83
100
  trawl scraps update <id> --no-alert # disable alerts
84
101
  trawl scraps update <id> --autofix # enable AI Fix (auto-repair on failure) — @trawlme/cli@1.11.0+
85
102
  trawl scraps update <id> --no-autofix # disable AI Fix
86
- trawl scraps update <id> -p '{"key":"page","value":"2"}' # add a param (JSON object)
87
- trawl scraps update <id> --params-file ./params.json # bulk params from file
103
+ trawl scraps update <id> -p '[{"TRAWL.page":"2"}]' # runtime params: JSON array of {"TRAWL.<name>":"<value>"} objects
104
+ trawl scraps update <id> --params-file ./params.json # bulk params from file (same array shape)
105
+ trawl scraps update <id> --tier tier2 # request a proxy tier
106
+ trawl scraps update <id> --force-tier tier4 # raise the tier CEILING past the auto-cap
88
107
  ```
89
108
 
90
109
  > **GTM seed scraps:** always run `trawl scraps update <id> --autofix --cron '0 0 * * 0'` post-create (weekly schedule + AI Fix enabled).
91
110
 
111
+ ### Proxy tiers
112
+
113
+ - `--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. On `update`, the CLI **echoes** the clamp (`⚠ proxyTier requested tier4 → applied tier3`); on `create` (and older servers) the clamp is silent — so don't rely on seeing a warning.
114
+ - `--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` and exits `1`) or it may cost more, depending on the scrap's run history.
115
+ - Either way, verify what tier a run actually used with `trawl scraps history <id>` / `trawl scraps run-info <hid>` (the `history` list may show these columns blank — drill into `run-info` for the confirmed value) — don't assume the requested tier was honored.
116
+
92
117
  ### Run / trigger / watch
93
118
 
94
- - `trawl scraps run <id>` — synchronous run, blocks until done
119
+ - `trawl scraps run <id>` — synchronous run via the load endpoint, blocks until done
95
120
  - `trawl scraps run <id> --watch` — same but streams activity logs
96
- - `trawl scraps trigger <id>` — fire-and-forget (returns immediately)
121
+ - `trawl scraps trigger <id>` — **async by default**: queues the worker run and returns immediately (no waiting on the 30-250s run)
122
+ - `trawl scraps trigger <id> --wait` — synchronous: block until the run completes (legacy behaviour)
123
+ - `trawl scraps trigger <id> --watch` — queue, then stream the activity log
97
124
  - `trawl scraps watch <id>` — attach to an in-progress run's activity stream
98
125
 
126
+ ### Inspect past runs
127
+
128
+ ```bash
129
+ trawl scraps history <id> # table of recent runs (status, time, tier, failureKind)
130
+ trawl scraps history <id> --json # JSON array, newest first
131
+ trawl scraps history <id> --limit 50 # cap rows (default 20)
132
+ trawl scraps run-info <hid> # one run's detail by its history id (status, tier, failureKind, error + selector)
133
+ trawl scraps run-info <hid> --json
134
+ ```
135
+
136
+ `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. (In `history`'s embedded list those columns may be blank — drill into `run-info <hid>` for them.)
137
+
99
138
  ### Delete
100
139
 
101
140
  ```bash
102
141
  trawl scraps rm <id> # prompts for confirmation
103
142
  trawl scraps rm <id> --force # no prompt, useful in scripts
143
+ trawl scraps delete <id> # `delete` is an alias for `rm`, same flags
104
144
  ```
105
145
 
106
146
  ## Scrap accounts
107
147
 
108
148
  For per-scrap authentication, see the `trawl-scrap-account` skill. CLI commands: `trawl scraps account set/status/clear-session/delete`.
109
149
 
150
+ ## MCP bridge
151
+
152
+ `trawl token` prints the stored session JWT to **stdout** (any advisory text, e.g. expiry, goes to stderr — safe to capture stdout alone).
153
+
154
+ The session JWT authenticates two different ways depending on the endpoint:
155
+
156
+ ```bash
157
+ # MCP endpoint — accepts the session JWT as a Bearer token:
158
+ curl -H "Authorization: Bearer $(trawl token)" https://api.trawl.me/api/mcp
159
+
160
+ # Raw REST (/api/scraps, etc.) — the JWT strategy is COOKIE-ONLY (reads the TOKEN cookie).
161
+ # Bearer is NOT accepted here; pass the JWT as the TOKEN cookie instead:
162
+ curl -H "Cookie: TOKEN=$(trawl token)" https://api.trawl.me/api/scraps
163
+ ```
164
+
110
165
  ## Common patterns
111
166
 
112
167
  **"Run my X scrap and show me the result"**
@@ -115,6 +170,7 @@ ID=$(trawl scraps list --json | jq -r '.[] | select(.title=="X") | ._id')
115
170
  trawl scraps run "$ID" --watch
116
171
  trawl scraps data "$ID" --json
117
172
  ```
173
+ > `list --json` auto-paginates, so this lookup searches all scraps — no page-1 blind spot.
118
174
 
119
175
  **"Why did this scrap fail?"**
120
176
  ```bash
@@ -141,6 +197,12 @@ trawl scraps update <id> -r '<new script>'
141
197
  trawl scraps run <id> --watch
142
198
  ```
143
199
 
200
+ ## Other commands
201
+
202
+ - `trawl logout` — clear stored credentials
203
+ - `trawl skills list/install/uninstall/update` — manage the bundled Claude Code skills (this package)
204
+ - `trawl telemetry` — inspect/toggle usage telemetry (`TRAWL_TELEMETRY=0` / `DO_NOT_TRACK=1` env overrides also work)
205
+
144
206
  ## Output shapes (JSON)
145
207
 
146
208
  Scrap object shape:
@@ -154,7 +216,7 @@ Scrap object shape:
154
216
  "request": "var page = ...",
155
217
  "scrapper": "puppeteer",
156
218
  "cron": "0 9 * * *" ,
157
- "params": [{"key": "...", "value": "..."}],
219
+ "params": [{"TRAWL.paramName": "value"}],
158
220
  "lastRun": { "status": "success" | "failure", "duration": 1234, "error": "..." },
159
221
  "createdAt": "...",
160
222
  "updatedAt": "..."
@@ -171,6 +233,35 @@ Scrap object shape:
171
233
  - HTTP 404 → wrong scrap ID
172
234
  - HTTP 422 on create/update → missing required field or invalid cron expression
173
235
 
236
+ ### Exit codes
237
+
238
+ Every command uses these exit codes — check `$?` instead of parsing stderr text:
239
+
240
+ | Code | Meaning |
241
+ |---|---|
242
+ | `0` | success |
243
+ | `1` | API error (non-401/404) / unknown error — also **"Not logged in"** (no stored token at all) and commander parse errors (see below) |
244
+ | `2` | usage error — invalid flag **value** / malformed input (bad ObjectId, invalid `--tier` value, malformed `-p` JSON, missing file, `--limit`+`--page` conflict) |
245
+ | `3` | auth error (server **401** — token present but expired/invalid) |
246
+ | `4` | not found (404 — wrong ID) |
247
+ | `5` | network error (unreachable API, timeout) |
248
+
249
+ Two edges to know:
250
+ - **No stored token at all** exits `1` with "Not logged in. Run: trawl login" (not `3`). Exit `3` is specifically a server 401 for a token that *was* sent. `trawl token` with no/expired token also exits `1`.
251
+ - **Unknown flags / missing required args** are caught by commander *before* the command runs, so they exit `1` (not `2`) — only bad flag *values* reach the usage-error path (`2`).
252
+
253
+ ### `--json` failure envelope
254
+
255
+ 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:
256
+
257
+ ```json
258
+ {"error":{"message":"Session expired or invalid. Run: trawl login","kind":"auth","status":401}}
259
+ ```
260
+
261
+ `kind` is one of `auth` / `not_found` / `api` / `network` / `usage` / `unknown`. `status` is only present for HTTP-backed errors.
262
+
263
+ > Caveat: commander-level parse errors (unknown flag, missing required arg) bypass this envelope entirely — even with `--json` you get empty stdout, a plain-text error on stderr, and exit `1`.
264
+
174
265
  ## What this skill does NOT do
175
266
 
176
267
  - Script body → `trawl-scrap-design`
@@ -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 (legacy), BYO-cookies embedded in the script (flavour A), and BYO-cookies persisted via the Trawl API (flavour B).
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 (legacy flow)
24
+ ## Trawl-managed credentials (server-stored, still supported)
25
25
 
26
26
  The worker injects the account credentials under `TRAWL.account`:
27
27
 
@@ -1,11 +1,11 @@
1
1
  ---
2
2
  name: trawl-scrap-banner
3
- description: Generate + upload a brand-aware banner (1200x630 PNG) for a Trawl scrap. Fetches the official brand logo from Wikimedia Commons, composes against a gradient or flat brand-color background, renders via Chrome headless, uploads via `trawl scraps banner`. Triggers on "make banner for my scrap", "generate scrap banner", "upload banner for {site}". Does NOT cover scrap script generation (see trawl-scrap-design) or CLI account management (see trawl-cli).
3
+ description: Generate + upload a brand-aware banner (1200x630 PNG) for a Trawl scrap. Triggers on "make banner for my scrap", "generate scrap banner", "upload banner for {site}", or after a scrap ships to prod. Does NOT cover scrap script generation (see trawl-scrap-design) or CLI account management (see trawl-cli).
4
4
  ---
5
5
 
6
6
  # Trawl Scrap Banner
7
7
 
8
- Generate + upload a brand-aware 1200x630 banner for a Trawl scrap. Prototype validated 2026-05-10 on eBay.
8
+ Generate + upload a brand-aware 1200x630 banner for a Trawl scrap. See the Examples table for validated brands (eBay, Reddit, GitHub).
9
9
 
10
10
  ## When to use
11
11
 
@@ -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="${siteName^}_logo.svg" # capitalize first letter: ebay → Ebay_logo.svg
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 `${siteName^}_logo.svg` heuristic (capitalize first letter) fails for compound brands. Use the table below first:
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 `${siteName^}_logo.svg` heuristic, then PNG fallback via thumb endpoint: `https://upload.wikimedia.org/wikipedia/commons/thumb/.../1200px-....png`
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 `1` ("Not logged in"); an expired/invalid token → 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` not logged in (no token) / other error, `3` 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.
@@ -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, you can pin a higher tier from the start so the first run doesn't waste a cycle; the top tier passes most protections. That's the whole knob. Don't try to outsmart protection in your script — return what you can and let the platform escalate.
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. On `update` the CLI echoes the clamp (`⚠ proxyTier requested tier4 → applied tier3`); on `create`/older servers it's silent.
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
 
@@ -15,9 +15,14 @@ Local testing intentionally uses vanilla `puppeteer-core` — no fingerprint pol
15
15
 
16
16
  ## Quick-start
17
17
 
18
+ Paths below assume the default install location (`~/.claude/skills/`); adjust if the skill lives elsewhere (project `.claude/skills/`, a plugin cache, etc.).
19
+
18
20
  ```bash
19
21
  # Install puppeteer-core once (it's a peer dependency, not bundled with the skill).
20
- npm install -g puppeteer-core
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
21
26
 
22
27
  # Run a scrap locally:
23
28
  node ~/.claude/skills/trawl-scrap-local-test/scripts/run-local.mjs path/to/scrap.js \
@@ -55,6 +60,7 @@ No changes to the script body are needed to run it locally.
55
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`.
56
61
  - `--headless` — launches Chrome headlessly (no window). Default is headed (`headless: false`) for interactive debugging.
57
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.
58
64
  - `--help` — prints usage.
59
65
 
60
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` between 100 and 500 — lower is faster, higher lets you watch each action.
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
 
@@ -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 ? 1 : 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(1);
46
+ process.exit(2);
46
47
  }
47
48
 
48
- const scrapBody = readFileSync(resolve(scrapPath), 'utf8');
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('puppeteer-core not installed. Run: npm install -g puppeteer-core');
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(1);
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: flags.headless ? 0 : 250,
118
+ slowMo,
95
119
  devtools: !flags.headless,
96
120
  args: ['--no-sandbox'],
97
121
  });