unbrowse 12.3.1 → 12.5.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
@@ -13,6 +13,7 @@ unbrowse resume <runId> origin=SIN # answer on the same run
13
13
  | Command | Does |
14
14
  |---|---|
15
15
  | `login [--key K]`, `logout`, `whoami`, `usage` | Account |
16
+ | `accounts`, `accounts use <name>`, `--account NAME` | Several Unbrowse accounts on one machine, each with its own vault ([docs](https://github.com/unbrowse-ai/unbrowse/blob/main/docs/cli.md#several-accounts)) |
16
17
  | `discover <query>` | Your capabilities, then the public registry |
17
18
  | `run <task…>`, `inspect`, `resume`, `cancel` | Runs |
18
19
  | `scrape <url>` | One page as markdown on stdout |
@@ -21,8 +22,13 @@ unbrowse resume <runId> origin=SIN # answer on the same run
21
22
  | `logins`, `logins remove <origin>` | Saved logins, masked. The CLI never takes a password |
22
23
  | `registry [query]`, `site <host>`, `openapi <host>` | Public compiled sites, a site's tools, its OpenAPI 3.1 document — no account |
23
24
  | `call <host> <tool> [JSON]` | Run one site tool (`--set k=v`, `--deadline MS`, `--select a,b`, `--idempotency-key K`, `--end-user ID`) |
25
+ | `browse open <url>`, `browse act <id> click e1`, `browse snapshot`, `browse finish`, `browse close` | The recorded cloud browser |
26
+ | `map <url>`, `sites [site]`, `forget <capability>`, `connect [app]`, `credits` | Site map, what your workspace knows per site, learned tools, app connections, credits |
27
+ | `credentials list`, `credentials request <origin>`, `credentials status <id>` | Saved logins, and a link for the person to save one you need |
28
+ | `replay list`, `replay search`, `replay get`, `replay timeline`, `replay ask` | Recorded sessions |
29
+ | `tools [query]`, `tool <name> [--key value…]` | Any tool by name, such as your learned site tools |
24
30
 
25
- The CLI is the REST client. The remote MCP is a separate client; see the [install guide](https://github.com/unbrowse-ai/unbrowse/blob/main/docs/install.md).
31
+ The CLI matches the remote MCP: every MCP tool has a command ([table](https://github.com/unbrowse-ai/unbrowse/blob/main/docs/cli.md#same-as-the-mcp)). To give an agent host the MCP itself, see the [install guide](https://github.com/unbrowse-ai/unbrowse/blob/main/docs/install.md).
26
32
 
27
33
  Exit codes: 0 accepted/ok (check status and verified), 1 error, 2 input required, 3 sign-in or saved login needed, 4 not verified.
28
34
  Env: `UNBROWSE_API_KEY`, `UNBROWSE_BASE_URL`. Node 18.17+, no dependencies.
package/dist/cli.js CHANGED
@@ -26,7 +26,7 @@ var __esm = (fn, res, err) => () => {
26
26
  };
27
27
 
28
28
  // ../sdk/src/version.ts
29
- var SDK_VERSION = "12.3.1";
29
+ var SDK_VERSION = "12.5.0";
30
30
 
31
31
  // ../sdk/src/client.ts
32
32
  function apiBase(url) {
@@ -924,10 +924,12 @@ async function watch(opts) {
924
924
  }
925
925
  function servicePlan(opts) {
926
926
  const os = opts.os ?? platform();
927
+ const service = opts.account ? `${SERVICE}-${opts.account}` : SERVICE;
928
+ const label = opts.account ? `${LAUNCHD_LABEL}.${opts.account}` : LAUNCHD_LABEL;
927
929
  const home = opts.home ?? homedir3();
928
930
  const env = Object.entries(opts.env ?? {});
929
931
  if (os === "linux") {
930
- const path = join3(home, ".config", "systemd", "user", `${SERVICE}.service`);
932
+ const path = join3(home, ".config", "systemd", "user", `${service}.service`);
931
933
  const content = [
932
934
  "[Unit]",
933
935
  "Description=Unbrowse cookie sync: keeps your browser sign-ins for chosen sites in sync with Unbrowse",
@@ -948,21 +950,21 @@ function servicePlan(opts) {
948
950
  kind: "systemd",
949
951
  path,
950
952
  content,
951
- enable: [["systemctl", "--user", "daemon-reload"], ["systemctl", "--user", "enable", "--now", `${SERVICE}.service`]],
952
- disable: [["systemctl", "--user", "disable", "--now", `${SERVICE}.service`], ["systemctl", "--user", "daemon-reload"]],
953
- status: ["systemctl", "--user", "is-active", `${SERVICE}.service`],
954
- log: `journalctl --user -u ${SERVICE} -f`
953
+ enable: [["systemctl", "--user", "daemon-reload"], ["systemctl", "--user", "enable", "--now", `${service}.service`]],
954
+ disable: [["systemctl", "--user", "disable", "--now", `${service}.service`], ["systemctl", "--user", "daemon-reload"]],
955
+ status: ["systemctl", "--user", "is-active", `${service}.service`],
956
+ log: `journalctl --user -u ${service} -f`
955
957
  };
956
958
  }
957
959
  if (os === "darwin") {
958
- const path = join3(home, "Library", "LaunchAgents", `${LAUNCHD_LABEL}.plist`);
959
- const logPath = join3(home, "Library", "Logs", `${SERVICE}.log`);
960
+ const path = join3(home, "Library", "LaunchAgents", `${label}.plist`);
961
+ const logPath = join3(home, "Library", "Logs", `${service}.log`);
960
962
  const esc = (s) => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
961
963
  const content = `<?xml version="1.0" encoding="UTF-8"?>
962
964
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
963
965
  <plist version="1.0">
964
966
  <dict>
965
- <key>Label</key><string>${LAUNCHD_LABEL}</string>
967
+ <key>Label</key><string>${label}</string>
966
968
  <key>ProgramArguments</key>
967
969
  <array><string>${esc(opts.node)}</string><string>${esc(opts.cli)}</string><string>cookies</string><string>watch</string></array>
968
970
  ${env.length ? ` <key>EnvironmentVariables</key>
@@ -982,7 +984,7 @@ ${env.length ? ` <key>EnvironmentVariables</key>
982
984
  content,
983
985
  enable: [["launchctl", "bootout", domain, path], ["launchctl", "bootstrap", domain, path]],
984
986
  disable: [["launchctl", "bootout", domain, path]],
985
- status: ["launchctl", "print", `${domain}/${LAUNCHD_LABEL}`],
987
+ status: ["launchctl", "print", `${domain}/${label}`],
986
988
  log: `tail -f ${logPath}`
987
989
  };
988
990
  }
@@ -1218,7 +1220,7 @@ var HEADER = 100;
1218
1220
  // src/cookies.ts
1219
1221
  import { createDecipheriv, createHash as createHash3, pbkdf2Sync } from "node:crypto";
1220
1222
  import { execFileSync } from "node:child_process";
1221
- import { existsSync as existsSync4, readdirSync, readFileSync as readFileSync4 } from "node:fs";
1223
+ import { existsSync as existsSync4, readdirSync as readdirSync2, readFileSync as readFileSync4 } from "node:fs";
1222
1224
  import { homedir as homedir4, platform as platform2 } from "node:os";
1223
1225
  import { join as join4 } from "node:path";
1224
1226
  function chromium(name, [mac, linux], keychain) {
@@ -1306,7 +1308,7 @@ function firefoxProfiles(def, base) {
1306
1308
  }
1307
1309
  function safeReaddir(dir) {
1308
1310
  try {
1309
- return readdirSync(dir);
1311
+ return readdirSync2(dir);
1310
1312
  } catch {
1311
1313
  return [];
1312
1314
  }
@@ -1510,6 +1512,144 @@ var init_cookies = __esm(() => {
1510
1512
  TEXT = /^[\x20-\x7e]*$/;
1511
1513
  });
1512
1514
 
1515
+ // src/mcp-tools.ts
1516
+ function resolveTool(tools, typed) {
1517
+ const names = new Map(tools.map((t) => [t.name, t]));
1518
+ const safe = safeToolName(typed);
1519
+ const underscored = safe.replace(/-/g, "_");
1520
+ for (const n of [typed, safe, underscored, `unbrowse_${safe}`, `unbrowse_${underscored}`])
1521
+ if (names.has(n))
1522
+ return names.get(n);
1523
+ return;
1524
+ }
1525
+ function shortName(name) {
1526
+ return name.replace(/^unbrowse_/, "");
1527
+ }
1528
+ function signature(t, max = 60) {
1529
+ const schema = t.inputSchema ?? {};
1530
+ const required = new Set(schema.required ?? []);
1531
+ const keys = Object.keys(schema.properties ?? {});
1532
+ const props = [...keys.filter((k) => required.has(k)), ...keys.filter((k) => !required.has(k)).map((k) => `${k}?`)];
1533
+ let shown = "";
1534
+ for (const [i, p] of props.entries()) {
1535
+ const next = shown ? `${shown}, ${p}` : p;
1536
+ if (`${shortName(t.name)}(${next})`.length > max && i > 0)
1537
+ return `${shortName(t.name)}(${shown}, …)`;
1538
+ shown = next;
1539
+ }
1540
+ return `${shortName(t.name)}(${shown})`;
1541
+ }
1542
+ function summary(description = "", max = 110) {
1543
+ const first = description.split(/(?<=[.!?])\s|\n/)[0].trim();
1544
+ return first.length > max ? `${first.slice(0, max - 1)}…` : first;
1545
+ }
1546
+ function filterTools(tools, query) {
1547
+ const split = (s) => s.toLowerCase().split(/[^a-z0-9]+/).filter(Boolean);
1548
+ const words = split(query);
1549
+ const matches = (text) => {
1550
+ const tokens = split(text);
1551
+ return words.every((w) => tokens.some((k) => k.startsWith(w)));
1552
+ };
1553
+ const byName = tools.filter((t) => matches(shortName(t.name)));
1554
+ return byName.length ? byName : tools.filter((t) => matches(`${shortName(t.name)} ${t.description ?? ""}`));
1555
+ }
1556
+ function findCommand(cmd, sub) {
1557
+ const all = MCP_COMMANDS.filter((c) => c.cmd === cmd);
1558
+ const command = all.find((c) => !c.sub || c.sub === sub);
1559
+ return command ? { command } : { usage: all.map((c) => `unbrowse ${c.usage}`).join(`
1560
+ `) };
1561
+ }
1562
+ function commandInput(c, words, flags, sets, coerce) {
1563
+ const out = {};
1564
+ c.args.forEach((name, i) => {
1565
+ const v = c.rest && i === c.args.length - 1 ? words.slice(i).join(" ") : words[i];
1566
+ if (v)
1567
+ out[name.replace(/\?$/, "")] = v;
1568
+ });
1569
+ for (const [k, v] of Object.entries(flags))
1570
+ if (!CLI_FLAGS.has(k))
1571
+ out[k.replace(/-([a-z])/g, (_, ch) => ch.toUpperCase())] = typeof v === "string" ? coerce(v) : v;
1572
+ Object.assign(out, sets);
1573
+ for (const k of c.lists ?? [])
1574
+ if (typeof out[k] === "string")
1575
+ out[k] = out[k].split(",").map((s) => s.trim()).filter(Boolean);
1576
+ return out;
1577
+ }
1578
+ function toolInput(t, json, flags, sets, coerce) {
1579
+ const props = new Set(Object.keys((t.inputSchema ?? {}).properties ?? {}));
1580
+ const key = (k) => props.has(k) ? k : k.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
1581
+ const base = json ? JSON.parse(json) : {};
1582
+ if (!base || typeof base !== "object" || Array.isArray(base))
1583
+ throw new SyntaxError("the tool's input must be a JSON object");
1584
+ const out = { ...base };
1585
+ for (const [k, v] of Object.entries(flags))
1586
+ if (!CLI_FLAGS.has(k))
1587
+ out[key(k)] = typeof v === "string" ? coerce(v) : v;
1588
+ for (const [k, v] of Object.entries(sets))
1589
+ out[key(k)] = v;
1590
+ return out;
1591
+ }
1592
+ function resultValue(r) {
1593
+ if (r.structuredContent !== undefined)
1594
+ return r.structuredContent;
1595
+ const parts = (r.content ?? []).map((c) => c.type === "text" ? c.text ?? "" : `[${c.type}${c.mimeType ? ` ${c.mimeType}` : ""}]`);
1596
+ const text = parts.join(`
1597
+ `);
1598
+ try {
1599
+ return JSON.parse(text);
1600
+ } catch {
1601
+ return text;
1602
+ }
1603
+ }
1604
+ function resultCode(r, value) {
1605
+ if (r.isError)
1606
+ return 1;
1607
+ const status = value?.status;
1608
+ return status === "input_required" ? 2 : 0;
1609
+ }
1610
+ var MCP_COMMANDS, CLI_FOR_TOOL, CLI_FLAGS;
1611
+ var init_mcp_tools = __esm(() => {
1612
+ init_mcp_proxy();
1613
+ MCP_COMMANDS = [
1614
+ { cmd: "map", tool: "unbrowse_map", args: ["url"], usage: "map <url> [--search TEXT] [--limit N]", does: "A site's URLs from its sitemaps and the page's links" },
1615
+ { cmd: "browse", sub: "open", tool: "unbrowse_browse_open", args: ["url"], usage: "browse open <url> [--task TEXT] [--country XX]", does: "Open a recorded cloud browser on a page; prints its text and @refs" },
1616
+ { cmd: "browse", sub: "snapshot", tool: "unbrowse_browse_snapshot", args: ["sessionId"], usage: "browse snapshot <sessionId> [--text-offset N]", does: "The page's current text and @refs" },
1617
+ { cmd: "browse", sub: "act", tool: "unbrowse_browse_act", args: ["sessionId", "action", "ref?", "value?"], rest: true, usage: "browse act <sessionId> <click|fill|select|check|press|wait|autofill> [ref] [value…] [--name N] [--vault FIELD] [--key K]", does: "One action on a @ref" },
1618
+ { cmd: "browse", sub: "finish", tool: "unbrowse_browse_finish", args: ["sessionId"], usage: "browse finish <sessionId> [--title T] [--goal G]", does: "End the session and learn the site's routes from it" },
1619
+ { cmd: "browse", sub: "close", tool: "unbrowse_browse_close", args: ["sessionId"], usage: "browse close <sessionId> [--discard]", does: "End the session (it still indexes unless --discard)" },
1620
+ { cmd: "sites", tool: "unbrowse_sites", args: ["site?"], usage: "sites [site]", does: "What your workspace knows about each site: access, saved login, session" },
1621
+ { cmd: "forget", tool: "unbrowse_forget", args: ["capability"], usage: "forget <capability>", does: "Delete one of your learned capabilities" },
1622
+ { cmd: "credentials", sub: "list", tool: "unbrowse_credentials_list", args: ["origin?"], usage: "credentials list [origin] [--query TEXT] [--limit N]", does: "Saved logins as masked hints, filtered by site" },
1623
+ { cmd: "credentials", sub: "request", tool: "unbrowse_credentials_request", args: ["origin"], lists: ["fields"], usage: "credentials request <origin> [--fields username,password,totp] [--reason TEXT]", does: "A one-time link for the person to save a login you need" },
1624
+ { cmd: "credentials", sub: "status", tool: "unbrowse_credentials_status", args: ["requestId"], usage: "credentials status <requestId> [--wait-seconds N]", does: "Whether that request was answered" },
1625
+ { cmd: "connect", tool: "unbrowse_connect", args: ["app?"], usage: "connect [app] [--url URL --name N] [--search TEXT] [--disconnect]", does: "Connect an app's own MCP server (Linear, Notion, GitHub…) so its tools run as you" },
1626
+ { cmd: "credits", tool: "unbrowse_credits", args: [], usage: "credits [--pack p10|p50|p200]", does: "Credits left; --pack gets a checkout link" },
1627
+ { cmd: "replay", sub: "list", tool: "unbrowse_replay_list", args: [], usage: "replay list [--site S] [--outcome O] [--has-error] [--from D] [--to D] [--limit N]", does: "Recorded sessions, newest first" },
1628
+ { cmd: "replay", sub: "search", tool: "unbrowse_replay_search", args: ["query"], rest: true, usage: "replay search <query…> [same filters]", does: "Search what happened in recorded sessions" },
1629
+ { cmd: "replay", sub: "get", tool: "unbrowse_replay_get", args: ["sid"], usage: "replay get <sid>", does: "One session's details, signals and summary" },
1630
+ { cmd: "replay", sub: "timeline", tool: "unbrowse_replay_timeline", args: ["sid"], lists: ["kinds"], usage: "replay timeline <sid> [--from MS] [--to MS] [--kinds a,b]", does: "A session as text, one line per event" },
1631
+ { cmd: "replay", sub: "ask", tool: "unbrowse_replay_ask", args: ["question"], rest: true, usage: "replay ask <question…> [same filters]", does: "Ask a question across recorded sessions" }
1632
+ ];
1633
+ CLI_FOR_TOOL = {
1634
+ unbrowse_discover: "discover",
1635
+ search: "discover",
1636
+ unbrowse_run: "run",
1637
+ unbrowse_inspect: "inspect",
1638
+ unbrowse_resume: "resume",
1639
+ unbrowse_cancel: "cancel",
1640
+ unbrowse_learn: "learn",
1641
+ unbrowse_scrape: "scrape",
1642
+ fetch: "scrape",
1643
+ unbrowse_usage: "usage",
1644
+ unbrowse_index: "index",
1645
+ unbrowse_index_status: "index status",
1646
+ unbrowse_import_mcps: "mcps import",
1647
+ unbrowse_local_mcps: "mcps",
1648
+ ...Object.fromEntries(MCP_COMMANDS.map((c) => [c.tool, c.sub ? `${c.cmd} ${c.sub}` : c.cmd]))
1649
+ };
1650
+ CLI_FLAGS = new Set(["json", "base-url", "account", "no-open", "input", "from-here", "help", "version"]);
1651
+ });
1652
+
1513
1653
  // src/cli.ts
1514
1654
  import { spawn, spawnSync } from "node:child_process";
1515
1655
  import { randomUUID } from "node:crypto";
@@ -1519,13 +1659,70 @@ import { createInterface as createInterface2 } from "node:readline/promises";
1519
1659
 
1520
1660
  // src/auth.ts
1521
1661
  import { createHash, randomBytes } from "node:crypto";
1522
- import { chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
1662
+ import { chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
1523
1663
  import { createServer } from "node:http";
1524
1664
  import { homedir, hostname } from "node:os";
1525
1665
  import { dirname, join } from "node:path";
1666
+ function configRoot() {
1667
+ return process.env.UNBROWSE_CONFIG_DIR ?? join(process.env.XDG_CONFIG_HOME ?? join(homedir(), ".config"), "unbrowse");
1668
+ }
1669
+ var selected;
1670
+ var ACCOUNT_NAME = /^[A-Za-z0-9][A-Za-z0-9_-]{0,39}$/;
1671
+ var defaultFile = () => join(configRoot(), "account");
1672
+ function checkAccount(name) {
1673
+ if (name !== "default" && !ACCOUNT_NAME.test(name))
1674
+ throw new Error(`invalid account name "${name}": use letters, digits, - and _ (up to 40)`);
1675
+ return name;
1676
+ }
1677
+ function savedAccount() {
1678
+ try {
1679
+ const name = readFileSync(defaultFile(), "utf8").trim();
1680
+ return name && ACCOUNT_NAME.test(name) ? name : undefined;
1681
+ } catch {
1682
+ return;
1683
+ }
1684
+ }
1685
+ function selectAccount(name) {
1686
+ const pick = name ?? (process.env.UNBROWSE_ACCOUNT || undefined) ?? savedAccount();
1687
+ selected = !pick || checkAccount(pick) === "default" ? undefined : pick;
1688
+ return account();
1689
+ }
1690
+ function account() {
1691
+ return selected ?? "default";
1692
+ }
1693
+ function useAccount(name) {
1694
+ if (checkAccount(name) === "default")
1695
+ return void rmSync(defaultFile(), { force: true });
1696
+ mkdirSync(configRoot(), { recursive: true, mode: 448 });
1697
+ writeFileSync(defaultFile(), `${name}
1698
+ `, { mode: 384 });
1699
+ }
1700
+ function listAccounts() {
1701
+ const read = (path) => {
1702
+ try {
1703
+ return JSON.parse(readFileSync(path, "utf8"));
1704
+ } catch {
1705
+ return;
1706
+ }
1707
+ };
1708
+ const row = (name, s) => ({ name, ...s.baseUrl ? { baseUrl: s.baseUrl } : {}, signIn: s.apiKey ? "api key" : s.oauth ? "oauth" : "none" });
1709
+ const out = [];
1710
+ const main = read(join(configRoot(), "cli.json"));
1711
+ if (main)
1712
+ out.push(row("default", main));
1713
+ let names = [];
1714
+ try {
1715
+ names = readdirSync(join(configRoot(), "accounts")).filter((n) => ACCOUNT_NAME.test(n)).sort();
1716
+ } catch {}
1717
+ for (const n of names) {
1718
+ const s = read(join(configRoot(), "accounts", n, "cli.json"));
1719
+ if (s)
1720
+ out.push(row(n, s));
1721
+ }
1722
+ return out;
1723
+ }
1526
1724
  function configPath() {
1527
- const root = process.env.UNBROWSE_CONFIG_DIR ?? join(process.env.XDG_CONFIG_HOME ?? join(homedir(), ".config"), "unbrowse");
1528
- return join(root, "cli.json");
1725
+ return selected ? join(configRoot(), "accounts", selected, "cli.json") : join(configRoot(), "cli.json");
1529
1726
  }
1530
1727
  function load() {
1531
1728
  const path = configPath();
@@ -1597,7 +1794,7 @@ async function currentToken(baseUrl, fetchImpl = fetch) {
1597
1794
  return stored.apiKey;
1598
1795
  const o = stored.oauth;
1599
1796
  if (!o)
1600
- return v1Key(baseUrl) ?? sharedSignIn(baseUrl)?.token;
1797
+ return selected ? undefined : v1Key(baseUrl) ?? sharedSignIn(baseUrl)?.token;
1601
1798
  if (o.expiresAt && o.refreshToken && Date.now() > o.expiresAt - 60000) {
1602
1799
  try {
1603
1800
  const fresh = await tokenRequest(baseUrl, { grant_type: "refresh_token", refresh_token: o.refreshToken, client_id: o.clientId, resource: apiResource(baseUrl) }, fetchImpl);
@@ -1627,6 +1824,8 @@ function signInSource(baseUrl) {
1627
1824
  return;
1628
1825
  if (stored.apiKey || stored.oauth)
1629
1826
  return "stored";
1827
+ if (selected)
1828
+ return;
1630
1829
  if (v1Key(baseUrl))
1631
1830
  return "v1";
1632
1831
  return sharedSignIn(baseUrl) ? "shared" : undefined;
@@ -1641,6 +1840,8 @@ function describe(baseUrl) {
1641
1840
  return `API key ${mask(stored.apiKey)} in ${configPath()}`;
1642
1841
  if (stored.oauth)
1643
1842
  return `OAuth sign-in in ${configPath()}`;
1843
+ if (selected)
1844
+ return `not signed in (account "${selected}": \`unbrowse login --account ${selected}\`)`;
1644
1845
  const v1 = !stored.baseUrl ? v1Key(baseUrl) : undefined;
1645
1846
  if (v1)
1646
1847
  return `v1 API key ${mask(v1)} from ~/.unbrowse/config.json (still works; \`unbrowse login\` replaces it)`;
@@ -1786,7 +1987,7 @@ async function deviceLogin(baseUrl, opts) {
1786
1987
 
1787
1988
  // src/cli.ts
1788
1989
  init_src();
1789
- var VERSION = "12.3.1";
1990
+ var VERSION = "12.5.0";
1790
1991
  var DEFAULT_ORIGIN = "https://unbrowse.ai";
1791
1992
  var HELP = `unbrowse ${VERSION} — call websites as APIs through the Unbrowse API
1792
1993
 
@@ -1794,6 +1995,8 @@ var HELP = `unbrowse ${VERSION} — call websites as APIs through the Unbrowse A
1794
1995
  [--device] On a remote/headless machine, show a code to approve on your phone
1795
1996
  (first use of any command below signs you in the same way)
1796
1997
  logout Forget the stored sign-in
1998
+ accounts Sign-ins saved on this machine, one per Unbrowse account (each has its own vault)
1999
+ accounts use <name> Make one the default; any command takes --account NAME for just that run
1797
2000
  whoami Workspace and usage
1798
2001
  usage Verified calls this month and quota left
1799
2002
 
@@ -1815,6 +2018,8 @@ var HELP = `unbrowse ${VERSION} — call websites as APIs through the Unbrowse A
1815
2018
  cookies list Browsers and profiles found on this machine (--json for agents)
1816
2019
  cookies sync Send your browser cookies so runs act as your signed-in self
1817
2020
  [--browser NAME] [--profile NAME] [--domain d] [--all]
2021
+ A page that says "sign in to view" (claude.ai, Notion, Google Docs…): sign in to it
2022
+ in your browser once, then: unbrowse cookies sync --domain <site>
1818
2023
  cookies watch --domain a,b Keep those sites' cookies in sync (re-upload on change) [--interval MIN] [--all-sites]
1819
2024
  cookies daemon start|status|stop
1820
2025
  The same as a background service (systemd / launchd) [--domain a,b | --all-sites] [--yes]
@@ -1834,18 +2039,50 @@ var HELP = `unbrowse ${VERSION} — call websites as APIs through the Unbrowse A
1834
2039
  call <host> <tool> [JSON] Run one site tool with its inputs (or --set key=value…); prints the run
1835
2040
  [--deadline MS] [--select PATH,…] [--idempotency-key K] [--end-user ID]
1836
2041
 
1837
- mcp Local stdio MCP server proxying the hosted one (tool names use _ not .)
2042
+ map <url> A site's URLs from its sitemaps and links [--search TEXT] [--limit N]
2043
+ sites [site] What your workspace knows about each site: access, saved login, session
2044
+ forget <capability> Delete one of your learned capabilities
2045
+ connect [app] Connect an app's own MCP server (Linear, Notion, GitHub…) so its tools run as you
2046
+ [--url URL --name N] [--search TEXT] [--disconnect]
2047
+ credits [--pack p10|p50|p200] Credits left; --pack gets a checkout link
2048
+
2049
+ browse open <url> A recorded cloud browser on a page: its text and @refs [--task TEXT] [--country XX]
2050
+ browse snapshot <sessionId> The page now [--text-offset N]
2051
+ browse act <sessionId> <action> [ref] [value…]
2052
+ click | fill | select | check | press | wait | autofill [--name N] [--vault FIELD] [--key K]
2053
+ browse finish <sessionId> End it and learn the site's routes from what you did [--title T] [--goal G]
2054
+ browse close <sessionId> End it (still indexes unless --discard)
2055
+
2056
+ credentials list [origin] Saved logins, masked, for one site [--query TEXT]
2057
+ credentials request <origin> A one-time link for the person to save a login [--fields username,password,totp] [--reason TEXT]
2058
+ credentials status <requestId> Whether they did [--wait-seconds N]
2059
+
2060
+ replay list Recorded sessions [--site S] [--outcome O] [--has-error] [--from D] [--to D] [--limit N]
2061
+ replay search <query…> Search what happened in them (same filters)
2062
+ replay get <sid> One session: details, signals, summary
2063
+ replay timeline <sid> One session as text, a line per event [--kinds a,b]
2064
+ replay ask <question…> Ask across sessions (same filters)
2065
+
2066
+ tools [query | name] Every tool the hosted MCP lists you, your own learned and indexed site tools included;
2067
+ one name prints its description and inputs (--json: every schema)
2068
+ tool <name> [JSON] Call any of them by name, e.g. a learned one: unbrowse tool my__arxiv_org__get_cs_ai_recent --name cs.AI
2069
+ [--key value]… [--set key=value]… [--input JSON]
2070
+ the unbrowse_ prefix is optional; every --flag the CLI does not use is an input
2071
+ [--from-here] run sends its site requests from this machine, like \`unbrowse run\`
2072
+
2073
+ mcp Local stdio MCP server proxying the hosted one (tool names use _ not .)
1838
2074
  [--url URL] [--end-user ID] for agent hosts that need stdio or strict tool names (Grok Build)
1839
- [--from-here] unbrowse_run sends its site requests from this machine, like run (a Grok Bot's computer)
2075
+ [--from-here] unbrowse_run sends its site requests from this machine, like run (a Grok Bot's computer).
2076
+ It changes the IP only: it does not sign you in to a site (that is cookies sync)
1840
2077
  mcp add [claude] [codex] Register that proxy with Claude Code / Codex: they use this CLI's sign-in (no second sign-in)
1841
2078
  [--name NAME] [--replace] [--dry-run]
1842
2079
  And back: no CLI sign-in, but Claude Code signed in to Unbrowse (plugin) → the CLI uses that
1843
2080
 
1844
- Options: --json (errors as JSON) · --base-url URL · --no-open
1845
- Env: UNBROWSE_API_KEY, UNBROWSE_BASE_URL (default ${DEFAULT_ORIGIN}), UNBROWSE_EGRESS=server, UNBROWSE_MCP_URL, UNBROWSE_END_USER
2081
+ Options: --json (errors as JSON) · --base-url URL · --no-open · --account NAME
2082
+ Env: UNBROWSE_API_KEY, UNBROWSE_ACCOUNT, UNBROWSE_BASE_URL (default ${DEFAULT_ORIGIN}), UNBROWSE_EGRESS=server, UNBROWSE_MCP_URL, UNBROWSE_END_USER
1846
2083
  Exit: 0 ok · 1 error · 2 input required · 3 sign-in or login needed · 4 not verified`;
1847
- var BOOLEAN = new Set(["json", "help", "version", "no-open", "no-wait", "unattended", "from-here", "from-unbrowse", "all", "all-sites", "yes", "full", "events", "dry-run", "with-keys", "replace"]);
1848
- var NEEDS_ACCOUNT = new Set(["whoami", "usage", "discover", "run", "scrape", "index", "inspect", "resume", "cancel", "learn", "learned", "logins", "call", "cookies"]);
2084
+ var BOOLEAN = new Set(["json", "help", "version", "no-open", "no-wait", "unattended", "from-here", "from-unbrowse", "all", "all-sites", "yes", "full", "events", "dry-run", "with-keys", "replace", "discard", "disconnect", "has-error"]);
2085
+ var NEEDS_ACCOUNT = new Set(["whoami", "usage", "discover", "run", "scrape", "index", "inspect", "resume", "cancel", "learn", "learned", "logins", "call", "cookies", "tools", "tool", "map", "sites", "forget", "connect", "credits", "browse", "credentials", "replay"]);
1849
2086
  var SCRAPE_FORMATS = ["markdown", "html", "text", "links", "raw"];
1850
2087
  function parseArgs(argv) {
1851
2088
  const out = { _: [], flags: {}, sets: {} };
@@ -1903,6 +2140,15 @@ async function main(argv, io = stdio) {
1903
2140
  return io.out(VERSION), 0;
1904
2141
  if (!cmd || cmd === "help" || args.flags.help)
1905
2142
  return io.out(HELP), 0;
2143
+ if (args.flags.account === true)
2144
+ return io.err("usage: --account NAME"), 1;
2145
+ try {
2146
+ selectAccount(typeof args.flags.account === "string" ? args.flags.account : undefined);
2147
+ } catch (e) {
2148
+ return io.err(e.message), 1;
2149
+ }
2150
+ const named = account() !== "default" ? account() : undefined;
2151
+ const loginCmd = `unbrowse login${named ? ` --account ${named}` : ""}`;
1906
2152
  const origin = String(args.flags["base-url"] ?? process.env.UNBROWSE_BASE_URL ?? load().baseUrl ?? DEFAULT_ORIGIN).replace(/\/+$/, "");
1907
2153
  const flag = (k) => typeof args.flags[k] === "string" ? args.flags[k] : undefined;
1908
2154
  const print = (v) => io.out(JSON.stringify(v, null, 2));
@@ -1951,7 +2197,7 @@ async function main(argv, io = stdio) {
1951
2197
  io.err("This CLI runs from a temporary npx copy, which a background service cannot point at. Install it first: npm i -g unbrowse — then run this again.");
1952
2198
  return 1;
1953
2199
  }
1954
- const plan = D.servicePlan({ os: io.service?.os, home: io.service?.home, node, cli, env: { ...origin !== DEFAULT_ORIGIN ? { UNBROWSE_BASE_URL: origin } : {}, ...process.env.UNBROWSE_CONFIG_DIR ? { UNBROWSE_CONFIG_DIR: process.env.UNBROWSE_CONFIG_DIR } : {}, ...process.env.UNBROWSE_COOKIES_HOME ? { UNBROWSE_COOKIES_HOME: process.env.UNBROWSE_COOKIES_HOME } : {} } });
2200
+ const plan = D.servicePlan({ os: io.service?.os, home: io.service?.home, node, cli, account: named, env: { ...origin !== DEFAULT_ORIGIN ? { UNBROWSE_BASE_URL: origin } : {}, ...named ? { UNBROWSE_ACCOUNT: named } : {}, ...process.env.UNBROWSE_CONFIG_DIR ? { UNBROWSE_CONFIG_DIR: process.env.UNBROWSE_CONFIG_DIR } : {}, ...process.env.UNBROWSE_COOKIES_HOME ? { UNBROWSE_COOKIES_HOME: process.env.UNBROWSE_COOKIES_HOME } : {} } });
1955
2201
  if (!plan) {
1956
2202
  io.err("No background service on this OS yet. Keep it running with: unbrowse cookies watch (e.g. from Task Scheduler at logon).");
1957
2203
  return 1;
@@ -2002,7 +2248,7 @@ async function main(argv, io = stdio) {
2002
2248
  };
2003
2249
  const onboard = async () => {
2004
2250
  if (!io.interactive || args.flags.json) {
2005
- const message = `Not signed in to ${origin}. Run \`npx unbrowse login\` (opens your browser, nothing to paste), or set UNBROWSE_API_KEY (keys: ${origin}/app).`;
2251
+ const message = `Not signed in to ${origin}${named ? ` as account "${named}"` : ""}. Run \`npx ${loginCmd}\` (opens your browser, nothing to paste), or set UNBROWSE_API_KEY (keys: ${origin}/app).`;
2006
2252
  if (args.flags.json)
2007
2253
  print({ error: { status: 401, code: "not_signed_in", message, details: null } });
2008
2254
  else
@@ -2031,18 +2277,31 @@ Your browser opens ${origin}; approve it and \`unbrowse ${cmd}\` carries on. (Sc
2031
2277
  else
2032
2278
  await oauthLogin(origin, { open: (u) => openLink(u, args, io), log: io.err });
2033
2279
  const me = await (await client()).me();
2034
- io.err(`Signed in to ${origin} (workspace ${me.workspaceId}).`);
2280
+ io.err(`Signed in to ${origin}${named ? ` as account "${named}"` : ""} (workspace ${me.workspaceId}).`);
2035
2281
  await offerCookieSync().catch((e) => io.err(`Cookie sync not set up: ${e.message}`));
2036
2282
  return 0;
2037
2283
  }
2284
+ case "accounts": {
2285
+ if (rest[0] === "use") {
2286
+ const name = checkAccount(need(rest[1], "accounts use <name>"));
2287
+ useAccount(name);
2288
+ const saved = listAccounts().some((a) => a.name === name);
2289
+ io.err(`Commands now use account "${name}"${saved ? "" : ` (not signed in yet: unbrowse login${name === "default" ? "" : ` --account ${name}`})`}.${process.env.UNBROWSE_ACCOUNT ? ` UNBROWSE_ACCOUNT=${process.env.UNBROWSE_ACCOUNT} still wins while it is set.` : ""}`);
2290
+ return 0;
2291
+ }
2292
+ if (rest[0])
2293
+ throw new UsageError("usage: unbrowse accounts [use <name>]");
2294
+ print({ current: account(), accounts: listAccounts() });
2295
+ return 0;
2296
+ }
2038
2297
  case "mcp":
2039
- return await mcpAdd(rest.slice(1), args, io, origin);
2298
+ return await mcpAdd(rest.slice(1), args, io, origin, named);
2040
2299
  case "logout":
2041
2300
  clear();
2042
- io.err("Signed out.");
2301
+ io.err(named ? `Signed out of account "${named}".` : "Signed out.");
2043
2302
  return 0;
2044
2303
  case "whoami":
2045
- print({ origin, auth: describe(origin), ...await ub.me() });
2304
+ print({ origin, account: account(), auth: describe(origin), ...await ub.me() });
2046
2305
  return 0;
2047
2306
  case "usage":
2048
2307
  print(await ub.usage());
@@ -2066,6 +2325,8 @@ Your browser opens ${origin}; approve it and \`unbrowse ${cmd}\` carries on. (Sc
2066
2325
  };
2067
2326
  const fromHere = !args.flags["from-unbrowse"] && !args.flags["no-wait"] && process.env.UNBROWSE_EGRESS !== "server";
2068
2327
  const view = fromHere ? await ub.runOnClient(request, { onRequest: (r) => void io.err(`→ ${r.method} ${r.url}`) }) : await ub.run(request);
2328
+ if (fromHere && view.egress?.mode === "server")
2329
+ io.err("Ran from Unbrowse, not this machine: this site uses your saved sign-in, which never leaves your vault.");
2069
2330
  return settle(ub, view, args, io, print);
2070
2331
  }
2071
2332
  case "scrape": {
@@ -2180,7 +2441,7 @@ Your browser opens ${origin}; approve it and \`unbrowse ${cmd}\` carries on. (Sc
2180
2441
  if (sub === "daemon") {
2181
2442
  const action = rest[1] ?? "status";
2182
2443
  const { D, dir, saved, config } = await cookieSync();
2183
- const plan = D.servicePlan({ os: io.service?.os, home: io.service?.home, node: io.service?.node ?? process.execPath, cli: io.service?.cli ?? process.argv[1] ?? "" });
2444
+ const plan = D.servicePlan({ os: io.service?.os, home: io.service?.home, node: io.service?.node ?? process.execPath, cli: io.service?.cli ?? process.argv[1] ?? "", account: named });
2184
2445
  const exec = io.exec ?? (() => ({ status: 1, stdout: "", stderr: "no exec" }));
2185
2446
  if (action === "start" || action === "install")
2186
2447
  return await installCookieDaemon(config(), !!args.flags.yes);
@@ -2326,6 +2587,18 @@ Your browser opens ${origin}; approve it and \`unbrowse ${cmd}\` carries on. (Sc
2326
2587
  return io.err("Outcome unknown: a change may have happened. Inspect before retrying."), 4;
2327
2588
  return io.err(`${run.status}${run.error ? `: ${run.error.code} — ${run.error.message}` : ""}`), 1;
2328
2589
  }
2590
+ case "map":
2591
+ case "sites":
2592
+ case "forget":
2593
+ case "connect":
2594
+ case "credits":
2595
+ case "browse":
2596
+ case "credentials":
2597
+ case "replay":
2598
+ return await mcpCommand(cmd, rest, args, io, origin, print, client);
2599
+ case "tools":
2600
+ case "tool":
2601
+ return await mcpTools(cmd, rest, args, io, origin, print, client);
2329
2602
  default:
2330
2603
  throw new UsageError(`unknown command "${cmd}". Run \`unbrowse help\`.`);
2331
2604
  }
@@ -2341,10 +2614,13 @@ Your browser opens ${origin}; approve it and \`unbrowse ${cmd}\` carries on. (Sc
2341
2614
  const cause = e.cause;
2342
2615
  e.message = `could not reach ${origin}${cause?.code ? ` (${cause.code})` : cause?.message ? ` (${cause.message})` : ""}. Check the connection, or --base-url / UNBROWSE_BASE_URL.`;
2343
2616
  }
2617
+ const siteSignIn = e.status === 401 && siteLoginRequired(e.body);
2344
2618
  if (args.flags.json)
2345
2619
  print({ error: { status: e.status ?? null, message: e.message, details: e.body ?? null } });
2620
+ else if (siteSignIn)
2621
+ io.err(siteSignInHint(siteSignIn, e.message));
2346
2622
  else
2347
- io.err(e.status === 401 ? `Not signed in to ${origin}. Run \`unbrowse login\`, or set UNBROWSE_API_KEY.` : `error${e.status ? ` (HTTP ${e.status})` : ""}: ${e.message}`);
2623
+ io.err(e.status === 401 ? `Not signed in to ${origin}${named ? ` as account "${named}"` : ""}. Run \`${loginCmd}\`, or set UNBROWSE_API_KEY.` : `error${e.status ? ` (HTTP ${e.status})` : ""}: ${e.message}`);
2348
2624
  return e.status === 401 ? 3 : 1;
2349
2625
  }
2350
2626
  }
@@ -2379,12 +2655,12 @@ async function settle(ub, view, args, io, print) {
2379
2655
  io.err(`${view.status}: ${view.error.code}${view.error.message ? ` — ${view.error.message}` : ""}`);
2380
2656
  return 1;
2381
2657
  }
2382
- async function mcpAdd(rest, args, io, origin) {
2658
+ async function mcpAdd(rest, args, io, origin, account) {
2383
2659
  const HOSTS = ["claude", "codex"];
2384
2660
  const unknown = rest.filter((h) => !HOSTS.includes(h));
2385
2661
  if (unknown.length)
2386
2662
  throw new UsageError(`usage: unbrowse mcp add [claude] [codex] [--name NAME] [--replace] [--dry-run] (unknown: ${unknown.join(", ")})`);
2387
- const name = (typeof args.flags.name === "string" ? args.flags.name : "") || "unbrowse";
2663
+ const name = (typeof args.flags.name === "string" ? args.flags.name : "") || (account ? `unbrowse-${account}` : "unbrowse");
2388
2664
  const exec = io.exec ?? (() => ({ status: 1, stdout: "", stderr: "no exec" }));
2389
2665
  const dry = !!args.flags["dry-run"];
2390
2666
  const replace = !!args.flags.replace;
@@ -2395,7 +2671,7 @@ async function mcpAdd(rest, args, io, origin) {
2395
2671
  try {
2396
2672
  cli = realpathSync(cli);
2397
2673
  } catch {}
2398
- const launch = [...io.service?.cli || !ephemeralCli(cli) ? [io.service?.node ?? process.execPath, cli] : shell(["npx", "-y", "unbrowse"]), "mcp", ...origin !== DEFAULT_ORIGIN ? ["--base-url", origin] : []];
2674
+ const launch = [...io.service?.cli || !ephemeralCli(cli) ? [io.service?.node ?? process.execPath, cli] : shell(["npx", "-y", "unbrowse"]), "mcp", ...origin !== DEFAULT_ORIGIN ? ["--base-url", origin] : [], ...account ? ["--account", account] : []];
2399
2675
  const env = ["UNBROWSE_CONFIG_DIR", "XDG_CONFIG_HOME", "CLAUDE_CONFIG_DIR", "UNBROWSE_SHARED_SIGNIN"].flatMap((k) => process.env[k] ? [`${k}=${process.env[k]}`] : []);
2400
2676
  const plans = {
2401
2677
  claude: { get: ["claude", "mcp", "get", name], remove: ["claude", "mcp", "remove", name, "--scope", "user"], add: ["claude", "mcp", "add", "--scope", "user", name, ...env.flatMap((e) => ["-e", e]), "--", ...launch] },
@@ -2523,6 +2799,115 @@ ${unique(servers.filter((s) => !s.self)).length} to import: unbrowse mcps import
2523
2799
  }
2524
2800
  return rows.some((r) => r.status === "failed") ? 1 : 0;
2525
2801
  }
2802
+ async function mcpRpc(args, origin, client) {
2803
+ await Promise.resolve().then(() => init_mcp_proxy());
2804
+ await Promise.resolve().then(() => init_src());
2805
+ const url = process.env.UNBROWSE_MCP_URL ?? `${origin}/api/mcp`;
2806
+ const endUser = process.env.UNBROWSE_END_USER;
2807
+ const handle = createProxy(async () => new UnbrowseMcp({ url, apiKey: await tokenFor(origin, url) ?? "", endUser, client: `cli/${VERSION}` }), VERSION, args.flags["from-here"] ? { runLocal: localRun(client) } : {});
2808
+ let id = 0;
2809
+ return async (method, params) => {
2810
+ const res = await handle({ jsonrpc: "2.0", id: ++id, method, ...params ? { params } : {} });
2811
+ if (res.error)
2812
+ throw Object.assign(new Error(res.error.message), { status: res.error.data?.code === "unauthorized" || /unbrowse login/.test(res.error.message) ? 401 : undefined, code: res.error.data?.code });
2813
+ return res.result;
2814
+ };
2815
+ }
2816
+ async function printToolResult(result, io, print) {
2817
+ const T = await Promise.resolve().then(() => (init_mcp_tools(), {}));
2818
+ const value = resultValue(result);
2819
+ const code = resultCode(result, value);
2820
+ if (code === 1)
2821
+ io.err(typeof value === "string" ? value : JSON.stringify(value, null, 2));
2822
+ else if (typeof value === "string")
2823
+ io.out(value);
2824
+ else
2825
+ print(value);
2826
+ if (code === 2) {
2827
+ const runId = value.runId;
2828
+ io.err(`Input required: ${runId ? `unbrowse resume ${runId} key=value…` : "answer the open requirements and call again"}`);
2829
+ }
2830
+ return code;
2831
+ }
2832
+ async function mcpCommand(cmd, rest, args, io, origin, print, client) {
2833
+ const T = await Promise.resolve().then(() => (init_mcp_tools(), {}));
2834
+ const { command, usage } = findCommand(cmd, rest[0]);
2835
+ if (!command)
2836
+ throw new UsageError(`usage:
2837
+ ${usage}`);
2838
+ const words = command.sub ? rest.slice(1) : rest;
2839
+ const required = command.args.filter((a) => !a.endsWith("?")).length;
2840
+ if (words.length < required || words.length > command.args.length && !command.rest)
2841
+ throw new UsageError(`usage: unbrowse ${command.usage}`);
2842
+ const input = commandInput(command, words, args.flags, mapValues(args.sets), coerce);
2843
+ const rpc = await mcpRpc(args, origin, client);
2844
+ return printToolResult(await rpc("tools/call", { name: command.tool, arguments: input }), io, print);
2845
+ }
2846
+ async function mcpTools(cmd, rest, args, io, origin, print, client) {
2847
+ const T = await Promise.resolve().then(() => (init_mcp_tools(), {}));
2848
+ const rpc = await mcpRpc(args, origin, client);
2849
+ const { tools } = await rpc("tools/list");
2850
+ if (cmd === "tools") {
2851
+ const query = rest.join(" ");
2852
+ const one = rest.length === 1 ? resolveTool(tools, rest[0]) : undefined;
2853
+ if (one) {
2854
+ if (args.flags.json)
2855
+ return print(one), 0;
2856
+ io.out(`${one.name}
2857
+
2858
+ ${one.description ?? ""}
2859
+
2860
+ Inputs: ${JSON.stringify(one.inputSchema ?? {}, null, 2)}`);
2861
+ return io.err(`Call it: unbrowse tool ${shortName(one.name)} --key value…`), 0;
2862
+ }
2863
+ const shown = query ? filterTools(tools, query) : tools;
2864
+ if (args.flags.json)
2865
+ return print({ tools: shown }), 0;
2866
+ if (!shown.length)
2867
+ return io.err(`No tool matches "${query}". All of them: unbrowse tools`), 1;
2868
+ for (const t of shown)
2869
+ io.out(`${signature(t).padEnd(44)} ${summary(t.description)}`);
2870
+ io.err(`
2871
+ ${shown.length} tool(s). One in full: unbrowse tools <name> · call one: unbrowse tool <name> --key value…`);
2872
+ return 0;
2873
+ }
2874
+ const typed = need(rest[0], "tool <name> [JSON] [--key value]… (list them: unbrowse tools)");
2875
+ const tool = resolveTool(tools, typed);
2876
+ if (!tool) {
2877
+ const words = typed.toLowerCase().split(/[._\s-]+/).filter((w) => w && w !== "unbrowse");
2878
+ const near = tools.filter((t) => words.some((w) => shortName(t.name).toLowerCase().includes(w))).slice(0, 5).map((t) => shortName(t.name));
2879
+ throw new UsageError(`no MCP tool named "${typed}".${near.length ? ` Did you mean: ${near.join(", ")}?` : ""} List them: unbrowse tools`);
2880
+ }
2881
+ const input = toolInput(tool, rest[1] ? rest.slice(1).join(" ") : typeof args.flags.input === "string" ? args.flags.input : undefined, args.flags, mapValues(args.sets), coerce);
2882
+ return printToolResult(await rpc("tools/call", { name: tool.name, arguments: input }), io, print);
2883
+ }
2884
+ function siteLoginRequired(body) {
2885
+ const err = body?.error;
2886
+ if (err?.code !== "login_required")
2887
+ return;
2888
+ const d = err.details ?? {};
2889
+ let site = typeof d.site === "string" ? d.site : undefined;
2890
+ if (!site && typeof d.finalUrl === "string") {
2891
+ try {
2892
+ site = new URL(d.finalUrl).hostname.replace(/^www\./, "");
2893
+ } catch {}
2894
+ }
2895
+ const next = Array.isArray(d.next) ? d.next.filter((s) => typeof s === "string") : undefined;
2896
+ return { site, next };
2897
+ }
2898
+ function siteSignInHint(found, message) {
2899
+ const site = found.site ?? "<site>";
2900
+ const lines = [message || `${site} shows a sign-in page.`];
2901
+ if (found.next?.length)
2902
+ lines.push(...found.next.map((s) => ` - ${s}`));
2903
+ else {
2904
+ lines.push(` Use your own browser's sign-in: unbrowse cookies sync --domain ${site}`);
2905
+ lines.push(` Keep it fresh: unbrowse cookies daemon start --domain ${site}`);
2906
+ }
2907
+ lines.push(" (--from-here / --from-unbrowse change only where requests come from; neither signs you in.)");
2908
+ return lines.join(`
2909
+ `);
2910
+ }
2526
2911
  function noCapabilityHint(view, args) {
2527
2912
  const result = view.result ?? {};
2528
2913
  const task = args._.slice(1).join(" ");
@@ -2531,6 +2916,7 @@ function noCapabilityHint(view, args) {
2531
2916
  if (url) {
2532
2917
  lines.push(` Read the page now: unbrowse scrape ${url}`);
2533
2918
  lines.push(` Teach Unbrowse the site: unbrowse index ${url} (minutes; then run the task again)`);
2919
+ lines.push(` Do it in a cloud browser: unbrowse browse open ${url} (recorded, so it teaches the site too)`);
2534
2920
  } else {
2535
2921
  lines.push(` Name the site: unbrowse run ${JSON.stringify(task || "<task>")} --url https://…`);
2536
2922
  lines.push(" Read any page now: unbrowse scrape https://…");
@@ -2577,5 +2963,7 @@ export {
2577
2963
  DEFAULT_ORIGIN,
2578
2964
  main,
2579
2965
  noCapabilityHint,
2580
- parseArgs
2966
+ parseArgs,
2967
+ siteLoginRequired,
2968
+ siteSignInHint
2581
2969
  };
package/package.json CHANGED
@@ -1,8 +1,24 @@
1
1
  {
2
2
  "name": "unbrowse",
3
- "version": "12.3.1",
3
+ "version": "12.5.0",
4
4
  "mcpName": "io.github.unbrowse-ai/unbrowse",
5
5
  "description": "Call websites as APIs: a thin CLI over the Unbrowse API.",
6
+ "keywords": [
7
+ "unbrowse",
8
+ "cli",
9
+ "mcp",
10
+ "browser",
11
+ "web-scraping",
12
+ "scraper",
13
+ "api",
14
+ "agent",
15
+ "ai-agent",
16
+ "claude",
17
+ "llm",
18
+ "automation",
19
+ "headless-browser",
20
+ "website-to-api"
21
+ ],
6
22
  "license": "MIT",
7
23
  "type": "module",
8
24
  "homepage": "https://unbrowse.ai",
@@ -251,7 +251,8 @@
251
251
  "type": "string"
252
252
  },
253
253
  "value": {
254
- "type": "string"
254
+ "type": "string",
255
+ "description": "fill: the text to type. select: the option, by its value or label as the snapshot's `options` list it (any case; a unique part of a label also works)"
255
256
  },
256
257
  "name": {
257
258
  "type": "string"