@trawlme/cli 4.0.3 → 4.0.5

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,9 +72,9 @@ 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 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.
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.
76
76
 
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 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`.
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
 
79
79
  > **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.
80
80
 
@@ -83,9 +83,9 @@ trawl spec [--json] Print a versioned, machine-readab
83
83
  - `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.
84
84
  - `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).
85
85
  - `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".
86
- - **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.
87
- - **`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`.
88
- - **`--watch` is poll-based, not a live stream:** the activities SSE endpoint has no backlog and, for the default async `trigger` (no `--wait`), runs in a separate cron-consumer pod whose events never reach the API pod holding the SSE connection — a naive "await the run, then open SSE" shows nothing. `run --watch` and `trigger --watch` instead poll `GET /api/scraps/:id` (terminal status) and the activities REST list until the run finishes, printing each new activity line as it appears. The watched run's outcome drives the exit code too, in BOTH human and `--json` mode: a genuinely failed terminal run, a poll timeout, or a persistently unreachable API all exit non-zero — a clean successful run is the only exit `0`. A run that never reaches a terminal status within 660s prints an honest timeout notice pointing at `scraps doctor <id>` (human mode) — see the `--json` shape below. `scraps watch <id>` (the standalone command, no trigger) is unchanged — it still opens the live SSE stream directly.
86
+ - **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; `trigger --wait` can also wait up to 600s for a worker before that budget starts, then up to 180s for the AI digest) — the CLI arms a 1380s timeout (about 23 minutes) for exactly these three call sites: the API itself cuts the request at 1320s, and the CLI waits 60s more so the server always answers or cuts first. It replaces the generic 30s default there, over the same raw `node:http(s)` transport `create` uses: Node's global `fetch` kills any call at ~300s whatever ceiling is asked for.
87
+ - **`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 **4800s** for that one call site (the server's 4200s pre-create bound — 600s probe ladder + 900s iteration loop + 2 × 1200s, as each can end with one run still in flight that waits up to 600s for a worker then runs 600s, + 300s margin — plus a 600s first run) — a safety ceiling only, since `create` reads the wizard's live NDJSON progress stream. Raising the 1380s above to cover it would make the three calls above wait 80 minutes 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`.
88
+ - **`--watch` is poll-based, not a live stream:** the activities SSE endpoint has no backlog and, for the default async `trigger` (no `--wait`), runs in a separate cron-consumer pod whose events never reach the API pod holding the SSE connection — a naive "await the run, then open SSE" shows nothing. `run --watch` and `trigger --watch` instead poll `GET /api/scraps/:id` (terminal status) and the activities REST list until the run finishes, printing each new activity line as it appears. The watched run's outcome drives the exit code too, in BOTH human and `--json` mode: a genuinely failed terminal run, a poll timeout, or a persistently unreachable API all exit non-zero — a clean successful run is the only exit `0`. A run that never reaches a terminal status within 1380s prints an honest timeout notice pointing at `scraps doctor <id>` (human mode) — see the `--json` shape below. `scraps watch <id>` (the standalone command, no trigger) is unchanged — it still opens the live SSE stream directly.
89
89
  - `spec --json` prints the CLI's own command tree — `{specVersion, cliVersion, commands[], exitCodes, errorKinds, kindExitCodes, docsUrl?, llmsUrl?}` — DERIVED at runtime by walking the live commander tree (never a hand-maintained file, which would silently drift from reality). Each entry in `commands[]` carries its full path (e.g. `"scraps account session set"`), description, `hidden` (the legacy `scraps <verb>` aliases above), `leaf` (false for a pure namespace/group node like `scraps`/`skills`/`telemetry` — invoking one directly is a guaranteed-failing tool, not a real command), `aliases`, `arguments`, `options`, and an optional per-command `docs` deep link (e.g. every `scraps account *` command points at the account-sessions guide); `exitCodes`/`errorKinds`/`kindExitCodes` are read from the exact same source `classifyError` uses (see [Exit codes](#exit-codes)) — never a second copy. `kindExitCodes` is the inverse of `exitCodes`: `kind -> exitCode`, since exit code `1` alone is a shared bucket (`api`/`refused`/`unknown`/`in_progress`/`run_failed`/`upgrade_failed`) that `exitCodes`' flat label can't disambiguate. `docsUrl` is resolved server-first (`externalDocs.url` on the configured API base's own OpenAPI document, when declared), else derived from a KNOWN first-party `trawl.me` API host, else **omitted entirely** — never a guessed URL pointed at the wrong docs host for a self-hosted install. `llmsUrl` and every per-command `docs` link are narrower: they only ever come from that same known-host derivation, NEVER from a server-declared `docsUrl` — this CLI's own guide slugs have no reason to exist on a third party's own docs root, so a self-hosted server that declares `externalDocs.url` gets a correct top-level `docsUrl` but no `llmsUrl` and no per-command `docs` links. A `failureKind:"auth"` run's JSON payload (`doctor`/`data --errors`/`run-info`) carries the same `docs` field, by the same known-host-only rule. Without `--json`, `spec` prints one short human line (version + visible command count) pointing at `--json`.
90
90
  - `run --json`/`trigger --json` bypass the spinner and print the raw launch/trigger payload on stdout; combined with `--watch`, every intermediate progress line stays suppressed (stdout stays pure JSON) and, once the watch reaches its outcome, exactly ONE final NDJSON line is emitted: `{"runId","status"}` (the honest terminal status — `success`/`error`/`empty`/`regression`/…), `{"runId","status":"timeout"}` on a poll timeout, or `{"runId","status":"poll_error","error"}` if the API stays unreachable for several consecutive polls — `process.exitCode` is non-zero for all three except a genuine success. `scraps watch --json` emits one raw JSON object per activity line (NDJSON) instead of the formatted `[time] message` text — there's no single final payload to wait for on a live stream.
91
91
 
@@ -253,7 +253,7 @@ Under `--json`, a failing command emits a single error envelope on stdout — `{
253
253
  | `TRAWL_TELEMETRY` | Set to `0` to disable telemetry for the current session |
254
254
  | `DO_NOT_TRACK` | Set to `1` to disable telemetry (cross-vendor convention, https://consoledonottrack.com) — same effect as `TRAWL_TELEMETRY=0` |
255
255
  | `TRAWL_CONFIG_DIR` | Override where the config file (token, API URL, telemetry state) is stored — useful for hermetic CI runs or concurrent `trawl login`s that must not share one on-disk file |
256
- | `TRAWL_TIMEOUT` | Override the per-request fetch timeout in milliseconds (default `30000`; `660000` for `run`/`data --fresh`/`trigger --wait`, `3600000` for `create` — this env var always wins over those longer defaults too) |
256
+ | `TRAWL_TIMEOUT` | Override the per-request fetch timeout in milliseconds (default `30000`; `1380000` for `run`/`data --fresh`/`trigger --wait`, `4800000` for `create` — this env var always wins over those longer defaults too) |
257
257
  | `TRAWL_SKILLS_SYNC` | Set to `0` to disable the startup skills auto-sync entirely |
258
258
 
259
259
  Session override (no `trawl login` mutation, ideal for CI/QA against another env):
@@ -715,7 +715,9 @@ export function attachDataCommand(parent, attachOpts = {}) {
715
715
  reportDataState(`Last run failed — see: trawl data ${id} --errors`, 1, 'run_failed', opts.json);
716
716
  return;
717
717
  }
718
- const detail = await api.get(`/api/historys/${last._id}`);
718
+ const detail = await api.getLongRunning(`/api/historys/${last._id}`, {
719
+ timeoutMs: LONG_RUN_TIMEOUT_MS,
720
+ });
719
721
  let items;
720
722
  if (typeof detail?.data === 'string' && detail.data) {
721
723
  try {
package/dist/lib/api.d.ts CHANGED
@@ -17,8 +17,8 @@ export declare class AuthError extends Error {
17
17
  }
18
18
  export declare function notLoggedInError(): AuthError;
19
19
  export declare function apiKeyUnsupportedError(command: string): AuthError;
20
- export declare const LONG_RUN_TIMEOUT_MS = 660000;
21
- export declare const WIZARD_TIMEOUT_MS = 3600000;
20
+ export declare const LONG_RUN_TIMEOUT_MS = 1380000;
21
+ export declare const WIZARD_TIMEOUT_MS = 4800000;
22
22
  export interface RequestOptions {
23
23
  timeoutMs?: number;
24
24
  }
package/dist/lib/api.js CHANGED
@@ -73,8 +73,8 @@ function authHeaders(token) {
73
73
  return getAuthMode(token) === 'apiKey' ? { Authorization: `Bearer ${token}` } : { Cookie: `TOKEN=${token}` };
74
74
  }
75
75
  const DEFAULT_TIMEOUT_MS = 30_000;
76
- export const LONG_RUN_TIMEOUT_MS = 660_000;
77
- export const WIZARD_TIMEOUT_MS = 3_600_000;
76
+ export const LONG_RUN_TIMEOUT_MS = 1_380_000;
77
+ export const WIZARD_TIMEOUT_MS = 4_800_000;
78
78
  function getTimeoutMs(overrideMs) {
79
79
  const raw = process.env['TRAWL_TIMEOUT']?.trim();
80
80
  if (raw) {
@@ -110,8 +110,8 @@ callers read `verified`. The call legitimately runs many minutes
110
110
  server-side (AI generation + a proxy-tier probe ladder + an iteration loop +
111
111
  a real run), so the CLI reads the wizard's NDJSON progress stream: human mode
112
112
  prints one short line per stage on stderr, `--json` prints only the final
113
- payload (same shape as always). It arms a 3600s safety ceiling for this
114
- endpoint alone, above the 660s `run`/`data --fresh`/`trigger --wait` use and
113
+ payload (same shape as always). It arms a 4800s safety ceiling for this
114
+ endpoint alone, above the 1380s `run`/`data --fresh`/`trigger --wait` use and
115
115
  well above the generic 30s default. Both use a transport of their own: Node's
116
116
  global `fetch` cannot wait longer than ~300s no matter what ceiling is asked
117
117
  for.
@@ -131,7 +131,7 @@ for.
131
131
  > (`cron: "0 7 * * 1"`, unrelated to `--no-autofix`) — each recurring run
132
132
  > consumes execute quota. Disable or change it once you've reviewed the
133
133
  > scrap: `trawl scraps update <id> --no-cron` (or `--cron <expr>`). Finally,
134
- > if `TRAWL_TIMEOUT` is set globally for a tighter budget than 3600s, it
134
+ > if `TRAWL_TIMEOUT` is set globally for a tighter budget than 4800s, it
135
135
  > clamps `create`'s ceiling too (env always wins) — so a value picked for a
136
136
  > quick call, e.g. 600s, aborts `create` mid-wizard. Unset it or raise it
137
137
  > before calling `create`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trawlme/cli",
3
- "version": "4.0.3",
3
+ "version": "4.0.5",
4
4
  "description": "Trawl CLI — manage scraps from the terminal",
5
5
  "type": "module",
6
6
  "bin": {