omowright 0.3.1 → 0.3.2

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.
@@ -1,3 +1,5 @@
1
+ export declare const BSK_CLI_VERSION = "0.5.0";
2
+ export declare const BSK_PINNED_MANIFEST_URL = "https://github.com/Tencent/BrowserSkill/releases/download/cli-v0.5.0/version.json";
1
3
  export type InstallEnv = Record<string, string | undefined>;
2
4
  export interface InstallCommand {
3
5
  command: string;
package/dist/index.js CHANGED
@@ -69,6 +69,7 @@ var require_constants = __commonJS(function(exports, module) {
69
69
 
70
70
  // node_modules/ws/lib/buffer-util.js
71
71
  var require_buffer_util = __commonJS(function(exports, module) {
72
+ var { websocketMask, websocketUnmask } = __require("http");
72
73
  var { EMPTY_BUFFER } = require_constants();
73
74
  var FastBuffer = Buffer[Symbol.species];
74
75
  function concat(list, totalLength) {
@@ -126,7 +127,20 @@ var require_buffer_util = __commonJS(function(exports, module) {
126
127
  toBuffer,
127
128
  unmask: _unmask
128
129
  };
129
- if (!process.env.WS_NO_BUFFER_UTIL) {
130
+ if (websocketMask) {
131
+ module.exports.mask = function(source, mask, output, offset, length) {
132
+ if (length < 24)
133
+ _mask(source, mask, output, offset, length);
134
+ else
135
+ websocketMask(source, mask, output, offset, length);
136
+ };
137
+ module.exports.unmask = function(buffer, mask) {
138
+ if (buffer.length < 24)
139
+ _unmask(buffer, mask);
140
+ else
141
+ websocketUnmask(buffer, mask);
142
+ };
143
+ } else if (!process.env.WS_NO_BUFFER_UTIL) {
130
144
  try {
131
145
  const bufferUtil = (()=>{throw new Error("Cannot require module "+"bufferutil");})();
132
146
  module.exports.mask = function(source, mask2, output, offset, length) {
@@ -878,6 +892,7 @@ var require_receiver = __commonJS(function(exports, module) {
878
892
  unmask(data, this._mask);
879
893
  }
880
894
  }
895
+ this._mask = undefined;
881
896
  if (this._opcode > 7) {
882
897
  this.controlMessage(data, cb);
883
898
  return;
@@ -1114,13 +1129,16 @@ var require_sender = __commonJS(function(exports, module) {
1114
1129
  target[2] = target[3] = 0;
1115
1130
  target.writeUIntBE(dataLength, 4, 6);
1116
1131
  }
1117
- if (!options.mask)
1118
- return [target, data];
1132
+ if (!options.mask) {
1133
+ return dataLength ? [target, data] : [target];
1134
+ }
1119
1135
  target[1] |= 128;
1120
1136
  target[offset - 4] = mask[0];
1121
1137
  target[offset - 3] = mask[1];
1122
1138
  target[offset - 2] = mask[2];
1123
1139
  target[offset - 1] = mask[3];
1140
+ if (!dataLength)
1141
+ return [target];
1124
1142
  if (skipMasking)
1125
1143
  return [target, data];
1126
1144
  if (merge) {
@@ -1703,6 +1721,7 @@ var require_websocket = __commonJS(function(exports, module) {
1703
1721
  var https = __require("https");
1704
1722
  var http = __require("http");
1705
1723
  var net = __require("net");
1724
+ var querystring = __require("querystring");
1706
1725
  var tls = __require("tls");
1707
1726
  var { randomBytes, createHash } = __require("crypto");
1708
1727
  var { Duplex, Readable } = __require("stream");
@@ -1754,21 +1773,38 @@ var require_websocket = __commonJS(function(exports, module) {
1754
1773
  this._isServer = false;
1755
1774
  this._redirects = 0;
1756
1775
  if (protocols === undefined) {
1757
- protocols = [];
1776
+ if (!options || options.protocols === undefined) {
1777
+ protocols = [];
1778
+ } else if (Array.isArray(options.protocols)) {
1779
+ protocols = options.protocols;
1780
+ } else {
1781
+ protocols = [options.protocols];
1782
+ }
1758
1783
  } else if (!Array.isArray(protocols)) {
1759
1784
  if (typeof protocols === "object" && protocols !== null) {
1760
1785
  options = protocols;
1761
- protocols = [];
1786
+ if (options.protocols === undefined) {
1787
+ protocols = [];
1788
+ } else if (Array.isArray(options.protocols)) {
1789
+ protocols = options.protocols;
1790
+ } else {
1791
+ protocols = [options.protocols];
1792
+ }
1762
1793
  } else {
1763
1794
  protocols = [protocols];
1764
1795
  }
1765
1796
  }
1766
- initAsClient(this, address, protocols, options);
1797
+ options = initAsClient(this, address, protocols, options);
1767
1798
  } else {
1768
- this._autoPong = options.autoPong;
1769
- this._closeTimeout = options.closeTimeout;
1770
1799
  this._isServer = true;
1771
1800
  }
1801
+ if (options.autoPong) {
1802
+ this._autoPong = true;
1803
+ this._autoPongComplete = () => autoPongComplete(this);
1804
+ this._pendingAutoPongs = 0;
1805
+ this._maxPendingAutoPongs = options.maxPendingAutoPongs | 0;
1806
+ }
1807
+ this._closeTimeout = options.closeTimeout;
1772
1808
  }
1773
1809
  get binaryType() {
1774
1810
  return this._binaryType;
@@ -1877,7 +1913,6 @@ var require_websocket = __commonJS(function(exports, module) {
1877
1913
  }
1878
1914
  return;
1879
1915
  }
1880
- this._readyState = WebSocket.CLOSING;
1881
1916
  this._sender.close(code, data, !this._isServer, (err) => {
1882
1917
  if (err)
1883
1918
  return;
@@ -1886,6 +1921,7 @@ var require_websocket = __commonJS(function(exports, module) {
1886
1921
  this._socket.end();
1887
1922
  }
1888
1923
  });
1924
+ this._readyState = WebSocket.CLOSING;
1889
1925
  setCloseTimer(this);
1890
1926
  }
1891
1927
  pause() {
@@ -2065,6 +2101,7 @@ var require_websocket = __commonJS(function(exports, module) {
2065
2101
  maxBufferedChunks: 256 * 1024,
2066
2102
  maxFragments: 16 * 1024,
2067
2103
  maxPayload: 100 * 1024 * 1024,
2104
+ maxPendingAutoPongs: 60,
2068
2105
  skipUTF8Validation: false,
2069
2106
  perMessageDeflate: true,
2070
2107
  followRedirects: false,
@@ -2073,14 +2110,13 @@ var require_websocket = __commonJS(function(exports, module) {
2073
2110
  socketPath: undefined,
2074
2111
  hostname: undefined,
2075
2112
  protocol: undefined,
2113
+ protocols: undefined,
2076
2114
  timeout: undefined,
2077
2115
  method: "GET",
2078
2116
  host: undefined,
2079
2117
  path: undefined,
2080
2118
  port: undefined
2081
2119
  };
2082
- websocket._autoPong = opts.autoPong;
2083
- websocket._closeTimeout = opts.closeTimeout;
2084
2120
  if (!protocolVersions.includes(opts.protocolVersion)) {
2085
2121
  throw new RangeError(`Unsupported protocol version: ${opts.protocolVersion} ` + `(supported versions: ${protocolVersions.join(", ")})`);
2086
2122
  }
@@ -2094,10 +2130,9 @@ var require_websocket = __commonJS(function(exports, module) {
2094
2130
  throw new SyntaxError(`Invalid URL: ${address}`);
2095
2131
  }
2096
2132
  }
2097
- if (parsedUrl.protocol === "http:") {
2098
- parsedUrl.protocol = "ws:";
2099
- } else if (parsedUrl.protocol === "https:") {
2100
- parsedUrl.protocol = "wss:";
2133
+ if (parsedUrl.protocol === "http:" || parsedUrl.protocol === "https:") {
2134
+ parsedUrl = new URL2(parsedUrl);
2135
+ parsedUrl.protocol = parsedUrl.protocol === "http:" ? "ws:" : "wss:";
2101
2136
  }
2102
2137
  websocket._url = parsedUrl.href;
2103
2138
  const isSecure = parsedUrl.protocol === "wss:";
@@ -2164,12 +2199,19 @@ var require_websocket = __commonJS(function(exports, module) {
2164
2199
  }
2165
2200
  }
2166
2201
  if (parsedUrl.username || parsedUrl.password) {
2167
- opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
2202
+ const username = querystring.unescape(parsedUrl.username);
2203
+ const password = querystring.unescape(parsedUrl.password);
2204
+ opts.auth = `${username}:${password}`;
2168
2205
  }
2169
2206
  if (isIpcUrl) {
2170
- const parts = opts.path.split(":");
2171
- opts.socketPath = parts[0];
2172
- opts.path = parts[1];
2207
+ const i = opts.path.indexOf(":");
2208
+ if (i === -1) {
2209
+ opts.socketPath = opts.path;
2210
+ opts.path = "";
2211
+ } else {
2212
+ opts.socketPath = opts.path.slice(0, i);
2213
+ opts.path = opts.path.slice(i + 1);
2214
+ }
2173
2215
  }
2174
2216
  let req;
2175
2217
  if (opts.followRedirects) {
@@ -2313,6 +2355,7 @@ var require_websocket = __commonJS(function(exports, module) {
2313
2355
  } else {
2314
2356
  req.end();
2315
2357
  }
2358
+ return opts;
2316
2359
  }
2317
2360
  function emitErrorAndClose(websocket, err) {
2318
2361
  websocket._readyState = WebSocket.CLOSING;
@@ -2364,8 +2407,13 @@ var require_websocket = __commonJS(function(exports, module) {
2364
2407
  function receiverOnConclude(code, reason) {
2365
2408
  const websocket = this[kWebSocket];
2366
2409
  websocket._closeFrameReceived = true;
2367
- websocket._closeMessage = reason;
2368
2410
  websocket._closeCode = code;
2411
+ if (reason.length === 0) {
2412
+ websocket._closeMessage = EMPTY_BUFFER;
2413
+ } else {
2414
+ websocket._closeMessage = Buffer.allocUnsafeSlow(reason.length);
2415
+ websocket._closeMessage.set(reason);
2416
+ }
2369
2417
  if (websocket._socket[kWebSocket] === undefined)
2370
2418
  return;
2371
2419
  websocket._socket.removeListener("data", socketOnData);
@@ -2400,10 +2448,19 @@ var require_websocket = __commonJS(function(exports, module) {
2400
2448
  }
2401
2449
  function receiverOnPing(data) {
2402
2450
  const websocket = this[kWebSocket];
2403
- if (websocket._autoPong)
2404
- websocket.pong(data, !this._isServer, NOOP);
2451
+ if (websocket._autoPong && websocket.readyState === WebSocket.OPEN) {
2452
+ if (websocket._maxPendingAutoPongs > 0 && websocket._pendingAutoPongs >= websocket._maxPendingAutoPongs) {
2453
+ websocket.terminate();
2454
+ } else {
2455
+ websocket._pendingAutoPongs++;
2456
+ websocket.pong(data, !this._isServer, websocket._autoPongComplete);
2457
+ }
2458
+ }
2405
2459
  websocket.emit("ping", data);
2406
2460
  }
2461
+ function autoPongComplete(websocket) {
2462
+ websocket._pendingAutoPongs--;
2463
+ }
2407
2464
  function receiverOnPong(data) {
2408
2465
  this[kWebSocket].emit("pong", data);
2409
2466
  }
@@ -2642,6 +2699,7 @@ var require_websocket_server = __commonJS(function(exports, module) {
2642
2699
  maxBufferedChunks: 256 * 1024,
2643
2700
  maxFragments: 16 * 1024,
2644
2701
  maxPayload: 100 * 1024 * 1024,
2702
+ maxPendingAutoPongs: 60,
2645
2703
  skipUTF8Validation: false,
2646
2704
  perMessageDeflate: false,
2647
2705
  handleProtocols: null,
@@ -31414,6 +31472,7 @@ class PipeCdpClient {
31414
31472
  #malformedFrameCount = 0;
31415
31473
  #events = new SerialEmitter;
31416
31474
  #connected = false;
31475
+ #closedByCaller = false;
31417
31476
  #commandTimeoutMs;
31418
31477
  #readinessTimeoutMs;
31419
31478
  #browserPath;
@@ -31459,6 +31518,7 @@ class PipeCdpClient {
31459
31518
  this.#dialogPolicy = normalizeDialogPolicy(policy);
31460
31519
  }
31461
31520
  async ensureConnected() {
31521
+ this.#closedByCaller = false;
31462
31522
  if (this.#connected)
31463
31523
  return;
31464
31524
  const stdio = ["ignore", "pipe", "pipe", "pipe", "pipe"];
@@ -31621,6 +31681,15 @@ ${tail}` : ""));
31621
31681
  if (String(method).startsWith("OmO.")) {
31622
31682
  throw Error(`Extension commands are unavailable over pipe transport: ${method}`);
31623
31683
  }
31684
+ if (this.#closedByCaller) {
31685
+ throw this.#commandError(CdpPipeClosedError, "CDP pipe client closed", {
31686
+ method,
31687
+ sessionId,
31688
+ targetId: this.#sessionTargets.get(sessionId),
31689
+ sentAt: performance.now(),
31690
+ receivedBytes: this.#receivedBytes
31691
+ });
31692
+ }
31624
31693
  await this.ensureConnected();
31625
31694
  return this.#dispatch(method, params, sessionId, opts);
31626
31695
  }
@@ -31679,6 +31748,7 @@ ${tail}` : ""));
31679
31748
  this.#failCommands(CdpSessionDetachedError, "Page closed", sessionId);
31680
31749
  }
31681
31750
  async close() {
31751
+ this.#closedByCaller = true;
31682
31752
  const child = this.#child;
31683
31753
  this.#child = undefined;
31684
31754
  if (child && child.exitCode === null) {
@@ -31686,7 +31756,7 @@ ${tail}` : ""));
31686
31756
  let quitRequested = false;
31687
31757
  if (this.#connected) {
31688
31758
  await Promise.race([
31689
- this.send("Browser.close", undefined, undefined, {
31759
+ this.#dispatch("Browser.close", undefined, undefined, {
31690
31760
  timeoutMs: GRACEFUL_CLOSE_TIMEOUT_MS
31691
31761
  }).then(() => {
31692
31762
  quitRequested = true;
@@ -34493,9 +34563,10 @@ var systemBinary = (...segments) => {
34493
34563
  throw new Error(`${file} is missing`);
34494
34564
  return file;
34495
34565
  };
34566
+ var RUN_TIMEOUT_MS = 60000;
34496
34567
  function run(file, args) {
34497
34568
  return new Promise((resolve, reject) => {
34498
- execFile3(file, args, { timeout: 15000, windowsHide: true, maxBuffer: 4 * 1024 * 1024, encoding: "utf8" }, (error, stdout, stderr) => {
34569
+ execFile3(file, args, { timeout: RUN_TIMEOUT_MS, windowsHide: true, maxBuffer: 4 * 1024 * 1024, encoding: "utf8" }, (error, stdout, stderr) => {
34499
34570
  if (error && (typeof error.code !== "number" || error.killed))
34500
34571
  reject(error);
34501
34572
  else
@@ -35594,7 +35665,7 @@ async function snapshotWithFrames(page, opts = {}) {
35594
35665
  // package.json
35595
35666
  var package_default = {
35596
35667
  name: "omowright",
35597
- version: "0.3.1",
35668
+ version: "0.3.2",
35598
35669
  description: "OmOWright browser automation for standard Chromium CDP endpoints.",
35599
35670
  keywords: [
35600
35671
  "accessibility-snapshot",
@@ -35640,35 +35711,38 @@ var package_default = {
35640
35711
  provenance: true
35641
35712
  },
35642
35713
  scripts: {
35643
- test: "bun test",
35714
+ test: "bun test --parallel",
35644
35715
  "test:node": "bun scripts/node-test.ts",
35645
35716
  "test:cloak-profile": "bun test test/cloak-profile.test.ts test/cloak-profile.integration.test.ts",
35646
- typecheck: "tsc --noEmit -p tsconfig.json",
35717
+ typecheck: "bun check --no-script --no-pretty -p tsconfig.json",
35647
35718
  "typecheck:control": "bun scripts/typecheck-control.ts",
35648
35719
  check: "bun run typecheck:control && bun run typecheck && bun run lint && bun run fmt:check",
35649
- lint: "oxlint --deny-warnings src bin bridge test scripts",
35720
+ lint: "oxlint --deny-warnings src bin bridge test scripts && bun scripts/lint-ratchet.ts",
35721
+ "lint:ratchet:update": "bun scripts/lint-ratchet.ts --update",
35650
35722
  "lint:fix": "oxlint --fix src bin bridge test scripts",
35651
- fmt: "oxfmt --write src bin bridge test scripts",
35652
- "fmt:check": "oxfmt --check src bin bridge test scripts",
35723
+ fmt: "bun fmt --no-script --write src bin bridge test scripts",
35724
+ "fmt:check": "bun fmt --no-script --check src bin bridge test scripts",
35653
35725
  format: "bun run fmt",
35654
35726
  "format:check": "bun run fmt:check",
35655
35727
  verify: "bun run check",
35728
+ "check:push": "bun run check && bun run build && git diff --exit-code HEAD --",
35729
+ prepare: "husky",
35656
35730
  build: "bun build.ts",
35657
35731
  "build:extension": "bun bridge/build-extension.ts",
35658
35732
  prepack: "bun run build",
35659
35733
  preversion: "git diff --quiet HEAD --"
35660
35734
  },
35661
35735
  dependencies: {
35662
- ws: "^8.18.3",
35663
- zod: "^4.6.6"
35736
+ ws: "^8.23.0",
35737
+ zod: "^4.6.7"
35664
35738
  },
35665
35739
  devDependencies: {
35666
- "@types/bun": "1.4.4",
35667
- acorn: "8.15.0",
35668
- "gpt-tokenizer": "4.1.0",
35669
- oxfmt: "^0.77.0",
35670
- oxlint: "^1.92.0",
35671
- typescript: "^7.0.2",
35740
+ "@types/bun": "1.4.5",
35741
+ acorn: "8.19.0",
35742
+ "gpt-tokenizer": "4.1.2",
35743
+ husky: "9.1.7",
35744
+ "oxc-parser": "0.159.0",
35745
+ oxlint: "^1.94.0",
35672
35746
  "typescript-5": "npm:typescript@5.9.3"
35673
35747
  },
35674
35748
  engines: {
@@ -36515,16 +36589,130 @@ function createTrace(page, options = {}) {
36515
36589
  }
36516
36590
  // src/bsk/ipc-client.ts
36517
36591
  import { connect as connect2 } from "node:net";
36518
- import { existsSync as existsSync5, readdirSync } from "node:fs";
36519
- import path19 from "node:path";
36592
+ import { existsSync as existsSync6, readdirSync } from "node:fs";
36593
+ import path20 from "node:path";
36520
36594
  import { randomBytes } from "node:crypto";
36521
36595
 
36522
36596
  // src/bsk/daemon-info.ts
36523
- import { existsSync as existsSync4, readFileSync as readFileSync4 } from "node:fs";
36597
+ import { existsSync as existsSync5, readFileSync as readFileSync5 } from "node:fs";
36598
+ import { homedir as homedir4 } from "node:os";
36599
+ import path19 from "node:path";
36600
+ import { spawn as spawn7 } from "node:child_process";
36601
+ import { createHash as createHash2 } from "node:crypto";
36602
+
36603
+ // src/bsk/install-cli.ts
36604
+ import { existsSync as existsSync4, readFileSync as readFileSync4, rmSync as rmSync3, writeFileSync as writeFileSync3 } from "node:fs";
36524
36605
  import { homedir as homedir3 } from "node:os";
36525
36606
  import path18 from "node:path";
36526
36607
  import { spawn as spawn6 } from "node:child_process";
36527
- import { createHash as createHash2 } from "node:crypto";
36608
+ var BSK_CLI_VERSION = "0.5.0";
36609
+ var RELEASE_TAG = `cli-v${BSK_CLI_VERSION}`;
36610
+ var INSTALL_SH = `https://raw.githubusercontent.com/Tencent/BrowserSkill/${RELEASE_TAG}/install.sh`;
36611
+ var INSTALL_PS1 = `https://raw.githubusercontent.com/Tencent/BrowserSkill/${RELEASE_TAG}/install.ps1`;
36612
+ var BSK_PINNED_MANIFEST_URL = `https://github.com/Tencent/BrowserSkill/releases/download/${RELEASE_TAG}/version.json`;
36613
+ var RC_FILES = [".zshrc", ".bashrc", ".profile"];
36614
+ function windowsPowerShellEnv(env) {
36615
+ const key = Object.keys(process.env).find((name) => name.toUpperCase() === "PSMODULEPATH");
36616
+ if (!key)
36617
+ return env;
36618
+ const value = process.env[key];
36619
+ if (value === undefined)
36620
+ throw new TypeError(`${key} has no value`);
36621
+ const kept = value.split(";").filter((entry) => entry && !/[\\/]PowerShell[\\/]/i.test(entry));
36622
+ return { ...env, [key]: kept.length > 0 ? kept.join(";") : undefined };
36623
+ }
36624
+ function cliInstallCommand({
36625
+ platform = process.platform,
36626
+ installDir,
36627
+ version = BSK_CLI_VERSION
36628
+ } = {}) {
36629
+ const env = { BSK_INSTALL_DIR: installDir, BSK_VERSION: version };
36630
+ if (platform === "win32") {
36631
+ return {
36632
+ command: windowsSystemTool("WindowsPowerShell\\v1.0\\powershell.exe"),
36633
+ args: ["-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", `irm ${INSTALL_PS1} | iex`],
36634
+ env: windowsPowerShellEnv(env)
36635
+ };
36636
+ }
36637
+ return { command: "sh", args: ["-c", `curl -fsSL ${INSTALL_SH} | sh`], env };
36638
+ }
36639
+ function runDefault(command, args, env) {
36640
+ return new Promise((resolve) => {
36641
+ const child = spawn6(command, args, {
36642
+ env: { ...process.env, ...env },
36643
+ stdio: ["ignore", "pipe", "pipe"],
36644
+ windowsHide: true
36645
+ });
36646
+ let stdout = "", stderr = "";
36647
+ child.stdout.on("data", (c) => {
36648
+ stdout = (stdout + c).slice(-8192);
36649
+ });
36650
+ child.stderr.on("data", (c) => {
36651
+ stderr = (stderr + c).slice(-8192);
36652
+ });
36653
+ child.on("error", (error) => resolve({ code: -1, stdout, stderr: error.message }));
36654
+ child.on("exit", (code) => resolve({ code, stdout, stderr }));
36655
+ });
36656
+ }
36657
+ function snapshotRcFiles(home) {
36658
+ const snapshot = new Map;
36659
+ for (const name of RC_FILES) {
36660
+ const file = path18.join(home, name);
36661
+ snapshot.set(file, existsSync4(file) ? readFileSync4(file) : null);
36662
+ }
36663
+ return snapshot;
36664
+ }
36665
+ function restoreRcFiles(snapshot) {
36666
+ const restored = [];
36667
+ for (const [file, before] of snapshot) {
36668
+ const after = existsSync4(file) ? readFileSync4(file) : null;
36669
+ if (before === null && after === null)
36670
+ continue;
36671
+ if (before !== null && after !== null && before.equals(after))
36672
+ continue;
36673
+ if (before === null)
36674
+ rmSync3(file, { force: true });
36675
+ else
36676
+ writeFileSync3(file, before);
36677
+ restored.push(file);
36678
+ }
36679
+ return restored;
36680
+ }
36681
+ async function installBskCli({
36682
+ platform = process.platform,
36683
+ home = homedir3(),
36684
+ installDir = path18.join(home, ".local", "bin"),
36685
+ version,
36686
+ run = runDefault
36687
+ } = {}) {
36688
+ const spec = cliInstallCommand({ platform, installDir, version });
36689
+ const rcBefore = platform === "win32" ? new Map : snapshotRcFiles(home);
36690
+ const result = await run(spec.command, spec.args, spec.env);
36691
+ const restoredRcFiles = restoreRcFiles(rcBefore);
36692
+ const bskBin = path18.join(installDir, platform === "win32" ? "bsk.exe" : "bsk");
36693
+ const installed = result.code === 0 && existsSync4(bskBin);
36694
+ return {
36695
+ installed,
36696
+ bskBin: installed ? bskBin : null,
36697
+ code: result.code,
36698
+ stdout: result.stdout,
36699
+ stderr: result.stderr,
36700
+ restoredRcFiles
36701
+ };
36702
+ }
36703
+ function cliVersionDefault(bskBin) {
36704
+ return new Promise((resolve) => {
36705
+ const child = spawn6(bskBin, ["--version"], { stdio: ["ignore", "pipe", "ignore"], windowsHide: true });
36706
+ let out = "";
36707
+ child.stdout.on("data", (c) => {
36708
+ out += c;
36709
+ });
36710
+ child.on("error", () => resolve(null));
36711
+ child.on("exit", (code) => resolve(code === 0 ? out.trim() : null));
36712
+ });
36713
+ }
36714
+
36715
+ // src/bsk/daemon-info.ts
36528
36716
  function isDaemonInfo(value) {
36529
36717
  if (!value || typeof value !== "object" || !("sock_path" in value))
36530
36718
  return false;
@@ -36534,16 +36722,16 @@ function resolveBskHome(env = process.env) {
36534
36722
  const override = env["BSK_HOME"];
36535
36723
  if (typeof override === "string" && override.length > 0)
36536
36724
  return override;
36537
- const home = env["HOME"] && env["HOME"].length > 0 ? env["HOME"] : homedir3();
36538
- return path18.join(home, ".bsk");
36725
+ const home = env["HOME"] && env["HOME"].length > 0 ? env["HOME"] : homedir4();
36726
+ return path19.join(home, ".bsk");
36539
36727
  }
36540
36728
  function daemonInfoPath(home) {
36541
- return path18.join(home, "daemon.json");
36729
+ return path19.join(home, "daemon.json");
36542
36730
  }
36543
36731
  function readDaemonInfo(home) {
36544
36732
  let raw;
36545
36733
  try {
36546
- raw = readFileSync4(daemonInfoPath(home), "utf8");
36734
+ raw = readFileSync5(daemonInfoPath(home), "utf8");
36547
36735
  } catch {
36548
36736
  return null;
36549
36737
  }
@@ -36558,27 +36746,37 @@ function readDaemonInfo(home) {
36558
36746
  return info;
36559
36747
  }
36560
36748
  function findBskBinary(env = process.env) {
36561
- const home = env["HOME"] && env["HOME"].length > 0 ? env["HOME"] : homedir3();
36749
+ const home = env["HOME"] && env["HOME"].length > 0 ? env["HOME"] : homedir4();
36562
36750
  const candidates = [
36563
36751
  env["BSK_BIN"],
36564
- path18.join(home, ".local", "bin", process.platform === "win32" ? "bsk.exe" : "bsk")
36752
+ path19.join(home, ".local", "bin", process.platform === "win32" ? "bsk.exe" : "bsk")
36565
36753
  ].filter((candidate) => Boolean(candidate));
36566
36754
  for (const candidate of candidates)
36567
- if (existsSync4(candidate))
36755
+ if (existsSync5(candidate))
36568
36756
  return candidate;
36569
36757
  return "bsk";
36570
36758
  }
36571
36759
  var NO_BREAKAWAY = /Job Object/;
36572
36760
  function windowsDaemonTaskName(home) {
36573
- return `bsk-daemon-${createHash2("sha256").update(path18.resolve(home).toLowerCase()).digest("hex").slice(0, 12)}`;
36761
+ return `bsk-daemon-${createHash2("sha256").update(path19.resolve(home).toLowerCase()).digest("hex").slice(0, 12)}`;
36574
36762
  }
36575
36763
  var powershellLiteral = (value) => `'${value.replace(/['\u2018\u2019\u201A\u201B]/g, (quote) => quote + quote)}'`;
36576
- function windowsDaemonLaunch(home, bskBin) {
36577
- const script = `$env:BSK_HOME = ${powershellLiteral(home)}; & ${powershellLiteral(bskBin)} daemon start --foreground; exit $LASTEXITCODE`;
36764
+ function daemonEnv(env, home) {
36765
+ return {
36766
+ ...env,
36767
+ BSK_HOME: home,
36768
+ BSK_AUTO_UPDATE: env["BSK_AUTO_UPDATE"] ?? "off",
36769
+ BSK_UPDATE_MANIFEST_URL: env["BSK_UPDATE_MANIFEST_URL"] ?? BSK_PINNED_MANIFEST_URL
36770
+ };
36771
+ }
36772
+ function windowsDaemonLaunch(env, bskBin) {
36773
+ const assignments = ["BSK_HOME", "BSK_AUTO_UPDATE", "BSK_UPDATE_MANIFEST_URL"].map((name) => `$env:${name} = ${powershellLiteral(env[name] ?? "")}; `).join("");
36774
+ const script = `${assignments}& ${powershellLiteral(bskBin)} daemon start --foreground; exit $LASTEXITCODE`;
36578
36775
  return `--headless "${windowsSystemTool("WindowsPowerShell\\v1.0\\powershell.exe")}" -NoProfile -NonInteractive -EncodedCommand ${Buffer.from(script, "utf16le").toString("base64")}`;
36579
36776
  }
36580
36777
  function startDaemonInWindowsTask({
36581
36778
  home,
36779
+ env,
36582
36780
  bskBin,
36583
36781
  timeoutMs
36584
36782
  }) {
@@ -36592,7 +36790,7 @@ function startDaemonInWindowsTask({
36592
36790
  env: {
36593
36791
  ...process.env,
36594
36792
  BSK_TASK_NAME: windowsDaemonTaskName(home),
36595
- BSK_TASK_ARGUMENT: windowsDaemonLaunch(home, bskBin)
36793
+ BSK_TASK_ARGUMENT: windowsDaemonLaunch(env, bskBin)
36596
36794
  },
36597
36795
  timeoutMs,
36598
36796
  label: "registering the bsk daemon task"
@@ -36600,7 +36798,7 @@ function startDaemonInWindowsTask({
36600
36798
  }
36601
36799
  function runToExit(command, args, { env, timeoutMs, label }) {
36602
36800
  return new Promise((resolve, reject) => {
36603
- const child = spawn6(command, args, { env, stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
36801
+ const child = spawn7(command, args, { env, stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
36604
36802
  let output = "";
36605
36803
  const keep = (chunk) => {
36606
36804
  output = (output + chunk).slice(-4096);
@@ -36627,8 +36825,9 @@ async function startDaemonWithCli({
36627
36825
  bskBin = findBskBinary(env),
36628
36826
  timeoutMs = 20000
36629
36827
  } = {}) {
36828
+ const daemon = daemonEnv(env, home);
36630
36829
  const status = await runToExit(bskBin, ["status", "--json"], {
36631
- env: { ...env, BSK_HOME: home },
36830
+ env: daemon,
36632
36831
  timeoutMs,
36633
36832
  label: "bsk status"
36634
36833
  });
@@ -36637,7 +36836,7 @@ async function startDaemonWithCli({
36637
36836
  if (process.platform === "win32" && NO_BREAKAWAY.test(status.output)) {
36638
36837
  if (home === undefined)
36639
36838
  throw new TypeError("startDaemonWithCli needs a home to register the Windows daemon task");
36640
- const task = await startDaemonInWindowsTask({ home, bskBin, timeoutMs });
36839
+ const task = await startDaemonInWindowsTask({ home, env: daemon, bskBin, timeoutMs });
36641
36840
  if (task.code === 0)
36642
36841
  return;
36643
36842
  throw new Error(`${status.output}; registering the bsk daemon task exited with ${task.code}${task.output ? `: ${task.output}` : ""}`);
@@ -36672,7 +36871,7 @@ function ownBudgetMs(params) {
36672
36871
  var PROBE_TIMEOUT_MS = 2000;
36673
36872
  function defaultSocketPath(home, env = process.env) {
36674
36873
  if (process.platform !== "win32")
36675
- return path19.join(home, "run", "daemon.sock");
36874
+ return path20.join(home, "run", "daemon.sock");
36676
36875
  return `\\\\.\\pipe\\bsk-daemon-${rustStrHash(env["USERNAME"] ?? "default", home)}`;
36677
36876
  }
36678
36877
  function rustStrHash(...values) {
@@ -36712,9 +36911,9 @@ function rustStrHash(...values) {
36712
36911
  }
36713
36912
  function socketExists(sockPath) {
36714
36913
  if (process.platform !== "win32")
36715
- return existsSync5(sockPath);
36914
+ return existsSync6(sockPath);
36716
36915
  try {
36717
- return readdirSync("\\\\.\\pipe\\").includes(path19.win32.basename(sockPath));
36916
+ return readdirSync("\\\\.\\pipe\\").includes(path20.win32.basename(sockPath));
36718
36917
  } catch {
36719
36918
  return false;
36720
36919
  }
@@ -37336,7 +37535,7 @@ function isTabGroupingExtension(browser) {
37336
37535
  }
37337
37536
  var TAB_GROUPING_EXTENSION_STEP = `Update the BrowserSkill extension to 0.4.1 or later (chrome://extensions -> Developer mode -> Update, or wait for the store update). Version 0.4.0 puts each task's tabs into a "BrowserSkill" tab group that the browser saves and syncs, so the group stays after the task ends; delete any saved "BrowserSkill" tab groups by hand.`;
37338
37537
  function outdatedError(browser) {
37339
- return new BskRpcError("extension_outdated", `the BrowserSkill extension in ${readProperty(browser, "browser_name") ?? "the browser"} [${readProperty(browser, "instance_id")}] is 0.4.0, which leaves a "BrowserSkill" tab group behind in the user's browser after each task. ${TAB_GROUPING_EXTENSION_STEP}`);
37538
+ return new BskRpcError("extension_outdated", `the BrowserSkill extension in ${textField(browser, "browser_name") ?? "the browser"} [${textField(browser, "instance_id") ?? "unknown id"}] is 0.4.0, which leaves a "BrowserSkill" tab group behind in the user's browser after each task. ${TAB_GROUPING_EXTENSION_STEP}`);
37340
37539
  }
37341
37540
  function namesBrowser(b, browser) {
37342
37541
  return readProperty(b, "instance_id") === browser || Boolean(readProperty(b, "label") && readProperty(b, "label") === browser);
@@ -37370,19 +37569,26 @@ function resolveBrowser(browser, browsers) {
37370
37569
  return browser;
37371
37570
  const named = browsers.filter((b) => readProperty(b, "browser_name") === browser);
37372
37571
  if (named.length > 1) {
37373
- throw new BskRpcError("invalid_params", `browser "${browser}" matches ${named.length} connected browsers (${named.map((b) => readProperty(b, "instance_id")).join(", ")}); pass the instance id instead`);
37572
+ throw new BskRpcError("invalid_params", `browser "${browser}" matches ${named.length} connected browsers (${named.map((b) => textField(b, "instance_id") ?? "unknown id").join(", ")}); pass the instance id instead`);
37374
37573
  }
37375
37574
  return named.length === 1 ? readProperty(named[0], "instance_id") : browser;
37376
37575
  }
37576
+ function textField(b, key) {
37577
+ const value = optionalProperty(b, key);
37578
+ if (typeof value === "string")
37579
+ return value;
37580
+ if (typeof value === "number" && Number.isFinite(value))
37581
+ return String(value);
37582
+ return;
37583
+ }
37377
37584
  function describeBrowser(b) {
37378
- const name = optionalProperty(b, "browser_name");
37379
- const label = optionalProperty(b, "label");
37585
+ const name = textField(b, "browser_name");
37380
37586
  const parts = [
37381
- `${String(label || name || "browser")} [${String(optionalProperty(b, "instance_id"))}]`,
37382
- [name, optionalProperty(b, "browser_version")].filter(Boolean).join(" ")
37587
+ `${textField(b, "label") || name || "browser"} [${textField(b, "instance_id") ?? "unknown id"}]`,
37588
+ [name, textField(b, "browser_version")].filter(Boolean).join(" ")
37383
37589
  ];
37384
37590
  const sessions = optionalProperty(b, "session_count");
37385
- if (typeof sessions === "number")
37591
+ if (typeof sessions === "number" && Number.isFinite(sessions))
37386
37592
  parts.push(`${sessions} session${sessions === 1 ? "" : "s"}`);
37387
37593
  const since = optionalProperty(b, "connected_at_ms");
37388
37594
  if (typeof since === "number" && Number.isFinite(since) && Math.abs(since) <= 8640000000000000) {
@@ -37896,117 +38102,6 @@ import { homedir as homedir6 } from "node:os";
37896
38102
  import path22 from "node:path";
37897
38103
  import { spawn as spawn8 } from "node:child_process";
37898
38104
 
37899
- // src/bsk/install-cli.ts
37900
- import { existsSync as existsSync6, readFileSync as readFileSync5, rmSync as rmSync3, writeFileSync as writeFileSync3 } from "node:fs";
37901
- import { homedir as homedir4 } from "node:os";
37902
- import path20 from "node:path";
37903
- import { spawn as spawn7 } from "node:child_process";
37904
- var INSTALL_SH = "https://raw.githubusercontent.com/Tencent/BrowserSkill/main/install.sh";
37905
- var INSTALL_PS1 = "https://raw.githubusercontent.com/Tencent/BrowserSkill/main/install.ps1";
37906
- var RC_FILES = [".zshrc", ".bashrc", ".profile"];
37907
- function windowsPowerShellEnv(env) {
37908
- const key = Object.keys(process.env).find((name) => name.toUpperCase() === "PSMODULEPATH");
37909
- if (!key)
37910
- return env;
37911
- const value = process.env[key];
37912
- if (value === undefined)
37913
- throw new TypeError(`${key} has no value`);
37914
- const kept = value.split(";").filter((entry) => entry && !/[\\/]PowerShell[\\/]/i.test(entry));
37915
- return { ...env, [key]: kept.length > 0 ? kept.join(";") : undefined };
37916
- }
37917
- function cliInstallCommand({
37918
- platform = process.platform,
37919
- installDir,
37920
- version
37921
- } = {}) {
37922
- const env = { BSK_INSTALL_DIR: installDir };
37923
- if (version)
37924
- env["BSK_VERSION"] = version;
37925
- if (platform === "win32") {
37926
- return {
37927
- command: windowsSystemTool("WindowsPowerShell\\v1.0\\powershell.exe"),
37928
- args: ["-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", `irm ${INSTALL_PS1} | iex`],
37929
- env: windowsPowerShellEnv(env)
37930
- };
37931
- }
37932
- return { command: "sh", args: ["-c", `curl -fsSL ${INSTALL_SH} | sh`], env };
37933
- }
37934
- function runDefault(command, args, env) {
37935
- return new Promise((resolve) => {
37936
- const child = spawn7(command, args, {
37937
- env: { ...process.env, ...env },
37938
- stdio: ["ignore", "pipe", "pipe"],
37939
- windowsHide: true
37940
- });
37941
- let stdout = "", stderr = "";
37942
- child.stdout.on("data", (c) => {
37943
- stdout = (stdout + c).slice(-8192);
37944
- });
37945
- child.stderr.on("data", (c) => {
37946
- stderr = (stderr + c).slice(-8192);
37947
- });
37948
- child.on("error", (error) => resolve({ code: -1, stdout, stderr: error.message }));
37949
- child.on("exit", (code) => resolve({ code, stdout, stderr }));
37950
- });
37951
- }
37952
- function snapshotRcFiles(home) {
37953
- const snapshot = new Map;
37954
- for (const name of RC_FILES) {
37955
- const file = path20.join(home, name);
37956
- snapshot.set(file, existsSync6(file) ? readFileSync5(file) : null);
37957
- }
37958
- return snapshot;
37959
- }
37960
- function restoreRcFiles(snapshot) {
37961
- const restored = [];
37962
- for (const [file, before] of snapshot) {
37963
- const after = existsSync6(file) ? readFileSync5(file) : null;
37964
- if (before === null && after === null)
37965
- continue;
37966
- if (before !== null && after !== null && before.equals(after))
37967
- continue;
37968
- if (before === null)
37969
- rmSync3(file, { force: true });
37970
- else
37971
- writeFileSync3(file, before);
37972
- restored.push(file);
37973
- }
37974
- return restored;
37975
- }
37976
- async function installBskCli({
37977
- platform = process.platform,
37978
- home = homedir4(),
37979
- installDir = path20.join(home, ".local", "bin"),
37980
- version,
37981
- run = runDefault
37982
- } = {}) {
37983
- const spec = cliInstallCommand({ platform, installDir, version });
37984
- const rcBefore = platform === "win32" ? new Map : snapshotRcFiles(home);
37985
- const result = await run(spec.command, spec.args, spec.env);
37986
- const restoredRcFiles = restoreRcFiles(rcBefore);
37987
- const bskBin = path20.join(installDir, platform === "win32" ? "bsk.exe" : "bsk");
37988
- const installed = result.code === 0 && existsSync6(bskBin);
37989
- return {
37990
- installed,
37991
- bskBin: installed ? bskBin : null,
37992
- code: result.code,
37993
- stdout: result.stdout,
37994
- stderr: result.stderr,
37995
- restoredRcFiles
37996
- };
37997
- }
37998
- function cliVersionDefault(bskBin) {
37999
- return new Promise((resolve) => {
38000
- const child = spawn7(bskBin, ["--version"], { stdio: ["ignore", "pipe", "ignore"], windowsHide: true });
38001
- let out = "";
38002
- child.stdout.on("data", (c) => {
38003
- out += c;
38004
- });
38005
- child.on("error", () => resolve(null));
38006
- child.on("exit", (code) => resolve(code === 0 ? out.trim() : null));
38007
- });
38008
- }
38009
-
38010
38105
  // src/aside/cli-binary.ts
38011
38106
  import { existsSync as existsSync7 } from "node:fs";
38012
38107
  import { homedir as homedir5 } from "node:os";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omowright",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "OmOWright browser automation for standard Chromium CDP endpoints.",
5
5
  "keywords": [
6
6
  "accessibility-snapshot",
@@ -46,35 +46,38 @@
46
46
  "provenance": true
47
47
  },
48
48
  "scripts": {
49
- "test": "bun test",
49
+ "test": "bun test --parallel",
50
50
  "test:node": "bun scripts/node-test.ts",
51
51
  "test:cloak-profile": "bun test test/cloak-profile.test.ts test/cloak-profile.integration.test.ts",
52
- "typecheck": "tsc --noEmit -p tsconfig.json",
52
+ "typecheck": "bun check --no-script --no-pretty -p tsconfig.json",
53
53
  "typecheck:control": "bun scripts/typecheck-control.ts",
54
54
  "check": "bun run typecheck:control && bun run typecheck && bun run lint && bun run fmt:check",
55
- "lint": "oxlint --deny-warnings src bin bridge test scripts",
55
+ "lint": "oxlint --deny-warnings src bin bridge test scripts && bun scripts/lint-ratchet.ts",
56
+ "lint:ratchet:update": "bun scripts/lint-ratchet.ts --update",
56
57
  "lint:fix": "oxlint --fix src bin bridge test scripts",
57
- "fmt": "oxfmt --write src bin bridge test scripts",
58
- "fmt:check": "oxfmt --check src bin bridge test scripts",
58
+ "fmt": "bun fmt --no-script --write src bin bridge test scripts",
59
+ "fmt:check": "bun fmt --no-script --check src bin bridge test scripts",
59
60
  "format": "bun run fmt",
60
61
  "format:check": "bun run fmt:check",
61
62
  "verify": "bun run check",
63
+ "check:push": "bun run check && bun run build && git diff --exit-code HEAD --",
64
+ "prepare": "husky",
62
65
  "build": "bun build.ts",
63
66
  "build:extension": "bun bridge/build-extension.ts",
64
67
  "prepack": "bun run build",
65
68
  "preversion": "git diff --quiet HEAD --"
66
69
  },
67
70
  "dependencies": {
68
- "ws": "^8.18.3",
69
- "zod": "^4.6.6"
71
+ "ws": "^8.23.0",
72
+ "zod": "^4.6.7"
70
73
  },
71
74
  "devDependencies": {
72
- "@types/bun": "1.4.4",
73
- "acorn": "8.15.0",
74
- "gpt-tokenizer": "4.1.0",
75
- "oxfmt": "^0.77.0",
76
- "oxlint": "^1.92.0",
77
- "typescript": "^7.0.2",
75
+ "@types/bun": "1.4.5",
76
+ "acorn": "8.19.0",
77
+ "gpt-tokenizer": "4.1.2",
78
+ "husky": "9.1.7",
79
+ "oxc-parser": "0.159.0",
80
+ "oxlint": "^1.94.0",
78
81
  "typescript-5": "npm:typescript@5.9.3"
79
82
  },
80
83
  "engines": {