@trawlme/cli 3.12.7 → 3.14.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 +8 -7
- package/dist/commands/create.d.ts +1 -0
- package/dist/commands/create.js +13 -9
- package/dist/commands/doctor.d.ts +5 -0
- package/dist/commands/doctor.js +2 -1
- package/dist/commands/scraps.d.ts +1 -1
- package/dist/commands/scraps.js +42 -11
- package/dist/index.js +2 -2
- package/dist/lib/runs.d.ts +8 -0
- package/dist/lib/runs.js +6 -0
- package/docs/agent-quickstart.md +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ Four methods:
|
|
|
36
36
|
3. **Token flag** — `trawl login --token <jwt>` (CI/CD, direct JWT)
|
|
37
37
|
4. **API key** — `TRAWL_API_KEY=trawl_xxx trawl list` (scoped, revocable one-by-one — the recommended credential for an agent driving this CLI; see [docs/agent-quickstart.md](docs/agent-quickstart.md))
|
|
38
38
|
|
|
39
|
-
A `TRAWL_API_KEY` is a `trawl_*`-prefixed credential (create/revoke one in the Trawl dashboard) sent as `Authorization: Bearer` instead of the session `Cookie: TOKEN=` a JWT uses — `trawl` picks the right one automatically based on the credential's own shape, never a flag. `TRAWL_API_KEY` wins over `TRAWL_TOKEN` when both happen to be set. It is scoped server-side — in practice to a set of scraps, since the dashboard's key-create form sets only the scrap allow-list; narrowing which *actions* a key may perform needs an explicit `scopes` array at creation over the API, and a key without one has every action granted. It works on most of the Core tier — `create`/`list`/`get`/`data`/`
|
|
39
|
+
A `TRAWL_API_KEY` is a `trawl_*`-prefixed credential (create/revoke one in the Trawl dashboard) sent as `Authorization: Bearer` instead of the session `Cookie: TOKEN=` a JWT uses — `trawl` picks the right one automatically based on the credential's own shape, never a flag. `TRAWL_API_KEY` wins over `TRAWL_TOKEN` when both happen to be set. It is scoped server-side — in practice to a set of scraps, since the dashboard's key-create form sets only the scrap allow-list; narrowing which *actions* a key may perform needs an explicit `scopes` array at creation over the API, and a key without one has every action granted. It works on most of the Core tier — `create`/`list`/`get`/`data`/`runs`/`run-info`/`run`/`trigger`/`ping`, including the `--watch` **polling flag** on `run`/`trigger` — plus, outside Core, `scraps account status`/`scraps doctor`/`scraps autofix` (all three only ever read routes the API opened to keys). It does **not** work on `whoami`, `scraps update`/`delete`, `scraps account set`/`delete`/`clear-session`/`session set`/`session capture`, `scraps banner`, `scraps snapshot` (the scrap lookup it starts from is dual-auth, but the `html-snapshot` route it downloads from isn't), or the standalone SSE **command** `scraps watch` (do not conflate the two: `--watch` is a flag on `run`/`trigger` and works under a key; `scraps watch` is a separate command and is JWT-only) — those stay JWT-only and fail with a `kind:"auth"` envelope (exit `3`) pointing at `trawl login` under a key. This list mirrors the server's route wiring as of this writing, not a frozen guarantee — for anything not named here, trust the real `--json` envelope over this paragraph. Never send both a key and a JWT on the same request — the CLI only ever attaches one. `list --unhealthy` (and the plain health badge on `list`/`get`) rides the same `GET /api/scraps`/`GET /api/scraps/:id` routes as the rest of the group — no separate auth path — so it works under a key exactly like plain `list`/`get`, and a scrap-scoped key still only ever sees its own allow-listed scraps through the filter.
|
|
40
40
|
|
|
41
41
|
Custom API URL: `trawl login --url https://self-hosted.example.com`
|
|
42
42
|
|
|
@@ -49,14 +49,14 @@ 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
|
|
56
56
|
trawl run <id> [--watch] [--json] Run a scrap (blocks until finished)
|
|
57
57
|
trawl trigger <id> [--watch] [--wait] [--json] Launch a scrap as a background worker (returns immediately)
|
|
58
58
|
trawl data <id> [--json] [--fresh] [--errors] Get scrap data (last persisted run — read-only, no quota; --fresh to launch one)
|
|
59
|
-
trawl history <id> [--json] [-n <limit>]
|
|
59
|
+
trawl runs|history <id> [--json] [-n <limit>] List past runs for a scrap (newest first)
|
|
60
60
|
trawl run-info <hid> [--json] Show details of a single run
|
|
61
61
|
trawl whoami [--json] Show the authenticated user's identity
|
|
62
62
|
trawl token [--json] Print the stored credential — API key or session JWT (for MCP Bearer auth)
|
|
@@ -68,16 +68,16 @@ 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
|
|
|
75
75
|
> **A failure the wizard reports itself** — the stream's terminal `error` event — arrives after the HTTP `200` was already sent, so there is no status to report: `create` exits `1` as `kind:"refused"` with **no `status` field** (`{"error":{"message":"…","kind":"refused","retryable":false}}` under `--json`, the server's message verbatim; `✗ <message>` on stderr otherwise, stripped of control characters and capped at 200 characters). Branch on `kind`, not on a status.
|
|
76
76
|
|
|
77
77
|
- `list` has a short alias, `ls` (matches `trawl --help`'s `list|ls`).
|
|
78
|
-
- `
|
|
78
|
+
- `runs` lists past runs (newest first); `history` is the older name of the same command and keeps working. `run-info <hid>` shows details of a single run.
|
|
79
79
|
- `data` returns the last persisted run payload (no execute quota); `--fresh` runs the scrap live instead (consumes execute quota); `--errors` shows the last run's error detail (`--json` on a never-run scrap returns `{"status":"no_runs"}`, exit 0, matching `scraps doctor --json`). `[]` on stdout means a genuine zero-item successful run — a scrap that has never run, whose last run failed, or whose payload aged out of retention returns a `--json` error envelope (exit 4/1/4 respectively) instead. Two more honest states: a run still **in flight** (`status: null` server-side) returns a `kind:"in_progress"` error envelope (exit 1, "retry shortly" — never suggests `--fresh`, which would just 429 against the run already holding the lock); a run whose item count **regressed** vs baseline (`statusDetail: "regression"`) still returns the real, non-empty items on stdout (exit 0) plus a stderr warning pointing at `scraps doctor <id>` — the data itself is genuine even though the run is flagged.
|
|
80
|
-
- `get` (and anything reading through it, like `data`'s default path) embeds only the newest 100
|
|
80
|
+
- `get` (and anything reading through it, like `data`'s default path) embeds only the newest 100 run rows (`runs`; older APIs: `history`) on the returned scrap object — `run-info` and `scraps doctor` fetch a single run directly and are unaffected by that cap. `list`/`get` show a distinct amber `▼` "regression" badge, never the red `✗` a genuine failure gets (matches `scraps doctor`'s own badge).
|
|
81
81
|
- `list`/`get` also show a **health** badge next to the status badge. By default it reads the scrap's own `lastCronOutcome` field (always present, no extra cost): `⚠ cron paused` when the last scheduled tick was skipped for being unhealthy, `—` otherwise — a breadcrumb of the last tick, not a live read (never set on a no-cron scrap, can lag by one tick). `list --unhealthy` asks the API to filter to scraps whose *current* consecutive-failure streak is 3+ (the server's own threshold) and annotates each with the exact `consecutiveFailedRuns`/`unhealthySince` — shown instead of the badge whenever present, and never re-derived client-side from history. `--json` carries whichever fields the request produced: `lastCronOutcome` always, `consecutiveFailedRuns`/`unhealthySince` only when `--unhealthy` was passed. **Old-server safety:** an older server version that predates this filter silently ignores the unknown `--unhealthy` query param and returns everything, unfiltered — the CLI detects that (no returned item carries `consecutiveFailedRuns`) and prints a stderr warning instead of presenting the full list as "your unhealthy scraps".
|
|
82
82
|
- **Long-running calls (`run`, `data --fresh`, `trigger --wait`):** these hit server-side paths that can legitimately take minutes (proxy tier escalation + AI-fix retries, up to the server's 600s per-run budget) — the CLI arms a 660s timeout (600s + 60s) for exactly these three call sites instead of the generic 30s default, over the same raw `node:http(s)` transport `create` uses: Node's global `fetch` kills any call at ~300s whatever ceiling is asked for.
|
|
83
83
|
- **`create` is longer still:** the wizard adds a proxy-tier probe ladder and an iteration loop on top of generation + creation + a first run, so it arms **3600s** for that one call site (600s probe ladder + 900s iteration loop + 600s for a dry-run still in flight + 600s first run + margin) — a safety ceiling only, since `create` reads the wizard's live NDJSON progress stream. Raising the 660s above to cover it would make the three calls above wait an hour on an unreachable API, so the two ceilings are deliberately separate. `TRAWL_TIMEOUT` (see below) still overrides ALL requests, including both — set it if you need a tighter or looser ceiling, but note a global override sized for a quick call also clamps `create`.
|
|
@@ -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.
|
package/dist/commands/create.js
CHANGED
|
@@ -8,6 +8,7 @@ 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
|
+
import { runIdOf } from '../lib/runs.js';
|
|
11
12
|
function unverifiedSuccess(data) {
|
|
12
13
|
return data.success && data.verified === false;
|
|
13
14
|
}
|
|
@@ -41,9 +42,9 @@ function scheduleLabel(scrap) {
|
|
|
41
42
|
}
|
|
42
43
|
return 'scheduled weekly by default (Monday 07:00 UTC)';
|
|
43
44
|
}
|
|
44
|
-
async function printDataSample(
|
|
45
|
+
async function printDataSample(runId) {
|
|
45
46
|
try {
|
|
46
|
-
const detail = await api.get(`/api/historys/${
|
|
47
|
+
const detail = await api.get(`/api/historys/${runId}`);
|
|
47
48
|
if (typeof detail?.data !== 'string' || !detail.data)
|
|
48
49
|
return;
|
|
49
50
|
const items = parseServerJson(detail.data)?.data;
|
|
@@ -89,6 +90,7 @@ export const create = new Command('create')
|
|
|
89
90
|
.requiredOption('--prompt <goal>', 'What to extract/scrape, in plain language (required)')
|
|
90
91
|
.option('--url <url>', 'Target public URL — alias of the positional argument')
|
|
91
92
|
.option('--no-autofix', 'Disable AI auto-fix on first-run failure (default: on)')
|
|
93
|
+
.option('--no-digest', 'Disable the AI digest on the created scrap (default: on when the account has an email)')
|
|
92
94
|
.option('--json', 'Output the raw API payload')
|
|
93
95
|
.action(async (rawUrl, opts) => {
|
|
94
96
|
if (rawUrl === undefined && opts.url === undefined) {
|
|
@@ -103,6 +105,7 @@ export const create = new Command('create')
|
|
|
103
105
|
url,
|
|
104
106
|
goal,
|
|
105
107
|
...(opts.autofix === false && { autoFix: false }),
|
|
108
|
+
...(opts.digest === false && { digest: { enabled: false } }),
|
|
106
109
|
};
|
|
107
110
|
const call = (onEvent) => api
|
|
108
111
|
.postLongRunning('/api/ai/wizard', body, { timeoutMs: WIZARD_TIMEOUT_MS, onEvent })
|
|
@@ -150,25 +153,26 @@ export const create = new Command('create')
|
|
|
150
153
|
}
|
|
151
154
|
else {
|
|
152
155
|
const scrapId = printable(data.scrap?._id);
|
|
153
|
-
const
|
|
156
|
+
const rawRunId = runIdOf(data);
|
|
157
|
+
const runId = printable(rawRunId);
|
|
154
158
|
const title = printable(data.scrap?.title ?? url);
|
|
155
159
|
const autoFixEnabled = opts.autofix !== false;
|
|
156
160
|
const schedule = scheduleLabel(data.scrap);
|
|
157
161
|
console.log(`${data.success ? chalk.green('✓') : chalk.red('✗')} ${chalk.bold(title)}`);
|
|
158
162
|
console.log(chalk.dim(` Scrap ID: `) + (scrapId || '—'));
|
|
159
|
-
if (
|
|
160
|
-
console.log(chalk.dim(`
|
|
163
|
+
if (runId)
|
|
164
|
+
console.log(chalk.dim(` Run ID: `) + runId);
|
|
161
165
|
console.log(chalk.dim(` First run: `) + firstRunLabel(data, autoFixEnabled));
|
|
162
166
|
if (schedule)
|
|
163
167
|
console.log(chalk.dim(` Schedule: `) + schedule);
|
|
164
|
-
if (data.success &&
|
|
165
|
-
await printDataSample(
|
|
168
|
+
if (data.success && rawRunId)
|
|
169
|
+
await printDataSample(rawRunId);
|
|
166
170
|
if (scrapId) {
|
|
167
171
|
console.log(chalk.dim(` Next step: `) + `trawl data ${scrapId}` + chalk.dim(` (details: trawl get ${scrapId})`));
|
|
168
172
|
}
|
|
169
173
|
if (!data.success && data.scrap && autoFixEnabled) {
|
|
170
|
-
const pollTarget =
|
|
171
|
-
? `\`trawl data ${scrapId}\` or \`trawl run-info ${
|
|
174
|
+
const pollTarget = runId
|
|
175
|
+
? `\`trawl data ${scrapId}\` or \`trawl run-info ${runId}\``
|
|
172
176
|
: `\`trawl data ${scrapId}\``;
|
|
173
177
|
console.log(chalk.yellow(` Note: `) +
|
|
174
178
|
`Auto-fix is retrying in the background — do NOT re-run create; poll ${pollTarget}.`);
|
package/dist/commands/doctor.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { api } from '../lib/api.js';
|
|
2
|
+
import { runsOf } from '../lib/runs.js';
|
|
2
3
|
import chalk from 'chalk';
|
|
3
4
|
import { formatDate } from '../lib/format.js';
|
|
4
5
|
const WALL_VENDOR_PATTERNS = [
|
|
@@ -147,7 +148,7 @@ export function formatAutofix(fix) {
|
|
|
147
148
|
}
|
|
148
149
|
export async function fetchRunAndFix(scrapId) {
|
|
149
150
|
const scrap = await api.get(`/api/scraps/${scrapId}`);
|
|
150
|
-
const hid = scrap
|
|
151
|
+
const hid = runsOf(scrap)?.[0]?._id;
|
|
151
152
|
if (!hid)
|
|
152
153
|
return null;
|
|
153
154
|
const run = await api.get(`/api/historys/${hid}`);
|
|
@@ -22,7 +22,7 @@ export declare function attachListCommand(parent: Command, attachOpts?: AttachOp
|
|
|
22
22
|
export declare function attachGetCommand(parent: Command, attachOpts?: AttachOptions): Command;
|
|
23
23
|
export declare function attachRunCommand(parent: Command, attachOpts?: AttachOptions): Command;
|
|
24
24
|
export declare function attachDataCommand(parent: Command, attachOpts?: AttachOptions): Command;
|
|
25
|
-
export declare function
|
|
25
|
+
export declare function attachRunsCommand(parent: Command, attachOpts?: AttachOptions): Command;
|
|
26
26
|
export declare function attachRunInfoCommand(parent: Command, attachOpts?: AttachOptions): Command;
|
|
27
27
|
export declare function attachTriggerCommand(parent: Command, attachOpts?: AttachOptions): Command;
|
|
28
28
|
export {};
|
package/dist/commands/scraps.js
CHANGED
|
@@ -14,6 +14,7 @@ import { maybeShowReferralTip } from '../lib/tips.js';
|
|
|
14
14
|
import { maybeSuggestSkillsForAuthWall } from '../lib/skillsNudge.js';
|
|
15
15
|
import { captureSession, checkInteractiveEnvironment, LOCALSTORAGE_READ_TIMEOUT_MS, } from '../lib/session-capture.js';
|
|
16
16
|
import { assertSecureTransport } from '../lib/secure-transport.js';
|
|
17
|
+
import { runsOf } from '../lib/runs.js';
|
|
17
18
|
import { getApiUrl } from '../lib/config.js';
|
|
18
19
|
import { resolveDocsUrls, resolveFailureKindDocsUrl } from '../lib/docs.js';
|
|
19
20
|
function runDocsField(run) {
|
|
@@ -69,7 +70,7 @@ function summarizeEmptyContext(ctx) {
|
|
|
69
70
|
return parts.length ? parts.join(' | ') : null;
|
|
70
71
|
}
|
|
71
72
|
function lastStatus(scrap) {
|
|
72
|
-
const last = scrap
|
|
73
|
+
const last = runsOf(scrap)?.[0];
|
|
73
74
|
if (!last)
|
|
74
75
|
return 'never';
|
|
75
76
|
if (last.status === null)
|
|
@@ -81,7 +82,7 @@ function lastStatus(scrap) {
|
|
|
81
82
|
return last.status === true ? 'success' : 'failure';
|
|
82
83
|
}
|
|
83
84
|
function lastRun(scrap) {
|
|
84
|
-
return formatDate(scrap
|
|
85
|
+
return formatDate(runsOf(scrap)?.[0]?.createdAt);
|
|
85
86
|
}
|
|
86
87
|
function statusIcon(status) {
|
|
87
88
|
if (status === 'success')
|
|
@@ -143,7 +144,7 @@ async function watchActivities(id, asJson) {
|
|
|
143
144
|
async function captureBeforeRunState(id) {
|
|
144
145
|
try {
|
|
145
146
|
const scrap = await api.get(`/api/scraps/${id}`);
|
|
146
|
-
const top = scrap
|
|
147
|
+
const top = runsOf(scrap)?.[0];
|
|
147
148
|
return { id: top?._id, alreadyInFlight: top?.status === null, captured: true };
|
|
148
149
|
}
|
|
149
150
|
catch {
|
|
@@ -195,7 +196,7 @@ export async function pollRunProgress(id, before, opts = {}) {
|
|
|
195
196
|
}
|
|
196
197
|
continue;
|
|
197
198
|
}
|
|
198
|
-
const last = scrap
|
|
199
|
+
const last = runsOf(scrap)?.[0];
|
|
199
200
|
if (!last?._id)
|
|
200
201
|
continue;
|
|
201
202
|
if (!baselineEstablished) {
|
|
@@ -366,6 +367,7 @@ export function attachGetCommand(parent, attachOpts = {}) {
|
|
|
366
367
|
}
|
|
367
368
|
attachGetCommand(scraps, { hidden: true });
|
|
368
369
|
const VALID_TIERS = ['tier0', 'tier1', 'tier2', 'tier3', 'tier4'];
|
|
370
|
+
const VALID_DIGEST_MODES = ['latest', 'changes', 'changes_only'];
|
|
369
371
|
function renderTierOverrideHuman(data) {
|
|
370
372
|
const ov = data._tierOverride;
|
|
371
373
|
if (!ov)
|
|
@@ -459,6 +461,10 @@ scraps
|
|
|
459
461
|
.option('--no-alert', 'Disable failure alert email (set to null)')
|
|
460
462
|
.option('--autofix', 'Enable AI Fix (auto-recovery on selector breakage)')
|
|
461
463
|
.option('--no-autofix', 'Disable AI Fix')
|
|
464
|
+
.option('--digest', 'Enable the AI digest (partial update — other digest settings are kept)')
|
|
465
|
+
.option('--no-digest', 'Disable the AI digest (partial update — other digest settings are kept)')
|
|
466
|
+
.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)`)
|
|
467
|
+
.option('--digest-prompt <text>', 'Digest prompt (empty string to clear; partial update — other digest settings are kept)')
|
|
462
468
|
.option('-p, --params <json>', 'Runtime params as JSON array of objects (e.g. \'[{"TRAWL.paramName":"value"}]\')')
|
|
463
469
|
.option('--params-file <path>', 'Runtime params from a JSON file')
|
|
464
470
|
.option('--tier <tier>', `Force proxy tier (${VALID_TIERS.join('|')})`)
|
|
@@ -474,6 +480,10 @@ scraps
|
|
|
474
480
|
usageError(`Invalid --force-tier "${opts.forceTier}" (allowed: ${VALID_TIERS.join(', ')})`, { json: opts.json });
|
|
475
481
|
return;
|
|
476
482
|
}
|
|
483
|
+
if (opts.digestMode !== undefined && !VALID_DIGEST_MODES.includes(opts.digestMode)) {
|
|
484
|
+
usageError(`Invalid --digest-mode "${opts.digestMode}" (allowed: ${VALID_DIGEST_MODES.join(', ')})`, { json: opts.json });
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
477
487
|
const body = {};
|
|
478
488
|
if (opts.title !== undefined)
|
|
479
489
|
body.title = opts.title;
|
|
@@ -499,6 +509,17 @@ scraps
|
|
|
499
509
|
body.autoFix = true;
|
|
500
510
|
else if (opts.autofix === false)
|
|
501
511
|
body.autoFix = false;
|
|
512
|
+
const digestPatch = {};
|
|
513
|
+
if (opts.digest === true)
|
|
514
|
+
digestPatch.enabled = true;
|
|
515
|
+
else if (opts.digest === false)
|
|
516
|
+
digestPatch.enabled = false;
|
|
517
|
+
if (opts.digestMode !== undefined)
|
|
518
|
+
digestPatch.mode = opts.digestMode;
|
|
519
|
+
if (opts.digestPrompt !== undefined)
|
|
520
|
+
digestPatch.prompt = opts.digestPrompt === '' ? null : opts.digestPrompt;
|
|
521
|
+
if (Object.keys(digestPatch).length > 0)
|
|
522
|
+
body.digest = digestPatch;
|
|
502
523
|
if (opts.params !== undefined || opts.paramsFile !== undefined) {
|
|
503
524
|
let raw;
|
|
504
525
|
if (opts.paramsFile) {
|
|
@@ -556,6 +577,15 @@ scraps
|
|
|
556
577
|
for (const key of Object.keys(body)) {
|
|
557
578
|
if (key === 'proxyTier' || key === 'proxyMaxTier')
|
|
558
579
|
continue;
|
|
580
|
+
if (key === 'digest') {
|
|
581
|
+
const digestShown = shown['digest'];
|
|
582
|
+
if (digestShown === undefined) {
|
|
583
|
+
console.error(chalk.yellow(' ⚠ Server did not confirm the digest change (older server) — it may not support digest yet.'));
|
|
584
|
+
continue;
|
|
585
|
+
}
|
|
586
|
+
console.log(chalk.dim(` digest: `) + printable(JSON.stringify(digestShown), HUMAN_ERROR_MAX));
|
|
587
|
+
continue;
|
|
588
|
+
}
|
|
559
589
|
const src = key in shown ? shown[key] : body[key];
|
|
560
590
|
console.log(chalk.dim(` ${key}: `) + (printable(src, HUMAN_ERROR_MAX) || '—'));
|
|
561
591
|
}
|
|
@@ -658,7 +688,7 @@ export function attachDataCommand(parent, attachOpts = {}) {
|
|
|
658
688
|
}
|
|
659
689
|
try {
|
|
660
690
|
const fresh = await api.get(`/api/scraps/${id}`);
|
|
661
|
-
if (fresh
|
|
691
|
+
if (runsOf(fresh)?.[0]?.statusDetail === 'regression') {
|
|
662
692
|
console.error(chalk.yellow(`⚠ Item count regressed vs baseline for the last run of ${id} — see: trawl scraps doctor ${id}`));
|
|
663
693
|
}
|
|
664
694
|
}
|
|
@@ -668,7 +698,7 @@ export function attachDataCommand(parent, attachOpts = {}) {
|
|
|
668
698
|
return;
|
|
669
699
|
}
|
|
670
700
|
const scrap = await api.get(`/api/scraps/${id}`);
|
|
671
|
-
const last = scrap
|
|
701
|
+
const last = runsOf(scrap)?.[0];
|
|
672
702
|
if (!last?._id) {
|
|
673
703
|
reportDataState(`Scrap ${id} has never run. Run it first (trawl run ${id}) or pass --fresh to launch one now.`, 4, 'not_found', opts.json);
|
|
674
704
|
return;
|
|
@@ -708,9 +738,10 @@ export function attachDataCommand(parent, attachOpts = {}) {
|
|
|
708
738
|
});
|
|
709
739
|
}
|
|
710
740
|
attachDataCommand(scraps, { hidden: true });
|
|
711
|
-
export function
|
|
741
|
+
export function attachRunsCommand(parent, attachOpts = {}) {
|
|
712
742
|
return parent
|
|
713
|
-
.command('
|
|
743
|
+
.command('runs <id>', attachOpts)
|
|
744
|
+
.alias('history')
|
|
714
745
|
.description('List past runs for a scrap (newest first)')
|
|
715
746
|
.option('--json', 'Output as JSON')
|
|
716
747
|
.option('-n, --limit <n>', 'Max runs to show', '20')
|
|
@@ -722,7 +753,7 @@ export function attachHistoryCommand(parent, attachOpts = {}) {
|
|
|
722
753
|
return;
|
|
723
754
|
}
|
|
724
755
|
const scrap = await api.get(`/api/scraps/${id}`);
|
|
725
|
-
const runs = (scrap
|
|
756
|
+
const runs = (runsOf(scrap) ?? []).slice(0, limit).map((h) => ({
|
|
726
757
|
hid: h._id,
|
|
727
758
|
status: h.statusDetail ?? null,
|
|
728
759
|
time: h.time ?? null,
|
|
@@ -738,7 +769,7 @@ export function attachHistoryCommand(parent, attachOpts = {}) {
|
|
|
738
769
|
table(runs, ['hid', 'status', 'time', 'tier', 'failureKind', 'blockType', 'createdAt']);
|
|
739
770
|
});
|
|
740
771
|
}
|
|
741
|
-
|
|
772
|
+
attachRunsCommand(scraps, { hidden: true });
|
|
742
773
|
export function attachRunInfoCommand(parent, attachOpts = {}) {
|
|
743
774
|
return parent
|
|
744
775
|
.command('run-info <hid>', attachOpts)
|
|
@@ -1254,7 +1285,7 @@ scraps
|
|
|
1254
1285
|
.action(async (id, opts) => {
|
|
1255
1286
|
validateObjectId(id);
|
|
1256
1287
|
const scrap = await api.get(`/api/scraps/${id}`);
|
|
1257
|
-
const hid = scrap
|
|
1288
|
+
const hid = runsOf(scrap)?.[0]?._id;
|
|
1258
1289
|
if (!hid) {
|
|
1259
1290
|
if (opts.json) {
|
|
1260
1291
|
json({ status: 'no_runs' });
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { readFileSync, realpathSync } from 'node:fs';
|
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
6
|
import { dirname, join } from 'node:path';
|
|
7
7
|
import { login, logout } from './commands/login.js';
|
|
8
|
-
import { scraps, attachListCommand, attachGetCommand, attachRunCommand, attachDataCommand,
|
|
8
|
+
import { scraps, attachListCommand, attachGetCommand, attachRunCommand, attachDataCommand, attachRunsCommand, attachRunInfoCommand, attachTriggerCommand, } from './commands/scraps.js';
|
|
9
9
|
import { skills } from './commands/skills.js';
|
|
10
10
|
import { telemetry } from './commands/telemetry.js';
|
|
11
11
|
import { token } from './commands/token.js';
|
|
@@ -61,7 +61,7 @@ export function createProgram() {
|
|
|
61
61
|
attachRunCommand(program);
|
|
62
62
|
attachTriggerCommand(program);
|
|
63
63
|
attachDataCommand(program);
|
|
64
|
-
|
|
64
|
+
attachRunsCommand(program);
|
|
65
65
|
attachRunInfoCommand(program);
|
|
66
66
|
program.addCommand(whoami);
|
|
67
67
|
program.addCommand(token);
|
package/dist/lib/runs.js
ADDED
package/docs/agent-quickstart.md
CHANGED
|
@@ -79,14 +79,14 @@ 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
|
|
86
86
|
trawl run <id> [--watch] [--json] Run a scrap (blocks until finished)
|
|
87
87
|
trawl trigger <id> [--watch] [--wait] [--json] Launch a scrap as a background worker
|
|
88
88
|
trawl data <id> [--json] [--fresh] [--errors] Get scrap data (last persisted run, or --fresh to launch one)
|
|
89
|
-
trawl history <id> [--json] [-n <limit>]
|
|
89
|
+
trawl runs|history <id> [--json] [-n <limit>] List past runs for a scrap
|
|
90
90
|
trawl run-info <hid> [--json] Show details of a single run
|
|
91
91
|
trawl whoami [--json] Show the authenticated user's identity
|
|
92
92
|
trawl token [--json] Print the stored credential — API key or session JWT (for MCP Bearer auth)
|