@trawlme/cli 3.16.0 → 3.18.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 +4 -10
- package/dist/commands/admin.js +3 -3
- package/dist/commands/orgs.d.ts +11 -0
- package/dist/commands/orgs.js +98 -0
- package/dist/commands/referral.d.ts +2 -0
- package/dist/commands/referral.js +38 -0
- package/dist/index.js +7 -3
- package/dist/lib/referral.d.ts +6 -0
- package/dist/lib/referral.js +7 -0
- package/dist/lib/tips.js +2 -1
- package/docs/agent-quickstart.md +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -59,6 +59,10 @@ trawl data <id> [--json] [--fresh] [--errors] Get scrap data (last persisted ru
|
|
|
59
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
|
+
trawl orgs list [--json] List your organizations (id, name, role) — session login only; bare `trawl orgs` is the same
|
|
63
|
+
trawl orgs current [--json] Show the current organization
|
|
64
|
+
trawl orgs switch <id> [--json] Switch the current organization (403 = not a member)
|
|
65
|
+
trawl referral [--json] Print your personal referral link and the reward — session login only
|
|
62
66
|
trawl token [--json] Print the stored credential — API key or session JWT (for MCP Bearer auth)
|
|
63
67
|
trawl ping [--json] Health/version handshake against the Trawl API
|
|
64
68
|
trawl spec [--json] Print a versioned, machine-readable description of the command tree
|
|
@@ -132,16 +136,6 @@ trawl scraps account session capture <id> [--chrome <path>] [--json]
|
|
|
132
136
|
|
|
133
137
|
`account session capture <id>` is the one-command version of the same idea: it opens a real, visible Chrome window at the scrap's target URL, waits for **you** to log in there — 2FA included — then reads the resulting session over the Chrome DevTools Protocol (cookies **and** per-origin localStorage) and uploads it. You stay authenticated as yourself; Trawl never sees your credentials, and responsibility for lawful use of the captured session stays with you. The capture is scoped to the scrap's own target host by RFC 6265 domain-matching, the same rule a real browser uses to decide which cookies to send: a cookie explicitly scoped to a domain (e.g. `Domain=example.com`) is in scope for that host and its subdomains, while a host-only cookie (no `Domain` attribute) is in scope only for the exact host it was set on — never a sibling subdomain, even one sharing a parent domain, and never another tenant on the same multi-tenant hosting domain (e.g. a different `*.github.io` site). localStorage follows the same anchor: an origin is in scope only if it's the target host itself or a subdomain of it. The one deliberate gap: a host-only cookie set on a sibling host (e.g. `auth.example.com` while the scrap targets `app.example.com`) is excluded — a real browser would never send it to the target host either, so nothing replay-relevant is lost unless the scrap script itself later navigates to that sibling. Completion is explicit: press Enter in the terminal once you're signed in — the primary path, and the only one guaranteed cross-platform. Closing the Chrome window also completes the capture (cookies only, not localStorage) when Chrome itself stays running after its last window closes, which this CLI verified on macOS; on a platform where closing the last window quits Chrome entirely, the command reports that fact instead of a session, and pressing Enter is the reliable path there. This command needs a local interactive terminal with a real display; it does not work headless, in CI, or over a plain SSH session, and auto-detects a system Chrome/Chromium (override with `--chrome <path>` or `TRAWL_CHROME_PATH`). Never prints the captured session itself, in any mode — `--json` echoes only the server's response plus capture counts.
|
|
134
138
|
|
|
135
|
-
### Platform admin (read-only)
|
|
136
|
-
|
|
137
|
-
Three read-only views for a platform admin. They need an API key with the `trawl:admin:read` scope whose owner is a platform admin (or an admin session); otherwise the API answers 403. Output is always JSON.
|
|
138
|
-
|
|
139
|
-
```
|
|
140
|
-
trawl admin orgs [--window 7d|30d|90d] Per-organization health and churn signals
|
|
141
|
-
trawl admin series [--window 7d|30d|90d] Platform-wide runs per day
|
|
142
|
-
trawl admin costs [--period day|week|month] Aggregate costs over a period
|
|
143
|
-
```
|
|
144
|
-
|
|
145
139
|
### Claude Code skills
|
|
146
140
|
|
|
147
141
|
The CLI bundles 5 Claude Code skills that teach Claude how to use `trawl`. Once installed, Claude can manage scraps for you via prompts.
|
package/dist/commands/admin.js
CHANGED
|
@@ -16,19 +16,19 @@ async function getAdmin(path, query) {
|
|
|
16
16
|
const windowOption = () => new Option('--window <window>', 'Time window (7d|30d|90d)').choices(['7d', '30d', '90d']);
|
|
17
17
|
export const admin = new Command('admin').description('Platform-admin read-only views (needs trawl:admin:read + an admin owner)');
|
|
18
18
|
admin
|
|
19
|
-
.command('orgs')
|
|
19
|
+
.command('orgs', { hidden: true })
|
|
20
20
|
.description('Per-organization health and churn signals (GET /api/admin/monitoring/organizations)')
|
|
21
21
|
.addOption(windowOption())
|
|
22
22
|
.option('--json', 'Output as JSON (default: on)', true)
|
|
23
23
|
.action((opts) => getAdmin('/api/admin/monitoring/organizations', { window: opts.window }));
|
|
24
24
|
admin
|
|
25
|
-
.command('series')
|
|
25
|
+
.command('series', { hidden: true })
|
|
26
26
|
.description('Platform-wide runs per day (GET /api/admin/monitoring/series)')
|
|
27
27
|
.addOption(windowOption())
|
|
28
28
|
.option('--json', 'Output as JSON (default: on)', true)
|
|
29
29
|
.action((opts) => getAdmin('/api/admin/monitoring/series', { window: opts.window }));
|
|
30
30
|
admin
|
|
31
|
-
.command('costs')
|
|
31
|
+
.command('costs', { hidden: true })
|
|
32
32
|
.description('Aggregate costs over a period (GET /api/admin/costs)')
|
|
33
33
|
.addOption(new Option('--period <period>', 'Reporting period (day|week|month)').choices(['day', 'week', 'month']))
|
|
34
34
|
.option('--json', 'Output as JSON (default: on)', true)
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { ApiError, api, apiKeyUnsupportedError } from '../lib/api.js';
|
|
4
|
+
import { getAuthMode } from '../lib/config.js';
|
|
5
|
+
import { json } from '../lib/format.js';
|
|
6
|
+
import { UsageError } from '../lib/errors.js';
|
|
7
|
+
function requireSession(command) {
|
|
8
|
+
if (getAuthMode() === 'apiKey')
|
|
9
|
+
throw apiKeyUnsupportedError(command);
|
|
10
|
+
}
|
|
11
|
+
function orgRef(ref) {
|
|
12
|
+
if (!ref)
|
|
13
|
+
return {};
|
|
14
|
+
if (typeof ref === 'string')
|
|
15
|
+
return { id: ref };
|
|
16
|
+
return { id: ref._id ?? ref.id, name: ref.name };
|
|
17
|
+
}
|
|
18
|
+
function currentOrg(ref) {
|
|
19
|
+
const { id, name } = orgRef(ref);
|
|
20
|
+
return { id: id ?? null, name: name ?? null };
|
|
21
|
+
}
|
|
22
|
+
function printCurrent(org, emptyMsg) {
|
|
23
|
+
if (!org.id) {
|
|
24
|
+
console.log(chalk.dim(emptyMsg));
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
console.log(chalk.bold(org.name ?? org.id));
|
|
28
|
+
console.log(chalk.dim(' ID: ') + org.id);
|
|
29
|
+
if (org.name)
|
|
30
|
+
console.log(chalk.dim(' Name: ') + org.name);
|
|
31
|
+
}
|
|
32
|
+
const wantsJson = (cmd) => Boolean(cmd.optsWithGlobals().json);
|
|
33
|
+
async function listOrgs(_opts, cmd) {
|
|
34
|
+
requireSession('trawl orgs');
|
|
35
|
+
const data = await api.get('/api/organizations');
|
|
36
|
+
const items = (Array.isArray(data) ? data : []).map((o) => ({
|
|
37
|
+
id: o._id ?? o.id ?? null,
|
|
38
|
+
name: o.name ?? null,
|
|
39
|
+
role: o.role ?? o.membership?.role ?? null,
|
|
40
|
+
}));
|
|
41
|
+
if (wantsJson(cmd)) {
|
|
42
|
+
json(items);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (!items.length) {
|
|
46
|
+
console.log(chalk.dim('No organizations.'));
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
for (const o of items)
|
|
50
|
+
console.log(`${o.id ?? '—'} ${o.name ?? '—'} ${chalk.dim(o.role ?? '—')}`);
|
|
51
|
+
}
|
|
52
|
+
export const orgs = new Command('orgs')
|
|
53
|
+
.description('List your organizations (GET /api/organizations)')
|
|
54
|
+
.option('--json', 'Output as JSON')
|
|
55
|
+
.action(listOrgs);
|
|
56
|
+
orgs
|
|
57
|
+
.command('list')
|
|
58
|
+
.description('Same as `trawl orgs` (GET /api/organizations)')
|
|
59
|
+
.option('--json', 'Output as JSON')
|
|
60
|
+
.action(listOrgs);
|
|
61
|
+
orgs
|
|
62
|
+
.command('current')
|
|
63
|
+
.description('Show the current organization (GET /api/auth/token)')
|
|
64
|
+
.option('--json', 'Output as JSON')
|
|
65
|
+
.action(async (_opts, cmd) => {
|
|
66
|
+
requireSession('trawl orgs current');
|
|
67
|
+
const data = await api.get('/api/auth/token');
|
|
68
|
+
const org = currentOrg(data?.user?.currentOrganization);
|
|
69
|
+
if (wantsJson(cmd))
|
|
70
|
+
json(org);
|
|
71
|
+
else
|
|
72
|
+
printCurrent(org, 'No current organization.');
|
|
73
|
+
});
|
|
74
|
+
orgs
|
|
75
|
+
.command('switch <id>')
|
|
76
|
+
.description('Switch the current organization (POST /api/organizations/:id/switch)')
|
|
77
|
+
.option('--json', 'Output as JSON')
|
|
78
|
+
.action(async (id, _opts, cmd) => {
|
|
79
|
+
requireSession('trawl orgs switch');
|
|
80
|
+
if (!/^[0-9a-fA-F]{24}$/.test(id)) {
|
|
81
|
+
throw new UsageError(`Invalid organization ID: "${id}" — expected a 24-char hex ObjectId`);
|
|
82
|
+
}
|
|
83
|
+
let data;
|
|
84
|
+
try {
|
|
85
|
+
data = await api.post(`/api/organizations/${id}/switch`);
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
if (err instanceof ApiError && err.status === 403) {
|
|
89
|
+
throw new ApiError(403, 'Not a member of this organization.');
|
|
90
|
+
}
|
|
91
|
+
throw err;
|
|
92
|
+
}
|
|
93
|
+
const org = currentOrg(data?.user?.currentOrganization ?? id);
|
|
94
|
+
if (wantsJson(cmd))
|
|
95
|
+
json(org);
|
|
96
|
+
else
|
|
97
|
+
printCurrent(org, 'Switched.');
|
|
98
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { api, apiKeyUnsupportedError } from '../lib/api.js';
|
|
4
|
+
import { getApiUrl, getAuthMode } from '../lib/config.js';
|
|
5
|
+
import { deriveDocsOrigin } from '../lib/docs.js';
|
|
6
|
+
import { json } from '../lib/format.js';
|
|
7
|
+
import { REFERRAL_REWARD_LINE } from '../lib/referral.js';
|
|
8
|
+
const UNAVAILABLE = 'Referral links are not available for this account.';
|
|
9
|
+
const CODE_SHAPE = /^[A-Za-z0-9_-]{1,64}$/;
|
|
10
|
+
export const referral = new Command('referral')
|
|
11
|
+
.description('Print your personal referral link and the reward')
|
|
12
|
+
.option('--json', 'Output as JSON')
|
|
13
|
+
.action(async (opts) => {
|
|
14
|
+
if (getAuthMode() === 'apiKey') {
|
|
15
|
+
throw apiKeyUnsupportedError('trawl referral');
|
|
16
|
+
}
|
|
17
|
+
const me = await api.get('/api/users/me');
|
|
18
|
+
const raw = me?.referralCode;
|
|
19
|
+
const code = typeof raw === 'string' && CODE_SHAPE.test(raw) ? raw : '';
|
|
20
|
+
if (!code) {
|
|
21
|
+
if (opts.json)
|
|
22
|
+
json({ referralCode: null, referralLink: null, message: UNAVAILABLE });
|
|
23
|
+
else
|
|
24
|
+
console.log(chalk.dim(UNAVAILABLE));
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const origin = deriveDocsOrigin(getApiUrl());
|
|
28
|
+
const link = origin ? `${origin.protocol}//${origin.host}/signup?ref=${code}` : null;
|
|
29
|
+
if (opts.json) {
|
|
30
|
+
json({ referralCode: code, referralLink: link, reward: REFERRAL_REWARD_LINE });
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (link)
|
|
34
|
+
console.log(chalk.bold(link));
|
|
35
|
+
else
|
|
36
|
+
console.log(`Referral code: ${chalk.bold(code)} ${chalk.dim('(web app URL unknown for this API base)')}`);
|
|
37
|
+
console.log(chalk.dim(REFERRAL_REWARD_LINE));
|
|
38
|
+
});
|
package/dist/index.js
CHANGED
|
@@ -14,6 +14,8 @@ import { create } from './commands/create.js';
|
|
|
14
14
|
import { whoami } from './commands/whoami.js';
|
|
15
15
|
import { ping } from './commands/ping.js';
|
|
16
16
|
import { admin } from './commands/admin.js';
|
|
17
|
+
import { orgs } from './commands/orgs.js';
|
|
18
|
+
import { referral } from './commands/referral.js';
|
|
17
19
|
import { spec } from './commands/spec.js';
|
|
18
20
|
import { autoUpdateInstalledSkills } from './lib/skills.js';
|
|
19
21
|
import { maybeSuggestSkillsInstall } from './lib/skillsNudge.js';
|
|
@@ -71,7 +73,9 @@ export function createProgram() {
|
|
|
71
73
|
program.commandsGroup(MANAGEMENT_GROUP);
|
|
72
74
|
program.addCommand(scraps);
|
|
73
75
|
program.addCommand(skills);
|
|
74
|
-
program.addCommand(admin);
|
|
76
|
+
program.addCommand(admin, { hidden: true });
|
|
77
|
+
program.addCommand(orgs);
|
|
78
|
+
program.addCommand(referral);
|
|
75
79
|
program.addCommand(login);
|
|
76
80
|
program.addCommand(logout);
|
|
77
81
|
program.addCommand(telemetry);
|
|
@@ -220,7 +224,7 @@ export async function runCli(argv = process.argv) {
|
|
|
220
224
|
exit_code: exitCode,
|
|
221
225
|
error: err.name,
|
|
222
226
|
});
|
|
223
|
-
const wantsJson = Boolean(currentCommand?.
|
|
227
|
+
const wantsJson = Boolean(currentCommand?.optsWithGlobals()?.json);
|
|
224
228
|
if (isDebug)
|
|
225
229
|
console.error(err);
|
|
226
230
|
process.exitCode = reportError(err, { json: wantsJson, quiet: isDebug });
|
|
@@ -245,7 +249,7 @@ export async function runCli(argv = process.argv) {
|
|
|
245
249
|
if (process.exitCode === undefined || process.exitCode === 0) {
|
|
246
250
|
try {
|
|
247
251
|
maybeSuggestSkillsInstall({
|
|
248
|
-
json: Boolean(currentCommand?.
|
|
252
|
+
json: Boolean(currentCommand?.optsWithGlobals()?.json),
|
|
249
253
|
});
|
|
250
254
|
}
|
|
251
255
|
catch {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export const REFERRAL_REWARD = {
|
|
2
|
+
referee: 1_500,
|
|
3
|
+
referrer: 3_000,
|
|
4
|
+
};
|
|
5
|
+
const fmt = (n) => n.toLocaleString('en-US');
|
|
6
|
+
export const REFERRAL_REWARD_SHORT = `they get ${fmt(REFERRAL_REWARD.referee)}, you get ${fmt(REFERRAL_REWARD.referrer)} compute`;
|
|
7
|
+
export const REFERRAL_REWARD_LINE = `Each friend who signs up with your link gets ${fmt(REFERRAL_REWARD.referee)} free compute; you get ${fmt(REFERRAL_REWARD.referrer)}.`;
|
package/dist/lib/tips.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
2
|
import config from './config.js';
|
|
3
3
|
import { api } from './api.js';
|
|
4
|
+
import { REFERRAL_REWARD_SHORT } from './referral.js';
|
|
4
5
|
const TIP_THROTTLE_MS = 7 * 24 * 60 * 60 * 1000;
|
|
5
6
|
const FLAG_CHECK_TIMEOUT_MS = 2_000;
|
|
6
|
-
const REFERRAL_TIP_TEXT =
|
|
7
|
+
const REFERRAL_TIP_TEXT = `Invite a builder — ${REFERRAL_REWARD_SHORT} → run \`trawl referral\``;
|
|
7
8
|
function isOptedOut() {
|
|
8
9
|
if (process.env['TRAWL_NO_TIPS'] !== undefined)
|
|
9
10
|
return true;
|
package/docs/agent-quickstart.md
CHANGED
|
@@ -89,6 +89,7 @@ trawl data <id> [--json] [--fresh] [--errors] Get scrap data (last persisted ru
|
|
|
89
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
|
+
trawl referral [--json] Print your personal referral link and the reward — session login only
|
|
92
93
|
trawl token [--json] Print the stored credential — API key or session JWT (for MCP Bearer auth)
|
|
93
94
|
trawl ping [--json] Health/version handshake against the Trawl API
|
|
94
95
|
trawl spec [--json] Print a versioned, machine-readable description of the command tree
|