@trawlme/cli 3.13.0 → 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 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`/`history`/`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.
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
 
@@ -56,7 +56,7 @@ 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>] List past runs for a scrap (newest first)
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)
@@ -75,9 +75,9 @@ trawl spec [--json] Print a versioned, machine-readab
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
- - `history` lists past runs (newest first); `run-info <hid>` shows details of a single run from that history.
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 history rows 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).
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`.
@@ -9,6 +9,7 @@ export interface WizardResponse {
9
9
  cronTimezone?: string;
10
10
  [key: string]: unknown;
11
11
  };
12
+ runId?: string | null;
12
13
  historyId?: string | null;
13
14
  }
14
15
  export declare const create: Command;
@@ -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(historyId) {
45
+ async function printDataSample(runId) {
45
46
  try {
46
- const detail = await api.get(`/api/historys/${historyId}`);
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;
@@ -152,25 +153,26 @@ export const create = new Command('create')
152
153
  }
153
154
  else {
154
155
  const scrapId = printable(data.scrap?._id);
155
- const historyId = printable(data.historyId);
156
+ const rawRunId = runIdOf(data);
157
+ const runId = printable(rawRunId);
156
158
  const title = printable(data.scrap?.title ?? url);
157
159
  const autoFixEnabled = opts.autofix !== false;
158
160
  const schedule = scheduleLabel(data.scrap);
159
161
  console.log(`${data.success ? chalk.green('✓') : chalk.red('✗')} ${chalk.bold(title)}`);
160
162
  console.log(chalk.dim(` Scrap ID: `) + (scrapId || '—'));
161
- if (historyId)
162
- console.log(chalk.dim(` History ID: `) + historyId);
163
+ if (runId)
164
+ console.log(chalk.dim(` Run ID: `) + runId);
163
165
  console.log(chalk.dim(` First run: `) + firstRunLabel(data, autoFixEnabled));
164
166
  if (schedule)
165
167
  console.log(chalk.dim(` Schedule: `) + schedule);
166
- if (data.success && data.historyId)
167
- await printDataSample(data.historyId);
168
+ if (data.success && rawRunId)
169
+ await printDataSample(rawRunId);
168
170
  if (scrapId) {
169
171
  console.log(chalk.dim(` Next step: `) + `trawl data ${scrapId}` + chalk.dim(` (details: trawl get ${scrapId})`));
170
172
  }
171
173
  if (!data.success && data.scrap && autoFixEnabled) {
172
- const pollTarget = historyId
173
- ? `\`trawl data ${scrapId}\` or \`trawl run-info ${historyId}\``
174
+ const pollTarget = runId
175
+ ? `\`trawl data ${scrapId}\` or \`trawl run-info ${runId}\``
174
176
  : `\`trawl data ${scrapId}\``;
175
177
  console.log(chalk.yellow(` Note: `) +
176
178
  `Auto-fix is retrying in the background — do NOT re-run create; poll ${pollTarget}.`);
@@ -58,6 +58,11 @@ export interface FixActivity {
58
58
  interface ScrapHead {
59
59
  _id: string;
60
60
  title: string;
61
+ runs?: Array<{
62
+ _id?: string;
63
+ status?: boolean | null;
64
+ createdAt?: string;
65
+ }>;
61
66
  history?: Array<{
62
67
  _id?: string;
63
68
  status?: boolean | null;
@@ -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.history?.[0]?._id;
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 attachHistoryCommand(parent: Command, attachOpts?: AttachOptions): Command;
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 {};
@@ -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.history?.[0];
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.history?.[0]?.createdAt);
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.history?.[0];
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.history?.[0];
199
+ const last = runsOf(scrap)?.[0];
199
200
  if (!last?._id)
200
201
  continue;
201
202
  if (!baselineEstablished) {
@@ -687,7 +688,7 @@ export function attachDataCommand(parent, attachOpts = {}) {
687
688
  }
688
689
  try {
689
690
  const fresh = await api.get(`/api/scraps/${id}`);
690
- if (fresh.history?.[0]?.statusDetail === 'regression') {
691
+ if (runsOf(fresh)?.[0]?.statusDetail === 'regression') {
691
692
  console.error(chalk.yellow(`⚠ Item count regressed vs baseline for the last run of ${id} — see: trawl scraps doctor ${id}`));
692
693
  }
693
694
  }
@@ -697,7 +698,7 @@ export function attachDataCommand(parent, attachOpts = {}) {
697
698
  return;
698
699
  }
699
700
  const scrap = await api.get(`/api/scraps/${id}`);
700
- const last = scrap.history?.[0];
701
+ const last = runsOf(scrap)?.[0];
701
702
  if (!last?._id) {
702
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);
703
704
  return;
@@ -737,9 +738,10 @@ export function attachDataCommand(parent, attachOpts = {}) {
737
738
  });
738
739
  }
739
740
  attachDataCommand(scraps, { hidden: true });
740
- export function attachHistoryCommand(parent, attachOpts = {}) {
741
+ export function attachRunsCommand(parent, attachOpts = {}) {
741
742
  return parent
742
- .command('history <id>', attachOpts)
743
+ .command('runs <id>', attachOpts)
744
+ .alias('history')
743
745
  .description('List past runs for a scrap (newest first)')
744
746
  .option('--json', 'Output as JSON')
745
747
  .option('-n, --limit <n>', 'Max runs to show', '20')
@@ -751,7 +753,7 @@ export function attachHistoryCommand(parent, attachOpts = {}) {
751
753
  return;
752
754
  }
753
755
  const scrap = await api.get(`/api/scraps/${id}`);
754
- const runs = (scrap.history ?? []).slice(0, limit).map((h) => ({
756
+ const runs = (runsOf(scrap) ?? []).slice(0, limit).map((h) => ({
755
757
  hid: h._id,
756
758
  status: h.statusDetail ?? null,
757
759
  time: h.time ?? null,
@@ -767,7 +769,7 @@ export function attachHistoryCommand(parent, attachOpts = {}) {
767
769
  table(runs, ['hid', 'status', 'time', 'tier', 'failureKind', 'blockType', 'createdAt']);
768
770
  });
769
771
  }
770
- attachHistoryCommand(scraps, { hidden: true });
772
+ attachRunsCommand(scraps, { hidden: true });
771
773
  export function attachRunInfoCommand(parent, attachOpts = {}) {
772
774
  return parent
773
775
  .command('run-info <hid>', attachOpts)
@@ -1283,7 +1285,7 @@ scraps
1283
1285
  .action(async (id, opts) => {
1284
1286
  validateObjectId(id);
1285
1287
  const scrap = await api.get(`/api/scraps/${id}`);
1286
- const hid = scrap.history?.[0]?._id;
1288
+ const hid = runsOf(scrap)?.[0]?._id;
1287
1289
  if (!hid) {
1288
1290
  if (opts.json) {
1289
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, attachHistoryCommand, attachRunInfoCommand, attachTriggerCommand, } from './commands/scraps.js';
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
- attachHistoryCommand(program);
64
+ attachRunsCommand(program);
65
65
  attachRunInfoCommand(program);
66
66
  program.addCommand(whoami);
67
67
  program.addCommand(token);
@@ -0,0 +1,8 @@
1
+ export declare function runsOf<R>(scrap: {
2
+ runs?: R[] | null;
3
+ history?: R[] | null;
4
+ }): R[] | undefined;
5
+ export declare function runIdOf(data: {
6
+ runId?: string | null;
7
+ historyId?: string | null;
8
+ }): string | null | undefined;
@@ -0,0 +1,6 @@
1
+ export function runsOf(scrap) {
2
+ return scrap.runs ?? scrap.history ?? undefined;
3
+ }
4
+ export function runIdOf(data) {
5
+ return data.runId ?? data.historyId;
6
+ }
@@ -86,7 +86,7 @@ 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>] List past runs for a scrap
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)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trawlme/cli",
3
- "version": "3.13.0",
3
+ "version": "3.14.0",
4
4
  "description": "Trawl CLI — manage scraps from the terminal",
5
5
  "type": "module",
6
6
  "bin": {