@trawlme/skills 1.2.3 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trawlme/skills",
3
- "version": "1.2.3",
3
+ "version": "1.3.0",
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": {
@@ -10,6 +10,7 @@
10
10
  "skills/**/*.md",
11
11
  "skills/**/references/**",
12
12
  "skills/**/run-local.mjs",
13
+ "skills/**/build-context.mjs",
13
14
  "bin/install.js",
14
15
  "README.md",
15
16
  "LICENSE"
@@ -27,7 +28,7 @@
27
28
  },
28
29
  "scripts": {
29
30
  "install-skill": "node bin/install.js",
30
- "test": "node bin/install.test.mjs && node skills/trawl-scrap-local-test/scripts/run-local.test.mjs"
31
+ "test": "node bin/install.test.mjs && node skills/trawl-scrap-local-test/scripts/run-local.test.mjs && node skills/trawl-scrap-local-test/scripts/build-context.test.mjs"
31
32
  },
32
33
  "keywords": [
33
34
  "trawl",
@@ -91,11 +91,25 @@ trawl scraps update <id> --params-file ./params.json # bulk params from f
91
91
 
92
92
  ### Run / trigger / watch
93
93
 
94
- - `trawl scraps run <id>` — synchronous run, blocks until done
94
+ - `trawl scraps run <id>` — synchronous run via the load endpoint, blocks until done
95
95
  - `trawl scraps run <id> --watch` — same but streams activity logs
96
- - `trawl scraps trigger <id>` — fire-and-forget (returns immediately)
96
+ - `trawl scraps trigger <id>` — **async by default**: queues the worker run and returns immediately (no waiting on the 30-250s run)
97
+ - `trawl scraps trigger <id> --wait` — synchronous: block until the run completes (legacy behaviour)
98
+ - `trawl scraps trigger <id> --watch` — queue, then stream the activity log
97
99
  - `trawl scraps watch <id>` — attach to an in-progress run's activity stream
98
100
 
101
+ ### Inspect past runs
102
+
103
+ ```bash
104
+ trawl scraps history <id> # table of recent runs (status, time, tier, failureKind)
105
+ trawl scraps history <id> --json # JSON array, newest first
106
+ trawl scraps history <id> --limit 50 # cap rows (default 20)
107
+ trawl scraps run-info <hid> # one run's detail by its history id (status, tier, failureKind, error + selector)
108
+ trawl scraps run-info <hid> --json
109
+ ```
110
+
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. (In `history`'s embedded list those columns may be blank — drill into `run-info <hid>` for them.)
112
+
99
113
  ### Delete
100
114
 
101
115
  ```bash
@@ -118,9 +132,16 @@ trawl scraps data "$ID" --json
118
132
 
119
133
  **"Why did this scrap fail?"**
120
134
  ```bash
121
- trawl scraps get <id> --json | jq '.lastRun'
122
- trawl scraps watch <id> # if running, see live errors
135
+ trawl scraps doctor <id> # last-run diagnosis: status/statusDetail, error message, failed selector, block status, empty-context, proxy Tier (0-4), regression, autofix summary
136
+ trawl scraps doctor <id> --autofix # same + full autofix diff/dry-run/knowledge inline
137
+ trawl scraps doctor <id> --json # raw run + autofix JSON
138
+ trawl scraps autofix <id> # full last auto-fix attempt: decision, unified fix diff, dry-run X/Y, knowledge fingerprint + confidence%
139
+ trawl scraps autofix <id> --json # raw autofix JSON
140
+ trawl scraps data <id> --errors # failure diagnostics inline with the data command
141
+ trawl scraps snapshot <id> --error -o /tmp/error.html # download the error-path HTML
142
+ trawl scraps snapshot <id> -o /tmp/page.html # download the captured page HTML
123
143
  ```
144
+ Note: the CLI surfaces the abstract proxy Tier (0–4) + diagnostics + autofix, but **not** cost or proxy nature/IP/vendor — those are admin-only by design.
124
145
 
125
146
  **"Create a job that runs every morning"**
126
147
  ```bash
@@ -15,33 +15,35 @@ Injecting cookies does not change the worker's fingerprint policy.
15
15
 
16
16
  ## Decision tree
17
17
 
18
- 1. **Plain username/password login, no MFA** → use **Trawl-managed credentials** (section below). Trawl stores credentials encrypted; the script reads `account.username` / `account.password` at runtime and calls `saveSession()` after a successful login to reuse the session on subsequent runs.
18
+ 1. **Plain username/password login, no MFA** → use **Trawl-managed credentials** (section below). Trawl stores credentials encrypted; the script reads `TRAWL.account.username` / `TRAWL.account.password` at runtime and calls `saveSession()` after a successful login to reuse the session on subsequent runs.
19
19
 
20
20
  2. **One-shot test or short-lived experiment, or you want to verify your cookies work before setting up persistence** → use **Flavour A — Embedded BYO-cookies**. Hard-code the cookie array directly in the script body. Accepts the trade-off that cookies are in plain text in the script source.
21
21
 
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 `account.session.cookies` via UI, CLI, or API, and the script reads them back before navigation. Cookies are encrypted at rest.
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
24
  ## Trawl-managed credentials (legacy flow)
25
25
 
26
- The script receives two VM globals injected by the worker:
26
+ The worker injects the account credentials under `TRAWL.account`:
27
27
 
28
- - `account.username` — the username stored for this scrap account.
29
- - `account.password` — the password stored for this scrap account.
28
+ - `TRAWL.account.username` — the username stored for this scrap account (alias: `account.username`).
29
+ - `TRAWL.account.password` — the password stored for this scrap account (alias: `account.password`).
30
30
 
31
- After a successful login, call `saveSession(await page.cookies())` immediately. The worker persists the cookie array encrypted at rest and exposes it as `account.session.cookies` on the next run.
31
+ After a successful login, call `saveSession(await page.cookies())` immediately. The worker persists the cookie array encrypted at rest and exposes it as `TRAWL.account.session.cookies` on the next run.
32
+
33
+ > Legacy bare `account.*` (e.g. `account.username`) still works as an alias.
32
34
 
33
35
  ```js
34
36
  const page = await browser.newPage();
35
37
 
36
- if (account.session?.cookies) {
38
+ if (TRAWL.account?.session?.cookies) {
37
39
  // Saved session exists — restore cookies and skip the login flow.
38
- await page.setCookie(...account.session.cookies);
40
+ await page.setCookie(...TRAWL.account.session.cookies);
39
41
  await page.goto('https://example.com/dashboard', { waitUntil: 'domcontentloaded' });
40
42
  } else {
41
43
  // First run (or cleared session) — perform full login.
42
44
  await page.goto('https://example.com/login', { waitUntil: 'domcontentloaded' });
43
- await page.type('#username', account.username);
44
- await page.type('#password', account.password);
45
+ await page.type('#username', TRAWL.account.username);
46
+ await page.type('#password', TRAWL.account.password);
45
47
  await Promise.all([
46
48
  page.click('button[type=submit]'),
47
49
  page.waitForNavigation({ waitUntil: 'networkidle2' }),
@@ -78,7 +80,7 @@ await page.goto('https://example.com/dashboard', { waitUntil: 'domcontentloaded'
78
80
 
79
81
  ## Flavour B — Persisted BYO-cookies
80
82
 
81
- Export cookies from a logged-in browser session. Three write paths exist for `account.session.cookies` (any one is fine; the scrap source reads them back identically):
83
+ Export cookies from a logged-in browser session. Three write paths exist for `TRAWL.account.session.cookies` (any one is fine; the scrap source reads them back identically):
82
84
 
83
85
  - **UI** (one-off / interactive): scrap settings drawer → Account section → **Upload session cookies** → paste a Puppeteer cookie JSON array → Save.
84
86
  - **CLI** (scripted / batch): `trawl scraps account session set <scrap-id> --cookies <file>` (npm `@trawlme/cli` ≥ 1.14.0).
@@ -87,12 +89,12 @@ Export cookies from a logged-in browser session. Three write paths exist for `ac
87
89
  The worker encrypts them at rest; the script reads the same global as the managed flow:
88
90
 
89
91
  ```js
90
- if (!account.session?.cookies) {
91
- throw new Error('Flavour B requires account.session.cookies — push them via UI / CLI / API first.');
92
+ if (!TRAWL.account?.session?.cookies) {
93
+ throw new Error('Flavour B requires TRAWL.account.session.cookies — push them via UI / CLI / API first.');
92
94
  }
93
95
 
94
96
  const page = await browser.newPage();
95
- await page.setCookie(...account.session.cookies);
97
+ await page.setCookie(...TRAWL.account.session.cookies);
96
98
  await page.goto('https://example.com/dashboard', { waitUntil: 'domcontentloaded' });
97
99
  ```
98
100
 
@@ -68,7 +68,7 @@ await page.reload({ waitUntil: 'domcontentloaded' });
68
68
 
69
69
  The worker starts a fresh browser context on each run. Persistence requires:
70
70
 
71
- - `saveSession(await page.cookies())` — stores encrypted, exposed as `account.session.cookies` next run.
71
+ - `saveSession(await page.cookies())` — stores encrypted, exposed as `TRAWL.account.session.cookies` next run (alias: `account.session.cookies`).
72
72
  - Flavour B persistence endpoint — cookies pushed externally.
73
73
 
74
74
  Flavour A re-injects cookies from the script source on every run.
@@ -10,22 +10,22 @@ Async helper injected by the worker. Call after confirming login succeeded — n
10
10
  await saveSession(await page.cookies());
11
11
  ```
12
12
 
13
- The worker persists the cookie array encrypted. On the next run, `account.session.cookies` is populated and the login flow is skipped. Call once per run only.
13
+ The worker persists the cookie array encrypted. On the next run, `TRAWL.account.session.cookies` is populated and the login flow is skipped. Call once per run only.
14
14
 
15
15
  ### Reuse pattern (full code)
16
16
 
17
17
  ```js
18
18
  const page = await browser.newPage();
19
19
 
20
- if (account.session?.cookies) {
20
+ if (TRAWL.account?.session?.cookies) {
21
21
  // Saved session exists — restore cookies and skip the login flow.
22
- await page.setCookie(...account.session.cookies);
22
+ await page.setCookie(...TRAWL.account.session.cookies);
23
23
  await page.goto('https://example.com/dashboard', { waitUntil: 'domcontentloaded' });
24
24
  } else {
25
25
  // First run (or cleared session) — perform full login.
26
26
  await page.goto('https://example.com/login', { waitUntil: 'domcontentloaded' });
27
- await page.type('#username', account.username);
28
- await page.type('#password', account.password);
27
+ await page.type('#username', TRAWL.account.username);
28
+ await page.type('#password', TRAWL.account.password);
29
29
  await Promise.all([
30
30
  page.click('button[type=submit]'),
31
31
  page.waitForNavigation({ waitUntil: 'networkidle2' }),
@@ -35,7 +35,7 @@ if (account.session?.cookies) {
35
35
  }
36
36
  ```
37
37
 
38
- `account.session` is `undefined` on the first run — hence the optional chain. Both branches must reach the same post-login URL before scraping starts.
38
+ `TRAWL.account.session` is `undefined` on the first run — hence the optional chain. Both branches must reach the same post-login URL before scraping starts.
39
39
 
40
40
  ### Forced re-login
41
41
 
@@ -43,7 +43,7 @@ if (account.session?.cookies) {
43
43
  trawl scraps account clear-session <scrap-id>
44
44
  ```
45
45
 
46
- The next run finds `account.session` undefined, falls into the login branch, and re-runs `saveSession` on success.
46
+ The next run finds `TRAWL.account.session` undefined, falls into the login branch, and re-runs `saveSession` on success.
47
47
 
48
48
  ### When the login flow itself breaks
49
49
 
@@ -58,8 +58,8 @@ const page = await browser.newPage();
58
58
 
59
59
  try {
60
60
  await page.goto('https://example.com/login', { waitUntil: 'domcontentloaded' });
61
- await page.type('#username', account.username);
62
- await page.type('#password', account.password);
61
+ await page.type('#username', TRAWL.account.username);
62
+ await page.type('#password', TRAWL.account.password);
63
63
  await Promise.all([
64
64
  page.click('button[type=submit]'),
65
65
  page.waitForNavigation({ waitUntil: 'networkidle2', timeout: 10000 }),
@@ -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
 
@@ -131,6 +131,7 @@ Full detail in `references/anti-patterns.md`. Summary:
131
131
  - No `waitForTimeout(N)` — deprecated and flaky.
132
132
  - No deep CSS chains (`div > div > div > span`) — break on every redesign.
133
133
  - No random jitter as anti-bot defence — detection happens at fingerprint level before timing matters.
134
+ - No bot-challenge detection or vendor-string sniffing (e.g. `if (html.includes('px-captcha'))`) — false-throws on pages that actually loaded. Throw only on structural failures.
134
135
  - No silent `.catch(() => {})` around data extraction.
135
136
 
136
137
  ## Interaction patterns (when the page needs them)
@@ -15,6 +15,8 @@ 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
22
  npm install -g puppeteer-core
@@ -38,7 +40,8 @@ The script body runs in a closure. The harness injects these globals, mirroring
38
40
 
39
41
  - `browser` — the Puppeteer browser instance (headed, with DevTools open).
40
42
  - `TRAWL` — object with `url` (from `--url`) and any `<custom>` keys from `--params`.
41
- - `account` — object with `username` and `password` (from `--account-username` / `--account-password`), plus optional `session.cookies` loaded from a JSON array file via `--account-cookies`.
43
+ - `TRAWL.account` — sub-namespace with `username`, `password`, and optional `session.cookies` (from `--account-username` / `--account-password` / `--account-cookies`). `null` when no credentials are provided (mirrors prod worker).
44
+ - `account` — legacy alias for `TRAWL.account` (still works; both are injected).
42
45
  - `returnData(arr)` — stub that prints the array as JSON to stdout.
43
46
  - `saveSession(cookies)` — stub that prints the cookie array to stdout (does not persist).
44
47
 
@@ -48,9 +51,9 @@ No changes to the script body are needed to run it locally.
48
51
 
49
52
  - `--url=<url>` — sets `TRAWL.url` (use a real value if your script navigates to it).
50
53
  - `--params=k=v[,k=v]*` — sets `TRAWL.<custom>` keys (comma-separated `key=value` pairs).
51
- - `--account-username=<u>` — sets `account.username`.
52
- - `--account-password=<p>` — sets `account.password`.
53
- - `--account-cookies=<path>` — loads `account.session.cookies` from a JSON array file.
54
+ - `--account-username=<u>` — sets `TRAWL.account.username` (alias: `account.username`).
55
+ - `--account-password=<p>` — sets `TRAWL.account.password` (alias: `account.password`).
56
+ - `--account-cookies=<path>` — loads `TRAWL.account.session.cookies` from a JSON array file (alias: `account.session.cookies`).
54
57
  - `--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`.
55
58
  - `--headless` — launches Chrome headlessly (no window). Default is headed (`headless: false`) for interactive debugging.
56
59
  - `--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.
@@ -76,6 +79,18 @@ An empty result has 5 causes: real bot-wall · first-visit interstitial (consent
76
79
  - Local runs use the user's IP — no proxy tier, no fingerprint policy.
77
80
  - Local pass does not guarantee worker pass — script logic is tested, not the network surface.
78
81
 
82
+ ## Diagnosing prod failures
83
+
84
+ To diagnose a *prod* failure (vs debugging locally), use the CLI instead of re-running blind:
85
+
86
+ ```bash
87
+ trawl scraps doctor <id> # last-run error + failed selector + block status + autofix summary
88
+ trawl scraps autofix <id> # full auto-fix detail: decision, diff, dry-run, knowledge consulted
89
+ trawl scraps snapshot <id> --error -o /tmp/err.html # download the error-path page HTML
90
+ ```
91
+
92
+ These commands surface what the worker captured (same info as the web frontend's "Last run" panel) without exposing cost or proxy-vendor internals.
93
+
79
94
  ## What this skill does NOT cover
80
95
 
81
96
  - Script body → `trawl-scrap-design`
@@ -0,0 +1,44 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { resolve } from 'node:path';
3
+
4
+ /**
5
+ * Build the script-VM context (TRAWL + account) from parsed CLI flags, mirroring
6
+ * the worker runtime contract (#786): credentials are exposed BOTH under the
7
+ * forward `TRAWL.account.*` sub-namespace AND the legacy bare `account` global
8
+ * (a retained alias). `readFile` is injected so the builder stays pure/testable.
9
+ * @param {Record<string, string|true>} flags - Parsed CLI flags.
10
+ * @param {(path: string) => string} [readFile] - File reader (injected in tests).
11
+ * @returns {{ TRAWL: object, account: object }}
12
+ */
13
+ export function buildContext(flags, readFile = (p) => readFileSync(resolve(p), 'utf8')) {
14
+ // A flag passed without `=value` parses to boolean `true` (see run-local.mjs's
15
+ // parser). Coerce any non-string flag to null so a value-less flag can't leak a
16
+ // boolean into the context (e.g. `TRAWL.account.username === true`) or crash
17
+ // `readFile(true)`.
18
+ const str = (v) => (typeof v === 'string' ? v : null);
19
+
20
+ const TRAWL = { url: str(flags.url) };
21
+ if (typeof flags.params === 'string') {
22
+ for (const pair of flags.params.split(',')) {
23
+ const eqIdx = pair.indexOf('=');
24
+ if (eqIdx <= 0) continue;
25
+ TRAWL[pair.slice(0, eqIdx)] = pair.slice(eqIdx + 1);
26
+ }
27
+ }
28
+
29
+ const account = {
30
+ username: str(flags['account-username']),
31
+ password: str(flags['account-password']),
32
+ };
33
+ const cookiesPath = str(flags['account-cookies']);
34
+ if (cookiesPath) {
35
+ account.session = { cookies: JSON.parse(readFile(cookiesPath)) };
36
+ }
37
+
38
+ // Parity with the worker (trawl_node#786): also expose creds under TRAWL.account.*.
39
+ // null when nothing was provided, mirroring buildTrawlAccount's null-when-empty contract.
40
+ const hasAccount = !!(account.username || account.password || account.session);
41
+ TRAWL.account = hasAccount ? account : null;
42
+
43
+ return { TRAWL, account };
44
+ }
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  // Local Trawl scrap harness — mirrors the worker entry contract.
3
- // Globals injected: browser, TRAWL, account, returnData, saveSession.
3
+ // Globals injected: browser, TRAWL (incl. TRAWL.account.*), account (legacy alias), returnData, saveSession.
4
4
  import { readFileSync, existsSync } from 'node:fs';
5
5
  import { resolve } from 'node:path';
6
+ import { buildContext } from './build-context.mjs';
6
7
 
7
8
  const args = process.argv.slice(2);
8
9
 
@@ -12,9 +13,9 @@ function help() {
12
13
  Flags:
13
14
  --url=<url> TRAWL.url
14
15
  --params=k=v[,k=v]* TRAWL.<custom> keys
15
- --account-username=<user> account.username
16
- --account-password=<pwd> account.password
17
- --account-cookies=<path> account.session.cookies (JSON array)
16
+ --account-username=<user> TRAWL.account.username (alias: account.username)
17
+ --account-password=<pwd> TRAWL.account.password (alias: account.password)
18
+ --account-cookies=<path> TRAWL.account.session.cookies (alias: account.session.cookies; JSON array)
18
19
  --remote connect to existing Chrome at 127.0.0.1:9222
19
20
  --headless launch Chrome in headless mode (no window)
20
21
  --chrome=<path> path to Chrome executable (auto-detected if omitted)
@@ -46,22 +47,7 @@ if (!scrapPath) {
46
47
 
47
48
  const scrapBody = readFileSync(resolve(scrapPath), 'utf8');
48
49
 
49
- const TRAWL = { url: flags.url || null };
50
- if (typeof flags.params === 'string') {
51
- for (const pair of flags.params.split(',')) {
52
- const eqIdx = pair.indexOf('=');
53
- if (eqIdx <= 0) continue;
54
- const k = pair.slice(0, eqIdx);
55
- const v = pair.slice(eqIdx + 1);
56
- TRAWL[k] = v;
57
- }
58
- }
59
-
60
- const account = { username: flags['account-username'] || null, password: flags['account-password'] || null };
61
- if (flags['account-cookies']) {
62
- const cookies = JSON.parse(readFileSync(resolve(flags['account-cookies']), 'utf8'));
63
- account.session = { cookies };
64
- }
50
+ const { TRAWL, account } = buildContext(flags);
65
51
 
66
52
  let puppeteer;
67
53
  try {