@xbrowser/cli 1.34.0 → 1.35.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.
Files changed (53) hide show
  1. package/dist/{browser-GXL6V2JW.js → browser-KY7AIRAB.js} +3 -2
  2. package/dist/{browser-ZWEJ663M.js → browser-MLKP72XP.js} +3 -3
  3. package/dist/{browser-X7LO42UI.js → browser-RZ7DPBI3.js} +3 -3
  4. package/dist/cdp-driver-CCG3OJUQ.js +49 -0
  5. package/dist/{cdp-driver-GCFEMRFJ.js → cdp-driver-HBMCD7NU.js} +2 -2
  6. package/dist/{cdp-driver-QOUSRPR2.js → cdp-driver-MJD7YIQI.js} +2 -2
  7. package/dist/{cdp-driver-4MNHDU2J.js → cdp-driver-YJU4GRSV.js} +196 -95
  8. package/dist/chunk-3SZTCI33.js +147 -0
  9. package/dist/{chunk-DZ6XEPAH.js → chunk-43U5VDLB.js} +8 -2
  10. package/dist/chunk-53VZHESL.js +150 -0
  11. package/dist/{chunk-NAIHOVDZ.js → chunk-63526WET.js} +2 -8
  12. package/dist/{chunk-YIL44YDX.js → chunk-6DS3T6UK.js} +196 -95
  13. package/dist/{chunk-N7DFS4V7.js → chunk-BLCBCESM.js} +8 -2
  14. package/dist/{chunk-SH6OTPXN.js → chunk-C5ZPXPD7.js} +31 -7
  15. package/dist/chunk-EGOWDZXP.js +149 -0
  16. package/dist/chunk-GNLZWHSP.js +1380 -0
  17. package/dist/{chunk-3E6VVMK2.js → chunk-GYGVHWG3.js} +272 -1460
  18. package/dist/{chunk-2KPI5GKP.js → chunk-IYCB2KJL.js} +2 -8
  19. package/dist/chunk-JYYKMSFH.js +39 -0
  20. package/dist/{chunk-TBJUSUKF.js → chunk-NBT2CE3H.js} +140 -96
  21. package/dist/{chunk-J4NOL5XX.js → chunk-QRFM4NOV.js} +1025 -202
  22. package/dist/chunk-RGL2YTWQ.js +64 -0
  23. package/dist/{chunk-BND5O5KC.js → chunk-SQLICOPZ.js} +177 -240
  24. package/dist/{chunk-O5PASNI7.js → chunk-UUW5EGES.js} +139 -237
  25. package/dist/{chunk-43TEMG4U.js → chunk-WGS3Y6ZV.js} +3 -1
  26. package/dist/{chunk-R57Z5KZX.js → chunk-Y2GRCINH.js} +1004 -183
  27. package/dist/{chunk-R7AG7ONI.js → chunk-ZCZELQCS.js} +196 -95
  28. package/dist/cli.js +2237 -278
  29. package/dist/{daemon-client-7D6EZNOE.js → daemon-client-OXKRGLPQ.js} +32 -8
  30. package/dist/{daemon-client-HEGAXWGK.js → daemon-client-Z3NKNZRL.js} +5 -1
  31. package/dist/daemon-main.js +2214 -159
  32. package/dist/human-interaction-BGAZC3JR.js +12 -0
  33. package/dist/human-interaction-TPKPEE7A.js +11 -0
  34. package/dist/human-interaction-ZSD3IX6Q.js +12 -0
  35. package/dist/index.d.ts +225 -94
  36. package/dist/index.js +2880 -267
  37. package/dist/{launcher-TOLF23ET.js → launcher-AUJK5QQM.js} +1 -1
  38. package/dist/{launcher-ZYB32LSZ.js → launcher-QBAZ6F5L.js} +1 -1
  39. package/dist/mistake-ledger-2B4N54CO.js +29 -0
  40. package/dist/{recovery-ORHJSBDN.js → recovery-5AGY7CV3.js} +4 -5
  41. package/dist/{recovery-JFGV3DBX.js → recovery-7NRRHLS4.js} +4 -4
  42. package/dist/{recovery-XDKN63O5.js → recovery-TIBRFGRP.js} +4 -4
  43. package/dist/run-routes-SJKVZ34L.js +26 -0
  44. package/dist/run-routes-TFNV5BBR.js +24 -0
  45. package/dist/{server-5U56MQD2.js → server-HUSX7EFE.js} +5 -4
  46. package/dist/{server-R4OYD7ZC.js → server-KSP5H4HD.js} +5 -3
  47. package/dist/{session-replayer-GHEFFNGV.js → session-replayer-4TCLQI76.js} +1 -1
  48. package/dist/viewer-routes-YOS5GTCV.js +11 -0
  49. package/package.json +1 -1
  50. package/dist/chunk-QCV2PI7U.js +0 -184
  51. package/dist/human-interaction-ISMMOJOK.js +0 -8
  52. package/dist/human-interaction-STTZZZ5N.js +0 -8
  53. package/dist/human-interaction-UXFYV7DU.js +0 -8
@@ -0,0 +1,149 @@
1
+ import {
2
+ executeChain
3
+ } from "./chunk-QRFM4NOV.js";
4
+ import {
5
+ outputEnvelope,
6
+ outputError
7
+ } from "./chunk-RGL2YTWQ.js";
8
+ import {
9
+ forwardManagedRun
10
+ } from "./chunk-C5ZPXPD7.js";
11
+ import {
12
+ errMsg
13
+ } from "./chunk-GDKLH7ZY.js";
14
+
15
+ // src/stdin.ts
16
+ import { readStdin, readCommandFile, splitFileLine } from "@dyyz1993/xcli-core";
17
+
18
+ // src/cli/run-routes.ts
19
+ import { readFileSync as readFileSync2 } from "fs";
20
+ import { z } from "zod/v4";
21
+
22
+ // src/browser/session-persistence.ts
23
+ import {
24
+ lstatSync,
25
+ existsSync,
26
+ mkdirSync,
27
+ readdirSync,
28
+ readFileSync,
29
+ renameSync,
30
+ unlinkSync,
31
+ writeFileSync
32
+ } from "fs";
33
+ import { homedir } from "os";
34
+ import { join } from "path";
35
+ import { randomUUID } from "crypto";
36
+ function sanitizeSessionName(name) {
37
+ if (!name || name === "." || name === "..") {
38
+ throw new Error(`Invalid session name "${name}": must be a non-empty file-safe name`);
39
+ }
40
+ if (name.length > 64) {
41
+ throw new Error(`Invalid session name: too long (max 64 chars, got ${name.length})`);
42
+ }
43
+ if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(name)) {
44
+ throw new Error(
45
+ `Invalid session name "${name}": only [A-Za-z0-9._-] allowed and it must start with an alphanumeric character`
46
+ );
47
+ }
48
+ return name;
49
+ }
50
+
51
+ // src/cli/run-routes.ts
52
+ var manifest = z.object({
53
+ jobs: z.array(z.object({
54
+ session: z.string(),
55
+ chain: z.string().trim().min(1)
56
+ })).min(1).max(100)
57
+ });
58
+ async function runNamedJobs(jobs, limit, run = forwardManagedRun) {
59
+ if (!Number.isInteger(limit) || limit < 1 || limit > 8) throw new Error("--parallel must be an integer from 1 to 8");
60
+ const names = jobs.map((job) => sanitizeSessionName(job.session));
61
+ if (new Set(names).size !== names.length) throw new Error("Each job must use a different session name");
62
+ const results = [];
63
+ let next = 0;
64
+ await Promise.all(Array.from({ length: Math.min(limit, jobs.length) }, async () => {
65
+ while (next < jobs.length) {
66
+ const index = next++;
67
+ const { session, chain } = jobs[index];
68
+ try {
69
+ const result = await run(chain, session);
70
+ results[index] = { session, success: result.success, result };
71
+ } catch (error) {
72
+ results[index] = { session, success: false, error: errMsg(error) };
73
+ }
74
+ }
75
+ }));
76
+ return results;
77
+ }
78
+ async function handleManagedRunFile(filePath, options) {
79
+ try {
80
+ if (filePath.endsWith(".json")) {
81
+ const { jobs } = manifest.parse(JSON.parse(readFileSync2(filePath, "utf8")));
82
+ const results = await runNamedJobs(jobs, options.parallel === void 0 ? 2 : Number(options.parallel));
83
+ const success = results.every((job) => job.success);
84
+ const failures = results.filter((job) => !job.success);
85
+ const message2 = failures.length ? `Jobs failed: ${failures.map((job) => job.session).join(", ")}` : void 0;
86
+ outputEnvelope({ success, data: { jobs: results }, message: message2 }, { command: "run" }, options.mode);
87
+ if (!success) process.exitCode = 1;
88
+ return;
89
+ }
90
+ if (options.parallel !== void 0) throw new Error("--parallel requires a JSON job manifest");
91
+ const commands = readCommandFile(filePath);
92
+ if (commands.length === 0) throw new Error("No commands found in file");
93
+ const session = sanitizeSessionName(options.sessionName);
94
+ const result = await forwardManagedRun(commands.join(" ; "), session, true);
95
+ const failed = result.steps.find((step) => !step.success);
96
+ const message = result.success ? void 0 : result.stoppedReason ?? failed?.message ?? "Run failed";
97
+ outputEnvelope({ success: result.success, data: result, message }, { command: "run", session }, options.mode);
98
+ if (!result.success) process.exitCode = 1;
99
+ } catch (error) {
100
+ outputEnvelope({ success: false, data: null, message: errMsg(error) }, { command: "run" }, options.mode);
101
+ process.exitCode = 1;
102
+ }
103
+ }
104
+ async function handleRun(filePath, options) {
105
+ let commands;
106
+ try {
107
+ commands = readCommandFile(filePath);
108
+ } catch (e) {
109
+ outputError(`Failed to read file '${filePath}': ${errMsg(e)}`);
110
+ return;
111
+ }
112
+ if (commands.length === 0) {
113
+ outputError("No commands found in file");
114
+ return;
115
+ }
116
+ const chain = commands.join(" ; ");
117
+ const chainResult = await executeChain(chain, {
118
+ cdpEndpoint: options?.cdpEndpoint,
119
+ sessionName: options?.sessionName,
120
+ fileMode: true
121
+ });
122
+ for (const step of chainResult.steps) {
123
+ if (step.success) {
124
+ process.stdout.write(`[OK] ${step.raw}
125
+ `);
126
+ if (step.data && typeof step.data === "object") {
127
+ const d = step.data;
128
+ for (const [k, v] of Object.entries(d)) {
129
+ if (k !== "ok")
130
+ process.stdout.write(` ${k}: ${typeof v === "string" ? v : JSON.stringify(v)}
131
+ `);
132
+ }
133
+ }
134
+ } else {
135
+ outputError(`[FAIL] ${step.raw}: ${step.message}`);
136
+ }
137
+ }
138
+ if (chainResult.stoppedReason) {
139
+ outputError(`Stopped: ${chainResult.stoppedReason}`);
140
+ }
141
+ if (!chainResult.success) process.exit(1);
142
+ }
143
+
144
+ export {
145
+ readStdin,
146
+ runNamedJobs,
147
+ handleManagedRunFile,
148
+ handleRun
149
+ };