@xbrowser/cli 1.35.0 → 1.36.1

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.
Files changed (35) hide show
  1. package/README.md +137 -80
  2. package/dist/{browser-MLKP72XP.js → browser-IEZOLTHA.js} +1 -1
  3. package/dist/{browser-KY7AIRAB.js → browser-NHQDQRXB.js} +1 -1
  4. package/dist/{browser-RZ7DPBI3.js → browser-XELRNYBL.js} +1 -1
  5. package/dist/{chunk-53VZHESL.js → chunk-3ZHERY5Z.js} +2 -2
  6. package/dist/{chunk-Y2GRCINH.js → chunk-5BD2RE4G.js} +78 -6
  7. package/dist/{chunk-VYTQLZAX.js → chunk-5UXRFNXG.js} +28 -2
  8. package/dist/{chunk-JYYKMSFH.js → chunk-7O73V4GO.js} +1 -1
  9. package/dist/{chunk-C5ZPXPD7.js → chunk-DGPPP5XB.js} +53 -16
  10. package/dist/{chunk-EGOWDZXP.js → chunk-DUC664TA.js} +2 -2
  11. package/dist/{chunk-BLCBCESM.js → chunk-ENTENDF5.js} +1 -1
  12. package/dist/{chunk-WGS3Y6ZV.js → chunk-HNIGRT6P.js} +1 -1
  13. package/dist/{chunk-GNLZWHSP.js → chunk-KSB4PMCY.js} +1 -1
  14. package/dist/{chunk-RMYKVZIZ.js → chunk-L6QJUB33.js} +28 -2
  15. package/dist/{chunk-QRFM4NOV.js → chunk-NE344XKO.js} +78 -6
  16. package/dist/{chunk-43U5VDLB.js → chunk-PGEZJ6V3.js} +1 -1
  17. package/dist/chunk-YW4BIJQL.js +489 -0
  18. package/dist/cli.js +69 -51
  19. package/dist/convert-JNOM6H6A.js +490 -0
  20. package/dist/{convert-R3XXYKC6.js → convert-K6TLQEPX.js} +5 -3
  21. package/dist/{daemon-client-Z3NKNZRL.js → daemon-client-D4JG74IW.js} +3 -1
  22. package/dist/{daemon-client-OXKRGLPQ.js → daemon-client-XKWIZI4N.js} +53 -16
  23. package/dist/daemon-main.js +101 -15
  24. package/dist/index.d.ts +26 -3
  25. package/dist/index.js +68 -50
  26. package/dist/{run-routes-TFNV5BBR.js → run-routes-BDNVNZOS.js} +4 -4
  27. package/dist/{run-routes-SJKVZ34L.js → run-routes-FBMZ3OUW.js} +4 -4
  28. package/dist/{server-HUSX7EFE.js → server-6OWQMWRG.js} +2 -2
  29. package/dist/{server-KSP5H4HD.js → server-TPM3X3XK.js} +2 -2
  30. package/dist/{session-recorder-RUNQOJ7T.js → session-recorder-CNTY5KXF.js} +1 -1
  31. package/dist/{session-recorder-N7VEKJVW.js → session-recorder-KMKSQWEP.js} +1 -1
  32. package/dist/{viewer-routes-YOS5GTCV.js → viewer-routes-7E7S2QBD.js} +2 -2
  33. package/package.json +3 -2
  34. package/dist/chunk-ETCO4SNK.js +0 -206
  35. package/dist/convert-LB3GJTLR.js +0 -207
package/dist/cli.js CHANGED
@@ -2,10 +2,11 @@
2
2
  import {
3
3
  handleRun,
4
4
  readStdin
5
- } from "./chunk-EGOWDZXP.js";
5
+ } from "./chunk-DUC664TA.js";
6
6
  import {
7
7
  PluginMetadataParser,
8
8
  XBrowserPluginLoader,
9
+ asZodSchema,
9
10
  attachDetectAntiBot,
10
11
  checkPluginLoginRequired,
11
12
  createStubContext,
@@ -19,9 +20,11 @@ import {
19
20
  getPluginStorage,
20
21
  isChainInput,
21
22
  loadHooks,
23
+ normalizeKebabParams,
22
24
  parsePluginParams,
23
- readJsonFile
24
- } from "./chunk-QRFM4NOV.js";
25
+ readJsonFile,
26
+ splitOutsideQuotes
27
+ } from "./chunk-NE344XKO.js";
25
28
  import {
26
29
  closeAllSessions,
27
30
  closeSessionByName,
@@ -30,7 +33,7 @@ import {
30
33
  findSession,
31
34
  getAllSessions,
32
35
  saveSessionDiskMeta
33
- } from "./chunk-GNLZWHSP.js";
36
+ } from "./chunk-KSB4PMCY.js";
34
37
  import "./chunk-JKVUFP3G.js";
35
38
  import "./chunk-3SZTCI33.js";
36
39
  import {
@@ -47,7 +50,7 @@ import {
47
50
  } from "./chunk-ZTHE5RBZ.js";
48
51
  import {
49
52
  handleViewer
50
- } from "./chunk-JYYKMSFH.js";
53
+ } from "./chunk-7O73V4GO.js";
51
54
  import {
52
55
  outputEnvelope,
53
56
  outputError,
@@ -77,7 +80,7 @@ import {
77
80
  forwardSessionClose,
78
81
  forwardSessionList,
79
82
  version
80
- } from "./chunk-C5ZPXPD7.js";
83
+ } from "./chunk-DGPPP5XB.js";
81
84
  import {
82
85
  getDaemonProcessStatus,
83
86
  killAllDaemonProcesses,
@@ -93,7 +96,7 @@ import {
93
96
  import {
94
97
  SessionRecorder,
95
98
  readMarkdownSummary
96
- } from "./chunk-RMYKVZIZ.js";
99
+ } from "./chunk-L6QJUB33.js";
97
100
  import {
98
101
  addKnownIssue,
99
102
  getKnowledgePath,
@@ -105,7 +108,7 @@ import {
105
108
  import "./chunk-KFQGP6VL.js";
106
109
 
107
110
  // src/router.ts
108
- import { parseArgs } from "@dyyz1993/xcli-core";
111
+ import { parseArgs, splitCommand, unquote } from "@dyyz1993/xcli-core";
109
112
 
110
113
  // src/utils/selector.ts
111
114
  var HTML_TAGS = /* @__PURE__ */ new Set([
@@ -193,11 +196,6 @@ function normalizeSelector(input) {
193
196
  return "#" + input;
194
197
  }
195
198
 
196
- // src/utils/zod-internal.ts
197
- function asZodSchema(value) {
198
- return value;
199
- }
200
-
201
199
  // src/cli/browser-routes.ts
202
200
  import { helpGenerator } from "@dyyz1993/xcli-core";
203
201
  function autoCompleteParams(cmdName, params, options) {
@@ -207,6 +205,7 @@ function autoCompleteParams(cmdName, params, options) {
207
205
  const schema = asZodSchema(cmd.parameters);
208
206
  const shape = schema?.shape ?? schema?._def?.shape;
209
207
  if (!shape) return params;
208
+ options = normalizeKebabParams(cmd.parameters, options);
210
209
  for (const key of Object.keys(shape)) {
211
210
  if (params[key] !== void 0) continue;
212
211
  const v = options[key];
@@ -2783,7 +2782,7 @@ async function handleSession(args, options, mode, _cdpEndpoint) {
2783
2782
  const sub = args[0];
2784
2783
  switch (sub) {
2785
2784
  case "handoff": {
2786
- const { handleViewer: handleViewer2 } = await import("./viewer-routes-YOS5GTCV.js");
2785
+ const { handleViewer: handleViewer2 } = await import("./viewer-routes-7E7S2QBD.js");
2787
2786
  await handleViewer2([], { ...options, session: args[1] ?? options.session }, mode, _cdpEndpoint);
2788
2787
  break;
2789
2788
  }
@@ -2791,7 +2790,7 @@ async function handleSession(args, options, mode, _cdpEndpoint) {
2791
2790
  case "restore": {
2792
2791
  const name = args[1] || options.session || process.env.XBROWSER_SESSION || "default";
2793
2792
  try {
2794
- const { forwardSessionState } = await import("./daemon-client-Z3NKNZRL.js");
2793
+ const { forwardSessionState } = await import("./daemon-client-D4JG74IW.js");
2795
2794
  const data = await forwardSessionState(sub, name);
2796
2795
  outputEnvelope({ success: true, data }, { command: `session ${sub}` }, mode);
2797
2796
  } catch (error) {
@@ -3321,7 +3320,7 @@ async function handlePlugin(args, options, mode) {
3321
3320
  } catch {
3322
3321
  }
3323
3322
  try {
3324
- const { daemonPing: daemonPing2 } = await import("./daemon-client-Z3NKNZRL.js");
3323
+ const { daemonPing: daemonPing2 } = await import("./daemon-client-D4JG74IW.js");
3325
3324
  if (await daemonPing2()) {
3326
3325
  await fetch("http://localhost:9224/rpc", {
3327
3326
  method: "POST",
@@ -3846,7 +3845,7 @@ async function handleConvert(args, _mode) {
3846
3845
  const fs2 = await import("fs");
3847
3846
  const path2 = await import("path");
3848
3847
  const { default: yaml } = await import("yaml");
3849
- const { generateJSScript, generatePythonScript, generateBashScript } = await import("./convert-LB3GJTLR.js");
3848
+ const { generateJSScript, generatePythonScript, generateBashScript } = await import("./convert-JNOM6H6A.js");
3850
3849
  let recording;
3851
3850
  try {
3852
3851
  const content = fs2.readFileSync(filePath, "utf-8");
@@ -3859,24 +3858,6 @@ async function handleConvert(args, _mode) {
3859
3858
  outputError(`Error: "${filePath}" does not contain a valid recording (expected a YAML/JSON object with events or actions).`);
3860
3859
  process.exit(1);
3861
3860
  }
3862
- const rawActions = recording.actions;
3863
- if (Array.isArray(rawActions) && !Array.isArray(recording.events)) {
3864
- recording.events = rawActions.map((a) => {
3865
- const action = a;
3866
- const element = action.element ?? {};
3867
- return {
3868
- type: action.type,
3869
- selector: element.selector ?? action.selector,
3870
- data: {
3871
- ...action.data,
3872
- value: action.value ?? action.data?.value,
3873
- key: action.key ?? action.data?.key,
3874
- x: action.scrollX ?? action.data?.x,
3875
- y: action.scrollY ?? action.data?.y
3876
- }
3877
- };
3878
- });
3879
- }
3880
3861
  const ext = path2.extname(outputPath).toLowerCase();
3881
3862
  const recordingTyped = recording;
3882
3863
  let script;
@@ -3889,12 +3870,13 @@ async function handleConvert(args, _mode) {
3889
3870
  }
3890
3871
  fs2.writeFileSync(outputPath, script);
3891
3872
  fs2.chmodSync(outputPath, 493);
3892
- const eventCount = (recordingTyped.events || []).length;
3873
+ const eventCount = [recordingTyped.events, recordingTyped.actions].find(Array.isArray)?.length ?? 0;
3874
+ const runner = ext === ".py" ? "python" : ext === ".sh" ? "bash" : "node";
3893
3875
  process.stdout.write(`Converted ${filePath} -> ${outputPath}
3894
3876
  `);
3895
3877
  process.stdout.write(` Events: ${eventCount}, Start URL: ${recordingTyped.startUrl}
3896
3878
  `);
3897
- process.stdout.write(` Run: ${ext === ".py" ? "python" : ext === ".sh" ? "./" : "node"} ${outputPath}
3879
+ process.stdout.write(` Run: ${runner} ${outputPath}
3898
3880
  `);
3899
3881
  }
3900
3882
  async function handleExtract(args, _mode) {
@@ -3941,7 +3923,7 @@ async function handleFilter(args, _mode, options) {
3941
3923
  }
3942
3924
  }
3943
3925
  async function handleGeneratePlugin(sessionName, pluginName, outputDir) {
3944
- const { SessionRecorder: SessionRecorder2 } = await import("./session-recorder-RUNQOJ7T.js");
3926
+ const { SessionRecorder: SessionRecorder2 } = await import("./session-recorder-CNTY5KXF.js");
3945
3927
  const { readSiteKnowledge: readSiteKnowledge2, toMarkdown } = await import("./site-knowledge-SYC6VCDB.js");
3946
3928
  const { mkdirSync: mkdirSync7, writeFileSync: writeFileSync7 } = await import("fs");
3947
3929
  const { join: join9 } = await import("path");
@@ -7180,6 +7162,10 @@ async function handleStdinMode(stdinCommands, argv) {
7180
7162
  async function handleEvalMode(argv) {
7181
7163
  const evalCommands = parseEvalFlags(argv);
7182
7164
  if (evalCommands.length === 0) return;
7165
+ if (evalCommands.includes("--help") || evalCommands.includes("-h")) {
7166
+ showMainHelp();
7167
+ return;
7168
+ }
7183
7169
  const knownCommands = new Set(getCommandNames());
7184
7170
  const chainParts = evalCommands.map((value) => {
7185
7171
  const firstWord = value.trim().split(/\s+/)[0] || "";
@@ -7453,6 +7439,7 @@ async function handleCommandHelp(command, positional, mode) {
7453
7439
  return true;
7454
7440
  }
7455
7441
  function showBuiltinHelp(builtinCmd, mode) {
7442
+ builtinCmd = hideInternalParams(builtinCmd);
7456
7443
  if (mode === "json") {
7457
7444
  const paramsList = [];
7458
7445
  const schema = asZodSchema(builtinCmd.parameters);
@@ -7487,6 +7474,22 @@ function showBuiltinHelp(builtinCmd, mode) {
7487
7474
  }
7488
7475
  console.log(helpGenerator3.generate(builtinCmd, { color: true, emoji: false }));
7489
7476
  }
7477
+ function hideInternalParams(builtinCmd) {
7478
+ const schema = builtinCmd.parameters;
7479
+ if (!schema || typeof schema.omit !== "function") return builtinCmd;
7480
+ const internal = asZodSchema(builtinCmd.parameters);
7481
+ const shapeOrFn = internal.shape ?? internal._def?.shape;
7482
+ const shape = typeof shapeOrFn === "function" ? shapeOrFn() : shapeOrFn;
7483
+ if (!shape) return builtinCmd;
7484
+ const mask = {};
7485
+ for (const [key, field] of Object.entries(shape)) {
7486
+ const fieldSchema = asZodSchema(field);
7487
+ const description = fieldSchema.description || fieldSchema._def?.description || "";
7488
+ if (description.startsWith("Internal:")) mask[key] = true;
7489
+ }
7490
+ if (Object.keys(mask).length === 0) return builtinCmd;
7491
+ return { ...builtinCmd, parameters: schema.omit(mask) };
7492
+ }
7490
7493
  var SUBCOMMAND_HELP = {
7491
7494
  session: "session open|close|kill|list [--session <name>] [--cdp <endpoint>]",
7492
7495
  plugin: "plugin install|uninstall|list|reload|schema|search|info <name>",
@@ -7499,7 +7502,7 @@ var SUBCOMMAND_HELP = {
7499
7502
  remote: "remote <url> [command] [--token <token>]",
7500
7503
  convert: "convert <file> [--to js|py|sh]",
7501
7504
  extract: "extract <file> [--format json|yaml]",
7502
- filter: "filter <file> [--include <type>] [--exclude <type>]",
7505
+ filter: "filter <in.yaml> <out.yaml> [--include <type>] [--exclude <type>]",
7503
7506
  test: "test <name> [--cdp <endpoint>]",
7504
7507
  viewer: "viewer [--session <name>]",
7505
7508
  "console-panel": "console-panel [--port <port>]",
@@ -8076,7 +8079,7 @@ async function handleRemote(args, options, mode) {
8076
8079
  }
8077
8080
  }
8078
8081
  async function startMcpServer() {
8079
- const { startMcpStdio } = await import("./server-KSP5H4HD.js");
8082
+ const { startMcpStdio } = await import("./server-TPM3X3XK.js");
8080
8083
  startMcpStdio();
8081
8084
  }
8082
8085
 
@@ -8126,7 +8129,7 @@ async function dispatchSubcommand(request) {
8126
8129
  if (cdpEndpoint || options.bridge) {
8127
8130
  outputError("Managed runs use a self-launched headless browser");
8128
8131
  } else {
8129
- const { handleManagedRunFile } = await import("./run-routes-TFNV5BBR.js");
8132
+ const { handleManagedRunFile } = await import("./run-routes-BDNVNZOS.js");
8130
8133
  await handleManagedRunFile(cmdArgs[0], { sessionName, parallel: options.parallel, mode });
8131
8134
  }
8132
8135
  } else {
@@ -8201,6 +8204,16 @@ var KNOWN_GLOBAL_OPTIONS = /* @__PURE__ */ new Set([
8201
8204
  "headless",
8202
8205
  "tab"
8203
8206
  ]);
8207
+ var GLOBAL_VALUE_FLAGS = /* @__PURE__ */ new Set([
8208
+ "--session",
8209
+ "--cdp",
8210
+ "--output",
8211
+ "-o",
8212
+ "--timeout",
8213
+ "--frame",
8214
+ "--target",
8215
+ "--tab"
8216
+ ]);
8204
8217
  async function handlePluginOrChainRoute(request) {
8205
8218
  const { command, cmdArgs, argv, options, mode, cdpEndpoint, sessionName, chainTokenStart, chainTokenEnd } = request;
8206
8219
  const loader = await getPluginLoader();
@@ -8222,7 +8235,7 @@ async function handlePluginOrChainRoute(request) {
8222
8235
  continue;
8223
8236
  }
8224
8237
  if (globalFlagSet.has(argv[i])) continue;
8225
- if (i > 0 && globalFlagSet.has(argv[i - 1]) && !argv[i].startsWith("-")) continue;
8238
+ if (i > 0 && GLOBAL_VALUE_FLAGS.has(argv[i - 1]) && !argv[i].startsWith("-")) continue;
8226
8239
  if (argv[i].startsWith("--session=") || argv[i].startsWith("--cdp=")) continue;
8227
8240
  cleanParts.push(argv[i]);
8228
8241
  }
@@ -8367,7 +8380,7 @@ Run "xbrowser ${command} ${subCommand} --help" to see available parameters.`
8367
8380
  }
8368
8381
  const needsBrowser = cmdEntry.scope === "page" || cmdEntry.scope === "browser";
8369
8382
  if (needsBrowser && !process.env.XBROWSER_DAEMON_WORKER) {
8370
- const { forwardPluginExec } = await import("./daemon-client-Z3NKNZRL.js");
8383
+ const { forwardPluginExec } = await import("./daemon-client-D4JG74IW.js");
8371
8384
  const userTimeout = typeof params.timeout === "number" && params.timeout > 0 ? params.timeout * 1e3 + 3e4 : void 0;
8372
8385
  const result = await forwardPluginExec(`${command}.${subCommand}`, params, sessionName, cdpEndpoint, userTimeout);
8373
8386
  const resultData = result && typeof result === "object" && "data" in result ? result.data : void 0;
@@ -8413,7 +8426,7 @@ Run "xbrowser ${command} ${subCommand} --help" to see available parameters.`
8413
8426
  const targetPage = pages[cmdTabIndex];
8414
8427
  await targetPage.bringToFront().catch(() => {
8415
8428
  });
8416
- const { setActivePage } = await import("./browser-KY7AIRAB.js");
8429
+ const { setActivePage } = await import("./browser-NHQDQRXB.js");
8417
8430
  setActivePage(session, targetPage);
8418
8431
  }
8419
8432
  }
@@ -8540,8 +8553,10 @@ async function routeCommand(argvIn, stdinCommands) {
8540
8553
  return;
8541
8554
  }
8542
8555
  const evalStart = findEvalStart(argv);
8543
- if (evalStart >= 0 && argv.length > evalStart + 1) {
8544
- await handleEvalScript(argv.slice(evalStart + 1), argv);
8556
+ const evalParts = evalStart >= 0 ? argv.slice(evalStart + 1) : [];
8557
+ const evalHelpRequested = evalParts.includes("--help") || evalParts.includes("-h");
8558
+ if (evalStart >= 0 && evalParts.length > 0 && !evalHelpRequested) {
8559
+ await handleEvalScript(evalParts, argv);
8545
8560
  return;
8546
8561
  }
8547
8562
  if (parseEvalFlags(argv).length > 0) {
@@ -8560,12 +8575,12 @@ async function routeCommand(argvIn, stdinCommands) {
8560
8575
  if (argv[0] === "--json" || argv[0] === "--yaml") {
8561
8576
  argv = argv.slice(1);
8562
8577
  }
8563
- const globalFlags = /* @__PURE__ */ new Set(["--session", "--cdp", "--json", "--yaml", "--output", "--timeout", "--help", "-h", "--version", "--frame", "--target", "--tab", "--bridge"]);
8578
+ const globalFlags = /* @__PURE__ */ new Set([...GLOBAL_VALUE_FLAGS, "--json", "--yaml", "--help", "-h", "--version", "--bridge"]);
8564
8579
  let chainArgIdx = -1;
8565
8580
  let seenCommandWord = false;
8566
8581
  for (let i = 0; i < argv.length; i++) {
8567
8582
  if (globalFlags.has(argv[i])) continue;
8568
- if (globalFlags.has(argv[i]) || i > 0 && globalFlags.has(argv[i - 1]) && !argv[i].startsWith("-")) continue;
8583
+ if (globalFlags.has(argv[i]) || i > 0 && GLOBAL_VALUE_FLAGS.has(argv[i - 1]) && !argv[i].startsWith("-")) continue;
8569
8584
  if (!seenCommandWord) {
8570
8585
  if (argv[i].includes(" ") && /^[a-zA-Z]/.test(argv[i])) {
8571
8586
  chainArgIdx = i;
@@ -8576,12 +8591,15 @@ async function routeCommand(argvIn, stdinCommands) {
8576
8591
  }
8577
8592
  if (chainArgIdx >= 0) {
8578
8593
  const chainArg = argv[chainArgIdx];
8594
+ if (isChainInput(chainArg)) {
8595
+ await handleChainInput(chainArg, argvIn);
8596
+ return;
8597
+ }
8579
8598
  const spaceIdx = chainArg.indexOf(" ");
8580
8599
  const possibleCmd = chainArg.substring(0, spaceIdx);
8581
8600
  if (/^[a-zA-Z][\w-]*$/.test(possibleCmd)) {
8582
8601
  const remainder = chainArg.substring(spaceIdx + 1);
8583
- let remainderParts = remainder.split(/\s+/).filter(Boolean);
8584
- remainderParts = remainderParts.flatMap((part) => part.split(";").filter(Boolean));
8602
+ const remainderParts = splitOutsideQuotes(remainder, ";").flatMap((part) => splitCommand(part)).map(unquote);
8585
8603
  chainTokenStart = chainArgIdx;
8586
8604
  chainTokenEnd = chainArgIdx + remainderParts.length;
8587
8605
  argv = [...argv.slice(0, chainArgIdx), possibleCmd, ...remainderParts, ...argv.slice(chainArgIdx + 1)];
@@ -8672,7 +8690,7 @@ async function main() {
8672
8690
  const commandSub = process.argv[3];
8673
8691
  const isLongRunning = command === "preview" || command === "serve" || command === "mcp" || command === "console-panel" || command === "site-memory" && commandSub === "mcp";
8674
8692
  if (!isLongRunning) {
8675
- const { ensureProcessCanExit } = await import("./browser-KY7AIRAB.js");
8693
+ const { ensureProcessCanExit } = await import("./browser-NHQDQRXB.js");
8676
8694
  await ensureProcessCanExit().catch(() => {
8677
8695
  });
8678
8696
  process.exit(process.exitCode || exitCode);