@trawlme/cli 3.16.0 → 3.17.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
@@ -59,6 +59,9 @@ 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)
62
65
  trawl token [--json] Print the stored credential — API key or session JWT (for MCP Bearer auth)
63
66
  trawl ping [--json] Health/version handshake against the Trawl API
64
67
  trawl spec [--json] Print a versioned, machine-readable description of the command tree
@@ -132,16 +135,6 @@ trawl scraps account session capture <id> [--chrome <path>] [--json]
132
135
 
133
136
  `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
137
 
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
138
  ### Claude Code skills
146
139
 
147
140
  The CLI bundles 5 Claude Code skills that teach Claude how to use `trawl`. Once installed, Claude can manage scraps for you via prompts.
@@ -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,11 @@
1
+ import { Command } from 'commander';
2
+ export interface OrgItem {
3
+ _id?: string;
4
+ id?: string;
5
+ name?: string;
6
+ role?: string;
7
+ membership?: {
8
+ role?: string;
9
+ };
10
+ }
11
+ export declare const orgs: Command;
@@ -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
+ });
package/dist/index.js CHANGED
@@ -14,6 +14,7 @@ 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';
17
18
  import { spec } from './commands/spec.js';
18
19
  import { autoUpdateInstalledSkills } from './lib/skills.js';
19
20
  import { maybeSuggestSkillsInstall } from './lib/skillsNudge.js';
@@ -71,7 +72,8 @@ export function createProgram() {
71
72
  program.commandsGroup(MANAGEMENT_GROUP);
72
73
  program.addCommand(scraps);
73
74
  program.addCommand(skills);
74
- program.addCommand(admin);
75
+ program.addCommand(admin, { hidden: true });
76
+ program.addCommand(orgs);
75
77
  program.addCommand(login);
76
78
  program.addCommand(logout);
77
79
  program.addCommand(telemetry);
@@ -220,7 +222,7 @@ export async function runCli(argv = process.argv) {
220
222
  exit_code: exitCode,
221
223
  error: err.name,
222
224
  });
223
- const wantsJson = Boolean(currentCommand?.opts()?.json);
225
+ const wantsJson = Boolean(currentCommand?.optsWithGlobals()?.json);
224
226
  if (isDebug)
225
227
  console.error(err);
226
228
  process.exitCode = reportError(err, { json: wantsJson, quiet: isDebug });
@@ -245,7 +247,7 @@ export async function runCli(argv = process.argv) {
245
247
  if (process.exitCode === undefined || process.exitCode === 0) {
246
248
  try {
247
249
  maybeSuggestSkillsInstall({
248
- json: Boolean(currentCommand?.opts()?.json),
250
+ json: Boolean(currentCommand?.optsWithGlobals()?.json),
249
251
  });
250
252
  }
251
253
  catch {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trawlme/cli",
3
- "version": "3.16.0",
3
+ "version": "3.17.0",
4
4
  "description": "Trawl CLI — manage scraps from the terminal",
5
5
  "type": "module",
6
6
  "bin": {