@trawlme/cli 4.0.9 → 4.0.11

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 CHANGED
@@ -72,7 +72,7 @@ trawl spec [--json] Print a versioned, machine-readab
72
72
 
73
73
  > **No breaking change:** every verb above is also still reachable under its pre-reorg path, `trawl scraps <verb>` (e.g. `trawl scraps list`, `trawl scraps run <id>`) — kept as a hidden alias so scripts written before the surface reorg keep working. `trawl --help` only shows the top-level form above; `trawl scraps --help` only shows the remaining scrap-management commands below.
74
74
 
75
- `create`/`whoami`/`ping` are fully non-interactive — all three read auth only from `TRAWL_API_KEY`/`TRAWL_TOKEN`/the stored login token, never prompt (`whoami` is JWT-only — see [Authentication](#authentication) — so it still refuses honestly under a key instead of prompting). `trawl create` runs the AI wizard server-side (`POST /api/ai/wizard`): generate scrap code from `--prompt` via LLM, persist the scrap, trigger its FIRST run, and auto-fix on failure (default on — `--no-autofix` disables it, sending `autoFix:false`). The created scrap's AI digest is on by default when the account has an email; `--no-digest` disables it at creation (sending `digest:{enabled:false}`) — change the mode or prompt afterwards with `trawl scraps update <id> --digest-mode`/`--digest-prompt` (one command = one route). On a successful first run (human mode) it prints a small **data sample** (item count + first-item fields + one truncated value) as proof of value — best-effort, silent if the sample can't be fetched — and points `Next step` at `trawl data <id>` (the data), with `trawl get <id>` as the secondary detail view. `--json` skips the sample fetch and prints the raw wizard payload verbatim. `success` is an honest outcome of that first run, not "did the HTTP call succeed" — a failed first run is still a 200 response (the scrap was still created; auto-fix, when enabled, retries in the background), and the CLI exits 1 in that case (both human and `--json` modes) even though `--json` always prints the raw payload verbatim. The call legitimately takes many minutes server-side (AI generation + a proxy-tier probe ladder + an iteration loop + a real run), so it reads the wizard's NDJSON progress stream (`Accept: application/x-ndjson`) — human mode prints one short line per stage on stderr, `--json` prints only the final payload, same shape as always — and arms a 4800s safety ceiling of its own, longer than the 1380s `run`/`data --fresh`/`trigger --wait` use below, over a transport of its own (Node's global `fetch` cannot wait past ~300s whatever ceiling is asked for). `trawl whoami`/`trawl ping` mirror the MCP `trawl_whoami`/`trawl_health_ping` tools as closely as the REST surface allows (`GET /api/users/me` / `GET /api/health`) — `ping`'s `--json` payload is admin-enriched (version/uptime/db) and just `{"status":"ok"}` for anyone else.
75
+ `create`/`whoami`/`ping` are fully non-interactive — all three read auth only from `TRAWL_API_KEY`/`TRAWL_TOKEN`/the stored login token, never prompt (`whoami` is JWT-only — see [Authentication](#authentication) — so it still refuses honestly under a key instead of prompting). `trawl create` runs the AI wizard server-side (`POST /api/ai/wizard`): generate scrap code from `--prompt` via LLM, persist the scrap, trigger its FIRST run, and make one AI repair of it if it fails (default on — `--no-autofix` sends `autoFix:false` and the setup then makes no repair at all). The created scrap's AI digest is on by default when the account has an email; `--no-digest` disables it at creation (sending `digest:{enabled:false}`) — change the mode or prompt afterwards with `trawl scraps update <id> --digest-mode`/`--digest-prompt` (one command = one route). On a successful first run (human mode) it prints a small **data sample** (item count + first-item fields + one truncated value) as proof of value — best-effort, silent if the sample can't be fetched — and points `Next step` at `trawl data <id>` (the data), with `trawl get <id>` as the secondary detail view. `--json` skips the sample fetch and prints the raw wizard payload verbatim. `success` is an honest outcome of that first run, not "did the HTTP call succeed" — it is true only when the first run (or the one repair the wizard makes of it, none under `--no-autofix`) brought data. Otherwise it is a 200 response with `success:false`: the scrap was created but is **not finished — no data yet**, nothing retries it in the background, and human mode points at fixing it on the scrap page or in its script; the CLI exits 1 in that case (both human and `--json` modes) even though `--json` always prints the raw payload verbatim. The call legitimately takes many minutes server-side (AI generation + a proxy-tier probe ladder + an iteration loop + a real run), so it reads the wizard's NDJSON progress stream (`Accept: application/x-ndjson`) — human mode prints one short line per stage on stderr, `--json` prints only the final payload, same shape as always — and arms a 4800s safety ceiling of its own, longer than the 1380s `run`/`data --fresh`/`trigger --wait` use below, over a transport of its own (Node's global `fetch` cannot wait past ~300s whatever ceiling is asked for). `trawl whoami`/`trawl ping` mirror the MCP `trawl_whoami`/`trawl_health_ping` tools as closely as the REST surface allows (`GET /api/users/me` / `GET /api/health`) — `ping`'s `--json` payload is admin-enriched (version/uptime/db) and just `{"status":"ok"}` for anyone else.
76
76
 
77
77
  > **`create` is NOT idempotent, and every wizard-created scrap runs on a WEEKLY cron by default.** A transport failure — a client-side timeout, a progress stream cut or ended without a result, a connection dropped after the API already answered (exit `5`, a `NetworkError`), or a gateway `502`/`504` — does not mean the wizard failed server-side: scrap creation + the first run keep going after the CLI gives up waiting, so the scrap may already exist. In human mode the CLI prints a stderr warning whenever the request reached the API without returning a complete answer; under `--json` there is no warning and no extra envelope field — a machine caller sees exit `5` (or, for a gateway `502`/`504`, exit `1` with `status` 502/504) and must check `trawl list` itself. Run `trawl list` and look for a matching URL/title **before** retrying — a blind retry creates a DUPLICATE scrap and burns AI-generation quota a second time for the same goal. Separately, the scrap the wizard creates is scheduled to re-run every week, on Monday at 07:00 UTC (`cron: "0 7 * * 1"`, hardcoded server-side, unrelated to `--no-autofix`) — each of those recurring runs consumes execute quota like any other run. Review the generated scrap, then change or disable the schedule with `trawl scraps update <id> --cron <expr>` (or `--no-cron` to disable it). Because the call can legitimately run many minutes, also confirm `TRAWL_TIMEOUT` isn't set to something tighter than `create` needs — the env var always wins over `create`'s own 4800s default (see [Environment variables](#environment-variables)), so a value set for another purpose (e.g. a tight CI smoke-test budget) silently clamps `create` too; unset it or raise it before running `create`.
78
78
 
@@ -12,16 +12,14 @@ import { runIdOf } from '../lib/runs.js';
12
12
  function unverifiedSuccess(data) {
13
13
  return data.success && data.verified === false;
14
14
  }
15
- function firstRunLabel(data, autoFixEnabled) {
15
+ function firstRunLabel(data) {
16
16
  if (unverifiedSuccess(data))
17
17
  return 'succeeded — script not verified by the wizard, check the rows';
18
18
  if (data.success)
19
19
  return 'succeeded';
20
20
  if (!data.scrap)
21
21
  return 'failed (no scrap was persisted)';
22
- if (autoFixEnabled)
23
- return 'failed (auto-fix retrying in the background)';
24
- return 'failed';
22
+ return 'not finished — no data yet';
25
23
  }
26
24
  const WEEKDAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
27
25
  function describeCron(cron) {
@@ -89,7 +87,7 @@ export const create = new Command('create')
89
87
  .argument('[url]', 'Target public URL (http/https)')
90
88
  .requiredOption('--prompt <goal>', 'What to extract/scrape, in plain language (required)')
91
89
  .option('--url <url>', 'Target public URL — alias of the positional argument')
92
- .option('--no-autofix', 'Disable AI auto-fix on first-run failure (default: on)')
90
+ .option('--no-autofix', 'Skip the one AI repair of a failed first run (default: on)')
93
91
  .option('--no-digest', 'Disable the AI digest on the created scrap (default: on when the account has an email)')
94
92
  .option('--json', 'Output the raw API payload')
95
93
  .action(async (rawUrl, opts) => {
@@ -156,26 +154,23 @@ export const create = new Command('create')
156
154
  const rawRunId = runIdOf(data);
157
155
  const runId = printable(rawRunId);
158
156
  const title = printable(data.scrap?.title ?? url);
159
- const autoFixEnabled = opts.autofix !== false;
160
157
  const schedule = scheduleLabel(data.scrap);
161
158
  console.log(`${data.success ? chalk.green('✓') : chalk.red('✗')} ${chalk.bold(title)}`);
162
159
  console.log(chalk.dim(` Scrap ID: `) + (scrapId || '—'));
163
160
  if (runId)
164
161
  console.log(chalk.dim(` Run ID: `) + runId);
165
- console.log(chalk.dim(` First run: `) + firstRunLabel(data, autoFixEnabled));
162
+ console.log(chalk.dim(` First run: `) + firstRunLabel(data));
166
163
  if (schedule)
167
164
  console.log(chalk.dim(` Schedule: `) + schedule);
168
165
  if (data.success && rawRunId)
169
166
  await printDataSample(rawRunId);
170
- if (scrapId) {
167
+ if (scrapId && data.success) {
171
168
  console.log(chalk.dim(` Next step: `) + `trawl data ${scrapId}` + chalk.dim(` (details: trawl get ${scrapId})`));
172
169
  }
173
- if (!data.success && data.scrap && autoFixEnabled) {
174
- const pollTarget = runId
175
- ? `\`trawl data ${scrapId}\` or \`trawl run-info ${runId}\``
176
- : `\`trawl data ${scrapId}\``;
177
- console.log(chalk.yellow(` Note: `) +
178
- `Auto-fix is retrying in the background — do NOT re-run create; poll ${pollTarget}.`);
170
+ else if (scrapId) {
171
+ console.log(chalk.dim(` Next step: `) +
172
+ `open scrap ${scrapId} on its page to fix it, or edit the script` +
173
+ chalk.dim(` (details: trawl get ${scrapId})`));
179
174
  }
180
175
  if (!opts.json && pinchEnabled()) {
181
176
  const mood = !data.success ? 'confused' : unverifiedSuccess(data) ? 'idle' : 'celebrating';
@@ -71,6 +71,7 @@ interface ScrapHead {
71
71
  }
72
72
  export declare function pickRun(run: Run): Partial<Run>;
73
73
  export declare function pickFix(fix: FixActivity | null): Partial<FixActivity> | null;
74
+ export declare function errorNamesSelector(messages: Array<string | null | undefined>, selector: string): boolean;
74
75
  export declare function formatDoctor(scrapTitle: string, run: Run, fix?: FixActivity | null, scrapId?: string): string;
75
76
  export declare function formatAutofix(fix: FixActivity): string;
76
77
  export declare function fetchRunAndFix(scrapId: string): Promise<{
@@ -52,6 +52,10 @@ export function pickFix(fix) {
52
52
  .filter((k) => k in fix)
53
53
  .map((k) => [k, fix[k]]));
54
54
  }
55
+ export function errorNamesSelector(messages, selector) {
56
+ const forms = ['`', '"', "'"].map((q) => q + selector + q).concat('selector: ' + selector);
57
+ return messages.some((m) => !!m && forms.some((f) => m.includes(f)));
58
+ }
55
59
  export function formatDoctor(scrapTitle, run, fix = null, scrapId) {
56
60
  const lines = [];
57
61
  const ok = run.status === true;
@@ -83,8 +87,12 @@ export function formatDoctor(scrapTitle, run, fix = null, scrapId) {
83
87
  else if (errMsg && !authHintWillRender) {
84
88
  lines.push(chalk.dim(' Error: ') + chalk.red(errMsg));
85
89
  }
86
- if (run.errorSnapshot?.selector) {
87
- lines.push(chalk.dim(' Failed selector: ') + chalk.cyan(run.errorSnapshot.selector));
90
+ const selector = run.errorSnapshot?.selector;
91
+ if (selector) {
92
+ const label = errorNamesSelector([run.errorMessage, run.errorSnapshot?.errorMessage], selector)
93
+ ? ' Failed selector: '
94
+ : ' Last selector tried: ';
95
+ lines.push(chalk.dim(label) + chalk.cyan(selector));
88
96
  }
89
97
  lines.push(chalk.dim(' Blocked: ') + (run.blocked ? chalk.red('yes') : 'no'));
90
98
  if (run.proxyTier && TIER_LABELS[run.proxyTier]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trawlme/cli",
3
- "version": "4.0.9",
3
+ "version": "4.0.11",
4
4
  "description": "Trawl CLI — manage scraps from the terminal",
5
5
  "type": "module",
6
6
  "bin": {
@@ -41,7 +41,7 @@
41
41
  "url": "https://github.com/comes-io/trawl_cli/issues"
42
42
  },
43
43
  "dependencies": {
44
- "@trawlme/skills": "1.4.11",
44
+ "@trawlme/skills": "1.4.12",
45
45
  "chalk": "^6.0.1",
46
46
  "commander": "^15.0.0",
47
47
  "conf": "^16.0.0",