@trawlme/cli 3.12.6 → 3.13.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/README.md CHANGED
@@ -49,7 +49,7 @@ All commands accept a global `--debug` flag to show full error stack traces on f
49
49
  ### Core commands (agent + human)
50
50
 
51
51
  ```
52
- trawl create <url> --prompt <goal> [--no-autofix] [--json] # url also accepted as --url <url> (#116)
52
+ trawl create <url> --prompt <goal> [--no-autofix] [--no-digest] [--json] # url also accepted as --url <url> (#116)
53
53
  Create a persistent, self-healing scrap from a URL + a goal (AI-generated)
54
54
  trawl list|ls [--json] [--status <success|failure|never|running|regression>] [--unhealthy] [--limit <n>] [--page <n>]
55
55
  trawl get <id> [--json] Get scrap details
@@ -68,7 +68,7 @@ trawl spec [--json] Print a versioned, machine-readab
68
68
 
69
69
  > **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.
70
70
 
71
- `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`). 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 3600s safety ceiling of its own, longer than the 660s `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.
71
+ `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 3600s safety ceiling of its own, longer than the 660s `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.
72
72
 
73
73
  > **`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 3600s 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`.
74
74
 
@@ -89,7 +89,7 @@ trawl spec [--json] Print a versioned, machine-readab
89
89
 
90
90
  ```
91
91
  trawl scraps create -t <title> -u <url> [-r <request>] [-d <description>] [--tier <tier0|tier1|tier2|tier3|tier4>] [--json]
92
- trawl scraps update <id> [-t <title>] [-u <url>] [-r <request>] [-d <description>] [--cron <expr>|--no-cron] [--alert <email>|--no-alert] [--autofix|--no-autofix] [-p <json>|--params-file <path>] [--tier <tier0|tier1|tier2|tier3|tier4>] [--force-tier <tier0|tier1|tier2|tier3|tier4>] [--json]
92
+ trawl scraps update <id> [-t <title>] [-u <url>] [-r <request>] [-d <description>] [--cron <expr>|--no-cron] [--alert <email>|--no-alert] [--autofix|--no-autofix] [--digest|--no-digest] [--digest-mode <latest|changes|changes_only>] [--digest-prompt <text>] [-p <json>|--params-file <path>] [--tier <tier0|tier1|tier2|tier3|tier4>] [--force-tier <tier0|tier1|tier2|tier3|tier4>] [--json]
93
93
  trawl scraps watch <id> [--json]
94
94
  trawl scraps doctor <id> [--json] [--autofix]
95
95
  trawl scraps autofix <id> [--json]
@@ -100,6 +100,7 @@ trawl scraps delete <id> [--force] [--json] Alias: rm
100
100
 
101
101
  - `-u/--url` is **the site the scrap targets**, not necessarily the exact URL fetched at run time — a scrap whose real target is computed inside its `-r/--request` script (a templated search query, an interpolated item id, e.g. `https://www.ebay.com/sch/i.html?_nkw=${query}`) should still supply a base/site URL. Every domain-level policy (proxy tier ceiling, provider routing, per-domain memoize) keys off this field, so a blank value silently disables all of it. `create` requires it — validated client-side (must parse as an `http`/`https` URL) so a missing or malformed value fails fast with a readable usage error (exit 2) instead of a raw server 400/422; `update` keeps it optional (omitting it is still a no-op, matching the API) but a value that **is** passed is validated the same way.
102
102
  - `--tier` forces a proxy tier; `--force-tier` raises the proxy-tier ceiling past the auto-cap (history-gated: may be refused or cost more). `create --json`/`update --json` print the full scrap object (including the `_tierOverride` outcome) on stdout; a refused tier override exits 1 with a standard `--json` error envelope (`kind:"refused"` — distinct from `"unknown"`, so a script can branch on "the server said no"). When a tier was requested but the server's response carries no `_tierOverride` at all (an older server that can't confirm what actually got applied), a stderr warning is printed either way, and under `--json` the emitted object also carries `"_tierUnconfirmed": true` — the machine-readable counterpart to that warning, since a `--json` caller has no reliable reason to read stderr.
103
+ - `update`'s digest settings live on one `digest` object server-side — `--digest`/`--no-digest` (enable/disable), `--digest-mode <latest|changes|changes_only>` (`latest`: this run's data; `changes`: what changed since the last successful run, computed by code; `changes_only`: the same, but no digest at all when nothing changed), `--digest-prompt <text>` (empty string clears it). The server does a **partial merge**: only the flags you actually pass are sent, and the keys you omit keep their current value. `create --no-digest` only ever disables the digest at creation (one command = one route) — set the mode or prompt afterwards with `scraps update`.
103
104
 
104
105
  `list --unhealthy` has the same shape of guard: against a server that predates the filter, the command warns on stderr and, under `--json`, wraps the payload as `{ "scraps": [...], "_healthFilterUnconfirmed": true }` instead of emitting a bare array — so a script can tell an unfiltered list from a genuinely-unhealthy one. A confirming server returns the bare array unchanged.
105
106
  - `scraps doctor` diagnoses the last run (error, failed selector, block status, page state, autofix outcome); `--autofix` includes the full autofix diff/dry-run/knowledge. A run that is still in flight (`status: null`, server-side) shows a `running` badge, never `failed`; a run whose item count regressed vs baseline (`statusDetail: "regression"`) shows its own amber `regression` badge, never `failed` either.
@@ -220,7 +221,7 @@ Every command exits with one of these codes — scripts and agents driving the C
220
221
  | Code | Meaning |
221
222
  |------|--------------------------------------------------------------------------|
222
223
  | `0` | Success |
223
- | `1` | Unknown/generic error (an unmapped failure — API errors other than 401/404, an unhandled bug — or a business-logic refusal like `data`'s `run_failed`/`in_progress` states, or `trawl create`'s honest `success:false` first-run outcome). **Known overload:** `create`'s domain-level failure and an arbitrary unmapped bug both land on `1` — a script needs to read the `--json` payload's own `success` field (for `create`) to tell them apart; this is intentional (the REST contract's outcome states are a separate axis from the CLI's transport-error taxonomy) and documented here rather than "resolved" by inventing a new code that would only apply to one command. |
224
+ | `1` | Unknown/generic error (an unmapped failure — API errors other than 401/404, an unhandled bug — or a business-logic refusal like `data`'s `run_failed`/`in_progress` states, or `trawl create`'s honest `success:false` first-run outcome). **Known overload:** `create`'s domain-level failure and an arbitrary unmapped bug both land on `1` — a script needs to read the `--json` payload's own `success` field (for `create`) to tell them apart (and its `verified` field: `success: true` with `verified: false` exits `0` but the wizard never confirmed the script, so check the rows); this is intentional (the REST contract's outcome states are a separate axis from the CLI's transport-error taxonomy) and documented here rather than "resolved" by inventing a new code that would only apply to one command. |
224
225
  | `2` | Usage error (bad flag/value, invalid ID, missing required argument, unknown option/command — including the [non-interactive rule](#non-interactive-rule) refusing to prompt) |
225
226
  | `3` | Auth error (not logged in, the session token is expired/invalid, or a JWT-only command was run under an API key — see [Authentication](#authentication)) — run `trawl login` |
226
227
  | `4` | Not found (no such resource, or — for `data` — no persisted payload to read) |
@@ -1,6 +1,7 @@
1
1
  import { Command } from 'commander';
2
2
  export interface WizardResponse {
3
3
  success: boolean;
4
+ verified?: boolean;
4
5
  scrap?: {
5
6
  _id: string;
6
7
  title: string;
@@ -8,7 +8,12 @@ import { requireUrl, requireString } from '../lib/validate.js';
8
8
  import { UsageError, RefusalError, HUMAN_ERROR_MAX } from '../lib/errors.js';
9
9
  import { renderPinch, pinchEnabled } from '../lib/pinch.js';
10
10
  import { startPinchAnimation } from '../lib/pinchAnimation.js';
11
+ function unverifiedSuccess(data) {
12
+ return data.success && data.verified === false;
13
+ }
11
14
  function firstRunLabel(data, autoFixEnabled) {
15
+ if (unverifiedSuccess(data))
16
+ return 'succeeded — script not verified by the wizard, check the rows';
12
17
  if (data.success)
13
18
  return 'succeeded';
14
19
  if (!data.scrap)
@@ -84,6 +89,7 @@ export const create = new Command('create')
84
89
  .requiredOption('--prompt <goal>', 'What to extract/scrape, in plain language (required)')
85
90
  .option('--url <url>', 'Target public URL — alias of the positional argument')
86
91
  .option('--no-autofix', 'Disable AI auto-fix on first-run failure (default: on)')
92
+ .option('--no-digest', 'Disable the AI digest on the created scrap (default: on when the account has an email)')
87
93
  .option('--json', 'Output the raw API payload')
88
94
  .action(async (rawUrl, opts) => {
89
95
  if (rawUrl === undefined && opts.url === undefined) {
@@ -98,6 +104,7 @@ export const create = new Command('create')
98
104
  url,
99
105
  goal,
100
106
  ...(opts.autofix === false && { autoFix: false }),
107
+ ...(opts.digest === false && { digest: { enabled: false } }),
101
108
  };
102
109
  const call = (onEvent) => api
103
110
  .postLongRunning('/api/ai/wizard', body, { timeoutMs: WIZARD_TIMEOUT_MS, onEvent })
@@ -169,7 +176,8 @@ export const create = new Command('create')
169
176
  `Auto-fix is retrying in the background — do NOT re-run create; poll ${pollTarget}.`);
170
177
  }
171
178
  if (!opts.json && pinchEnabled()) {
172
- console.log(data.success ? renderPinch('celebrating') : renderPinch('confused'));
179
+ const mood = !data.success ? 'confused' : unverifiedSuccess(data) ? 'idle' : 'celebrating';
180
+ console.log(renderPinch(mood));
173
181
  }
174
182
  }
175
183
  if (!data.success)
@@ -366,6 +366,7 @@ export function attachGetCommand(parent, attachOpts = {}) {
366
366
  }
367
367
  attachGetCommand(scraps, { hidden: true });
368
368
  const VALID_TIERS = ['tier0', 'tier1', 'tier2', 'tier3', 'tier4'];
369
+ const VALID_DIGEST_MODES = ['latest', 'changes', 'changes_only'];
369
370
  function renderTierOverrideHuman(data) {
370
371
  const ov = data._tierOverride;
371
372
  if (!ov)
@@ -459,6 +460,10 @@ scraps
459
460
  .option('--no-alert', 'Disable failure alert email (set to null)')
460
461
  .option('--autofix', 'Enable AI Fix (auto-recovery on selector breakage)')
461
462
  .option('--no-autofix', 'Disable AI Fix')
463
+ .option('--digest', 'Enable the AI digest (partial update — other digest settings are kept)')
464
+ .option('--no-digest', 'Disable the AI digest (partial update — other digest settings are kept)')
465
+ .option('--digest-mode <mode>', `Digest mode (${VALID_DIGEST_MODES.join('|')} — latest: this run's data · changes: only what changed · changes_only: like changes, no mail when nothing changed; partial update — other digest settings are kept)`)
466
+ .option('--digest-prompt <text>', 'Digest prompt (empty string to clear; partial update — other digest settings are kept)')
462
467
  .option('-p, --params <json>', 'Runtime params as JSON array of objects (e.g. \'[{"TRAWL.paramName":"value"}]\')')
463
468
  .option('--params-file <path>', 'Runtime params from a JSON file')
464
469
  .option('--tier <tier>', `Force proxy tier (${VALID_TIERS.join('|')})`)
@@ -474,6 +479,10 @@ scraps
474
479
  usageError(`Invalid --force-tier "${opts.forceTier}" (allowed: ${VALID_TIERS.join(', ')})`, { json: opts.json });
475
480
  return;
476
481
  }
482
+ if (opts.digestMode !== undefined && !VALID_DIGEST_MODES.includes(opts.digestMode)) {
483
+ usageError(`Invalid --digest-mode "${opts.digestMode}" (allowed: ${VALID_DIGEST_MODES.join(', ')})`, { json: opts.json });
484
+ return;
485
+ }
477
486
  const body = {};
478
487
  if (opts.title !== undefined)
479
488
  body.title = opts.title;
@@ -499,6 +508,17 @@ scraps
499
508
  body.autoFix = true;
500
509
  else if (opts.autofix === false)
501
510
  body.autoFix = false;
511
+ const digestPatch = {};
512
+ if (opts.digest === true)
513
+ digestPatch.enabled = true;
514
+ else if (opts.digest === false)
515
+ digestPatch.enabled = false;
516
+ if (opts.digestMode !== undefined)
517
+ digestPatch.mode = opts.digestMode;
518
+ if (opts.digestPrompt !== undefined)
519
+ digestPatch.prompt = opts.digestPrompt === '' ? null : opts.digestPrompt;
520
+ if (Object.keys(digestPatch).length > 0)
521
+ body.digest = digestPatch;
502
522
  if (opts.params !== undefined || opts.paramsFile !== undefined) {
503
523
  let raw;
504
524
  if (opts.paramsFile) {
@@ -556,6 +576,15 @@ scraps
556
576
  for (const key of Object.keys(body)) {
557
577
  if (key === 'proxyTier' || key === 'proxyMaxTier')
558
578
  continue;
579
+ if (key === 'digest') {
580
+ const digestShown = shown['digest'];
581
+ if (digestShown === undefined) {
582
+ console.error(chalk.yellow(' ⚠ Server did not confirm the digest change (older server) — it may not support digest yet.'));
583
+ continue;
584
+ }
585
+ console.log(chalk.dim(` digest: `) + printable(JSON.stringify(digestShown), HUMAN_ERROR_MAX));
586
+ continue;
587
+ }
559
588
  const src = key in shown ? shown[key] : body[key];
560
589
  console.log(chalk.dim(` ${key}: `) + (printable(src, HUMAN_ERROR_MAX) || '—'));
561
590
  }
@@ -79,7 +79,7 @@ first-class on every one, and none of them ever blocks on a prompt (see
79
79
  [Non-interactive contract](#non-interactive-contract) below):
80
80
 
81
81
  ```
82
- trawl create <url> --prompt <goal> [--no-autofix] [--json] # url also accepted as --url <url> (#116)
82
+ trawl create <url> --prompt <goal> [--no-autofix] [--no-digest] [--json] # url also accepted as --url <url> (#116)
83
83
  Create a persistent, self-healing scrap from a URL + a goal (AI-generated)
84
84
  trawl list|ls [--json] [--status <s>] [--unhealthy] [--limit <n>] [--page <n>] List all scraps
85
85
  trawl get <id> [--json] Get scrap details
@@ -101,7 +101,11 @@ first run, and auto-fix on failure (default on; `--no-autofix` disables it).
101
101
  `success` is an honest outcome of that first run, not "did the HTTP call
102
102
  succeed" — a failed first run is still a 200 response (the scrap was still
103
103
  created), and the CLI exits `1` in that case even though `--json` always
104
- prints the raw payload verbatim. The call legitimately runs many minutes
104
+ prints the raw payload verbatim. A `success: true` with `verified: false` means
105
+ the first run returned rows but the wizard never confirmed that exact script
106
+ (it stopped before `finish`): check the rows before trusting it — human mode
107
+ says "succeeded — script not verified by the wizard, check the rows", `--json`
108
+ callers read `verified`. The call legitimately runs many minutes
105
109
  server-side (AI generation + a proxy-tier probe ladder + an iteration loop +
106
110
  a real run), so the CLI reads the wizard's NDJSON progress stream: human mode
107
111
  prints one short line per stage on stderr, `--json` prints only the final
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trawlme/cli",
3
- "version": "3.12.6",
3
+ "version": "3.13.0",
4
4
  "description": "Trawl CLI — manage scraps from the terminal",
5
5
  "type": "module",
6
6
  "bin": {