@xbrowser/cli 1.5.2 → 1.5.3

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.
@@ -140,6 +140,7 @@ async function ensureDaemonRunning() {
140
140
  if (healthOk) return;
141
141
  if (attempt < 2) await new Promise((r) => setTimeout(r, 500));
142
142
  }
143
+ console.error("\u{1F504} Starting daemon...");
143
144
  _ensurePromise = startDaemonProcess(DAEMON_PORT).then(() => {
144
145
  });
145
146
  _ensurePromise.catch(() => {
@@ -153,7 +154,10 @@ async function ensureDaemonRunning() {
153
154
  }
154
155
  for (let attempt = 0; attempt < 20; attempt++) {
155
156
  const ready = await fetch(`${DAEMON_BASE}/health`, { signal: AbortSignal.timeout(1e3) }).then((r) => r.ok ? r.json() : null).then((d) => d?.status === "ok").catch(() => false);
156
- if (ready) return;
157
+ if (ready) {
158
+ console.error("\u2705 Daemon ready");
159
+ return;
160
+ }
157
161
  await new Promise((r) => setTimeout(r, 200));
158
162
  }
159
163
  throw new Error("Daemon HTTP server not ready after 4s");
package/dist/cli.js CHANGED
@@ -54,7 +54,7 @@ import {
54
54
  killAllDaemonProcesses,
55
55
  startDaemonProcess,
56
56
  stopDaemonProcess
57
- } from "./chunk-JPSFUFPG.js";
57
+ } from "./chunk-L35D5DAY.js";
58
58
  import {
59
59
  errMsg
60
60
  } from "./chunk-GDKLH7ZY.js";
@@ -1126,7 +1126,7 @@ var screenshotCommand = registerCommand({
1126
1126
  buffer = await ctx.page.screenshot(options);
1127
1127
  }
1128
1128
  if (p.output) {
1129
- writeFileSync(p.output, buffer);
1129
+ writeFileSync(p.output, buffer, "binary");
1130
1130
  return ok9({
1131
1131
  output: p.output,
1132
1132
  format,
@@ -1142,7 +1142,7 @@ var screenshotCommand = registerCommand({
1142
1142
  }
1143
1143
  ensureScreenshotsDir();
1144
1144
  const screenshotPath = generateScreenshotPath(format);
1145
- writeFileSync(screenshotPath, buffer);
1145
+ writeFileSync(screenshotPath, buffer, "binary");
1146
1146
  return ok9({
1147
1147
  output: screenshotPath,
1148
1148
  format,
@@ -5401,8 +5401,8 @@ function parseCommandChain(input, options) {
5401
5401
  continue;
5402
5402
  }
5403
5403
  if (char === "-" && input[i + 1] === ">" && isSpaceAround(input, i, 2)) {
5404
- pushCommand();
5405
- lastOperator = "and";
5404
+ lastOperator = "sequence";
5405
+ flushPipeline();
5406
5406
  i++;
5407
5407
  continue;
5408
5408
  }
@@ -5412,8 +5412,8 @@ function parseCommandChain(input, options) {
5412
5412
  continue;
5413
5413
  }
5414
5414
  if (char === "+" && isSpaceAdjacent(input, i)) {
5415
- pushCommand();
5416
- lastOperator = "and";
5415
+ lastOperator = "sequence";
5416
+ flushPipeline();
5417
5417
  continue;
5418
5418
  }
5419
5419
  if (options?.fileMode && char === "|" && input[i + 1] !== "|") {
@@ -7015,6 +7015,18 @@ async function loadHooks() {
7015
7015
  // src/executor.ts
7016
7016
  import { homedir as homedir6 } from "os";
7017
7017
  import { join as join6 } from "path";
7018
+ function levenshtein(a, b) {
7019
+ const m = a.length, n = b.length;
7020
+ const dp = Array(m + 1).fill(null).map(() => Array(n + 1).fill(0));
7021
+ for (let i = 0; i <= m; i++) dp[i][0] = i;
7022
+ for (let j = 0; j <= n; j++) dp[0][j] = j;
7023
+ for (let i = 1; i <= m; i++) {
7024
+ for (let j = 1; j <= n; j++) {
7025
+ dp[i][j] = a[i - 1] === b[j - 1] ? dp[i - 1][j - 1] : 1 + Math.min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]);
7026
+ }
7027
+ }
7028
+ return dp[m][n];
7029
+ }
7018
7030
  var NAVIGATION_COMMANDS = /* @__PURE__ */ new Set(["goto", "back", "forward", "refresh"]);
7019
7031
  var snapshotHintShown = /* @__PURE__ */ new WeakSet();
7020
7032
  var CONFIG_DIR2 = join6(homedir6(), ".xbrowser");
@@ -7075,8 +7087,10 @@ async function executeCommand(commandName, params, sessionName = "default", extr
7075
7087
  const command = getCommand(commandName);
7076
7088
  if (!command) {
7077
7089
  const available = getAllCommands().map((c) => c.name);
7090
+ const suggestions = available.map((name) => ({ name, dist: levenshtein(commandName, name) })).filter((s) => s.dist <= 3).sort((a, b) => a.dist - b.dist).slice(0, 3).map((s) => s.name);
7091
+ const hint = suggestions.length > 0 ? ` Did you mean: ${suggestions.join(" or ")}?` : "";
7078
7092
  return errorResult(
7079
- `Unknown command: ${commandName}. Available: ${available.join(", ")}`
7093
+ `Unknown command: ${commandName}.${hint} Available: ${available.join(", ")}`
7080
7094
  );
7081
7095
  }
7082
7096
  const _target = params._target;
@@ -7103,7 +7117,7 @@ async function executeCommand(commandName, params, sessionName = "default", extr
7103
7117
  params = result.data;
7104
7118
  }
7105
7119
  if (command.scope !== "cli" && !process.env.XBROWSER_DAEMON_WORKER) {
7106
- const { forwardExec } = await import("./daemon-client-XXKMJZZ7.js");
7120
+ const { forwardExec } = await import("./daemon-client-S3EUTRC6.js");
7107
7121
  const result = await forwardExec(commandName, params, sessionName, extraOpts?.cdpEndpoint);
7108
7122
  if (result) return result;
7109
7123
  }
@@ -10441,7 +10455,7 @@ async function handlePlugin(args, options, mode) {
10441
10455
  } catch {
10442
10456
  }
10443
10457
  try {
10444
- const { daemonPing } = await import("./daemon-client-XXKMJZZ7.js");
10458
+ const { daemonPing } = await import("./daemon-client-S3EUTRC6.js");
10445
10459
  if (await daemonPing()) {
10446
10460
  await fetch("http://localhost:9224/rpc", {
10447
10461
  method: "POST",
@@ -12520,7 +12534,7 @@ async function routeCommand(argvIn, stdinCommands) {
12520
12534
  const mode = options.json ? "json" : options.yaml ? "yaml" : "text";
12521
12535
  const sessionName = options.session || process.env.XBROWSER_SESSION || "default";
12522
12536
  const cdpEndpoint = options.cdp || process.env.XBROWSER_CDP;
12523
- if (options.version) {
12537
+ if (options.version || options.v && positional.length === 0) {
12524
12538
  console.log(`xbrowser v${version}`);
12525
12539
  return;
12526
12540
  }
@@ -12711,6 +12725,22 @@ async function routeCommand(argvIn, stdinCommands) {
12711
12725
  const fullInput = cleanParts.join(" ");
12712
12726
  if (isChainInput(fullInput)) {
12713
12727
  const chainResult = await executeChain(fullInput, { cdpEndpoint, sessionName });
12728
+ if (mode === "json" || mode === "yaml") {
12729
+ const output = {
12730
+ success: chainResult.success,
12731
+ steps: chainResult.steps.map((s) => ({
12732
+ command: s.raw,
12733
+ success: s.success,
12734
+ data: s.data,
12735
+ duration: s.duration
12736
+ })),
12737
+ totalDuration: chainResult.totalDuration,
12738
+ ...chainResult.stoppedReason ? { stoppedReason: chainResult.stoppedReason } : {}
12739
+ };
12740
+ outputResult(output, mode);
12741
+ if (!chainResult.success) throw new Error("Command failed");
12742
+ return;
12743
+ }
12714
12744
  for (const step of chainResult.steps) {
12715
12745
  if (step.success) {
12716
12746
  console.log(`[OK] ${step.raw}`);
@@ -12820,7 +12850,7 @@ Run "xbrowser ${command} ${subCommand} --help" to see available parameters.`
12820
12850
  }
12821
12851
  const needsBrowser = cmdEntry.scope === "page" || cmdEntry.scope === "browser";
12822
12852
  if (needsBrowser && !process.env.XBROWSER_DAEMON_WORKER) {
12823
- const { forwardExec } = await import("./daemon-client-XXKMJZZ7.js");
12853
+ const { forwardExec } = await import("./daemon-client-S3EUTRC6.js");
12824
12854
  const userTimeout = typeof params.timeout === "number" && params.timeout > 0 ? params.timeout * 1e3 + 3e4 : void 0;
12825
12855
  const result = await forwardExec(`${command}.${subCommand}`, params, sessionName, cdpEndpoint, userTimeout);
12826
12856
  const resultData = result && typeof result === "object" && "data" in result ? result.data : void 0;
@@ -29,7 +29,7 @@ import {
29
29
  forwardSessionList,
30
30
  forwardViewerCheckSelector,
31
31
  isDaemonRunning
32
- } from "./chunk-JPSFUFPG.js";
32
+ } from "./chunk-L35D5DAY.js";
33
33
  import "./chunk-GDKLH7ZY.js";
34
34
  import "./chunk-KFQGP6VL.js";
35
35
  export {
@@ -23,6 +23,7 @@ async function ensureDaemonRunning() {
23
23
  if (healthOk) return;
24
24
  if (attempt < 2) await new Promise((r) => setTimeout(r, 500));
25
25
  }
26
+ console.error("\u{1F504} Starting daemon...");
26
27
  _ensurePromise = startDaemonProcess(DAEMON_PORT).then(() => {
27
28
  });
28
29
  _ensurePromise.catch(() => {
@@ -36,7 +37,10 @@ async function ensureDaemonRunning() {
36
37
  }
37
38
  for (let attempt = 0; attempt < 20; attempt++) {
38
39
  const ready = await fetch(`${DAEMON_BASE}/health`, { signal: AbortSignal.timeout(1e3) }).then((r) => r.ok ? r.json() : null).then((d) => d?.status === "ok").catch(() => false);
39
- if (ready) return;
40
+ if (ready) {
41
+ console.error("\u2705 Daemon ready");
42
+ return;
43
+ }
40
44
  await new Promise((r) => setTimeout(r, 200));
41
45
  }
42
46
  throw new Error("Daemon HTTP server not ready after 4s");
@@ -1087,7 +1087,7 @@ var screenshotCommand = registerCommand({
1087
1087
  buffer = await ctx.page.screenshot(options);
1088
1088
  }
1089
1089
  if (p.output) {
1090
- writeFileSync(p.output, buffer);
1090
+ writeFileSync(p.output, buffer, "binary");
1091
1091
  return ok9({
1092
1092
  output: p.output,
1093
1093
  format,
@@ -1103,7 +1103,7 @@ var screenshotCommand = registerCommand({
1103
1103
  }
1104
1104
  ensureScreenshotsDir();
1105
1105
  const screenshotPath = generateScreenshotPath(format);
1106
- writeFileSync(screenshotPath, buffer);
1106
+ writeFileSync(screenshotPath, buffer, "binary");
1107
1107
  return ok9({
1108
1108
  output: screenshotPath,
1109
1109
  format,
@@ -5362,8 +5362,8 @@ function parseCommandChain(input, options) {
5362
5362
  continue;
5363
5363
  }
5364
5364
  if (char === "-" && input[i + 1] === ">" && isSpaceAround(input, i, 2)) {
5365
- pushCommand();
5366
- lastOperator = "and";
5365
+ lastOperator = "sequence";
5366
+ flushPipeline();
5367
5367
  i++;
5368
5368
  continue;
5369
5369
  }
@@ -5373,8 +5373,8 @@ function parseCommandChain(input, options) {
5373
5373
  continue;
5374
5374
  }
5375
5375
  if (char === "+" && isSpaceAdjacent(input, i)) {
5376
- pushCommand();
5377
- lastOperator = "and";
5376
+ lastOperator = "sequence";
5377
+ flushPipeline();
5378
5378
  continue;
5379
5379
  }
5380
5380
  if (options?.fileMode && char === "|" && input[i + 1] !== "|") {
@@ -6546,6 +6546,18 @@ async function loadHooks() {
6546
6546
  // src/executor.ts
6547
6547
  import { homedir as homedir5 } from "os";
6548
6548
  import { join as join5 } from "path";
6549
+ function levenshtein(a, b) {
6550
+ const m = a.length, n = b.length;
6551
+ const dp = Array(m + 1).fill(null).map(() => Array(n + 1).fill(0));
6552
+ for (let i = 0; i <= m; i++) dp[i][0] = i;
6553
+ for (let j = 0; j <= n; j++) dp[0][j] = j;
6554
+ for (let i = 1; i <= m; i++) {
6555
+ for (let j = 1; j <= n; j++) {
6556
+ dp[i][j] = a[i - 1] === b[j - 1] ? dp[i - 1][j - 1] : 1 + Math.min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]);
6557
+ }
6558
+ }
6559
+ return dp[m][n];
6560
+ }
6549
6561
  var NAVIGATION_COMMANDS = /* @__PURE__ */ new Set(["goto", "back", "forward", "refresh"]);
6550
6562
  var snapshotHintShown = /* @__PURE__ */ new WeakSet();
6551
6563
  var CONFIG_DIR2 = join5(homedir5(), ".xbrowser");
@@ -6606,8 +6618,10 @@ async function executeCommand(commandName, params, sessionName = "default", extr
6606
6618
  const command = getCommand(commandName);
6607
6619
  if (!command) {
6608
6620
  const available = getAllCommands().map((c) => c.name);
6621
+ const suggestions = available.map((name) => ({ name, dist: levenshtein(commandName, name) })).filter((s) => s.dist <= 3).sort((a, b) => a.dist - b.dist).slice(0, 3).map((s) => s.name);
6622
+ const hint = suggestions.length > 0 ? ` Did you mean: ${suggestions.join(" or ")}?` : "";
6609
6623
  return errorResult(
6610
- `Unknown command: ${commandName}. Available: ${available.join(", ")}`
6624
+ `Unknown command: ${commandName}.${hint} Available: ${available.join(", ")}`
6611
6625
  );
6612
6626
  }
6613
6627
  const _target = params._target;
@@ -6634,7 +6648,7 @@ async function executeCommand(commandName, params, sessionName = "default", extr
6634
6648
  params = result.data;
6635
6649
  }
6636
6650
  if (command.scope !== "cli" && !process.env.XBROWSER_DAEMON_WORKER) {
6637
- const { forwardExec } = await import("./daemon-client-COJQESU2.js");
6651
+ const { forwardExec } = await import("./daemon-client-WT7PTGYQ.js");
6638
6652
  const result = await forwardExec(commandName, params, sessionName, extraOpts?.cdpEndpoint);
6639
6653
  if (result) return result;
6640
6654
  }
package/dist/index.js CHANGED
@@ -25,7 +25,7 @@ import {
25
25
  killAllDaemonProcesses,
26
26
  startDaemonProcess,
27
27
  stopDaemonProcess
28
- } from "./chunk-JPSFUFPG.js";
28
+ } from "./chunk-L35D5DAY.js";
29
29
  import {
30
30
  CaptchaDetector,
31
31
  HumanInteractionManager,
@@ -1166,7 +1166,7 @@ var screenshotCommand = registerCommand({
1166
1166
  buffer = await ctx.page.screenshot(options);
1167
1167
  }
1168
1168
  if (p.output) {
1169
- writeFileSync(p.output, buffer);
1169
+ writeFileSync(p.output, buffer, "binary");
1170
1170
  return ok9({
1171
1171
  output: p.output,
1172
1172
  format,
@@ -1182,7 +1182,7 @@ var screenshotCommand = registerCommand({
1182
1182
  }
1183
1183
  ensureScreenshotsDir();
1184
1184
  const screenshotPath = generateScreenshotPath(format);
1185
- writeFileSync(screenshotPath, buffer);
1185
+ writeFileSync(screenshotPath, buffer, "binary");
1186
1186
  return ok9({
1187
1187
  output: screenshotPath,
1188
1188
  format,
@@ -5718,8 +5718,8 @@ function parseCommandChain(input, options) {
5718
5718
  continue;
5719
5719
  }
5720
5720
  if (char === "-" && input[i + 1] === ">" && isSpaceAround(input, i, 2)) {
5721
- pushCommand();
5722
- lastOperator = "and";
5721
+ lastOperator = "sequence";
5722
+ flushPipeline();
5723
5723
  i++;
5724
5724
  continue;
5725
5725
  }
@@ -5729,8 +5729,8 @@ function parseCommandChain(input, options) {
5729
5729
  continue;
5730
5730
  }
5731
5731
  if (char === "+" && isSpaceAdjacent(input, i)) {
5732
- pushCommand();
5733
- lastOperator = "and";
5732
+ lastOperator = "sequence";
5733
+ flushPipeline();
5734
5734
  continue;
5735
5735
  }
5736
5736
  if (options?.fileMode && char === "|" && input[i + 1] !== "|") {
@@ -7332,6 +7332,18 @@ async function loadHooks() {
7332
7332
  // src/executor.ts
7333
7333
  import { homedir as homedir6 } from "os";
7334
7334
  import { join as join6 } from "path";
7335
+ function levenshtein(a, b) {
7336
+ const m = a.length, n = b.length;
7337
+ const dp = Array(m + 1).fill(null).map(() => Array(n + 1).fill(0));
7338
+ for (let i = 0; i <= m; i++) dp[i][0] = i;
7339
+ for (let j = 0; j <= n; j++) dp[0][j] = j;
7340
+ for (let i = 1; i <= m; i++) {
7341
+ for (let j = 1; j <= n; j++) {
7342
+ dp[i][j] = a[i - 1] === b[j - 1] ? dp[i - 1][j - 1] : 1 + Math.min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1]);
7343
+ }
7344
+ }
7345
+ return dp[m][n];
7346
+ }
7335
7347
  var NAVIGATION_COMMANDS = /* @__PURE__ */ new Set(["goto", "back", "forward", "refresh"]);
7336
7348
  var snapshotHintShown = /* @__PURE__ */ new WeakSet();
7337
7349
  var CONFIG_DIR2 = join6(homedir6(), ".xbrowser");
@@ -7395,8 +7407,10 @@ async function executeCommand(commandName, params, sessionName = "default", extr
7395
7407
  const command = getCommand(commandName);
7396
7408
  if (!command) {
7397
7409
  const available = getAllCommands().map((c) => c.name);
7410
+ const suggestions = available.map((name) => ({ name, dist: levenshtein(commandName, name) })).filter((s) => s.dist <= 3).sort((a, b) => a.dist - b.dist).slice(0, 3).map((s) => s.name);
7411
+ const hint = suggestions.length > 0 ? ` Did you mean: ${suggestions.join(" or ")}?` : "";
7398
7412
  return errorResult(
7399
- `Unknown command: ${commandName}. Available: ${available.join(", ")}`
7413
+ `Unknown command: ${commandName}.${hint} Available: ${available.join(", ")}`
7400
7414
  );
7401
7415
  }
7402
7416
  const _target = params._target;
@@ -7423,7 +7437,7 @@ async function executeCommand(commandName, params, sessionName = "default", extr
7423
7437
  params = result.data;
7424
7438
  }
7425
7439
  if (command.scope !== "cli" && !process.env.XBROWSER_DAEMON_WORKER) {
7426
- const { forwardExec } = await import("./daemon-client-XXKMJZZ7.js");
7440
+ const { forwardExec } = await import("./daemon-client-S3EUTRC6.js");
7427
7441
  const result = await forwardExec(commandName, params, sessionName, extraOpts?.cdpEndpoint);
7428
7442
  if (result) return result;
7429
7443
  }
@@ -10781,7 +10795,7 @@ async function handlePlugin(args, options, mode) {
10781
10795
  } catch {
10782
10796
  }
10783
10797
  try {
10784
- const { daemonPing } = await import("./daemon-client-XXKMJZZ7.js");
10798
+ const { daemonPing } = await import("./daemon-client-S3EUTRC6.js");
10785
10799
  if (await daemonPing()) {
10786
10800
  await fetch("http://localhost:9224/rpc", {
10787
10801
  method: "POST",
@@ -12860,7 +12874,7 @@ async function routeCommand(argvIn, stdinCommands) {
12860
12874
  const mode = options.json ? "json" : options.yaml ? "yaml" : "text";
12861
12875
  const sessionName = options.session || process.env.XBROWSER_SESSION || "default";
12862
12876
  const cdpEndpoint = options.cdp || process.env.XBROWSER_CDP;
12863
- if (options.version) {
12877
+ if (options.version || options.v && positional.length === 0) {
12864
12878
  console.log(`xbrowser v${version}`);
12865
12879
  return;
12866
12880
  }
@@ -13051,6 +13065,22 @@ async function routeCommand(argvIn, stdinCommands) {
13051
13065
  const fullInput = cleanParts.join(" ");
13052
13066
  if (isChainInput(fullInput)) {
13053
13067
  const chainResult = await executeChain(fullInput, { cdpEndpoint, sessionName });
13068
+ if (mode === "json" || mode === "yaml") {
13069
+ const output = {
13070
+ success: chainResult.success,
13071
+ steps: chainResult.steps.map((s) => ({
13072
+ command: s.raw,
13073
+ success: s.success,
13074
+ data: s.data,
13075
+ duration: s.duration
13076
+ })),
13077
+ totalDuration: chainResult.totalDuration,
13078
+ ...chainResult.stoppedReason ? { stoppedReason: chainResult.stoppedReason } : {}
13079
+ };
13080
+ outputResult(output, mode);
13081
+ if (!chainResult.success) throw new Error("Command failed");
13082
+ return;
13083
+ }
13054
13084
  for (const step of chainResult.steps) {
13055
13085
  if (step.success) {
13056
13086
  console.log(`[OK] ${step.raw}`);
@@ -13160,7 +13190,7 @@ Run "xbrowser ${command} ${subCommand} --help" to see available parameters.`
13160
13190
  }
13161
13191
  const needsBrowser = cmdEntry.scope === "page" || cmdEntry.scope === "browser";
13162
13192
  if (needsBrowser && !process.env.XBROWSER_DAEMON_WORKER) {
13163
- const { forwardExec } = await import("./daemon-client-XXKMJZZ7.js");
13193
+ const { forwardExec } = await import("./daemon-client-S3EUTRC6.js");
13164
13194
  const userTimeout = typeof params.timeout === "number" && params.timeout > 0 ? params.timeout * 1e3 + 3e4 : void 0;
13165
13195
  const result = await forwardExec(`${command}.${subCommand}`, params, sessionName, cdpEndpoint, userTimeout);
13166
13196
  const resultData = result && typeof result === "object" && "data" in result ? result.data : void 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xbrowser/cli",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
4
4
  "description": "Browser automation CLI for web scraping, headless browsing, SEO analysis, and AI agent workflows. A command-line alternative to Playwright, Puppeteer, and Selenium.",
5
5
  "type": "module",
6
6
  "bin": {