bridex-worker 0.1.3 → 0.1.4

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 (3) hide show
  1. package/README.md +9 -2
  2. package/dist/cli.js +47 -6
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -157,8 +157,15 @@ codex_transport: auto # exec
157
157
  needs `plan` and `cli:<preset>` for each provider its plan uses; install
158
158
  `loopai` and restart the worker to advertise it.
159
159
  - **Slots and load.** A grant is refused when every slot is taken, free memory
160
- or the cache disk is below the reserve (3 GB), or the load per core is
161
- above 1.5 — your own work on the machine comes first. Slots are shared by
160
+ is below 700 MB, the cache disk has less than 3 GB free, or the load per
161
+ core is above 1.5 — your own work on the machine comes first. Free memory
162
+ is what the system can hand a run now: on Linux the kernel's available
163
+ memory, within the cgroup's limit when there is one; on macOS the free,
164
+ speculative, inactive and purgeable pages from `vm_stat`, whatever Node
165
+ version runs the worker. If `vm_stat` cannot run, the worker falls back to
166
+ Node's own reading without a log line, and on Node 20 and 22 that leaves
167
+ out the inactive pages macOS reclaims on demand (mostly file cache), so a
168
+ busy Mac shows a few hundred MB. Slots are shared by
162
169
  every instance served: each sees the machine's free slots, capped by its
163
170
  `max_slots`.
164
171
  - **Cache.** `repos/` bare clones, `work/` one checkout per task, `templates/`
package/dist/cli.js CHANGED
@@ -6300,6 +6300,7 @@ import path23 from "path";
6300
6300
  import WebSocket from "ws";
6301
6301
 
6302
6302
  // src/admission.ts
6303
+ import { execFileSync as execFileSync3 } from "child_process";
6303
6304
  import fs15 from "fs";
6304
6305
  import os5 from "os";
6305
6306
  import path12 from "path";
@@ -6391,12 +6392,52 @@ var AUTO_SLOTS_MIN = 2;
6391
6392
  var AUTO_SLOTS_MAX = 8;
6392
6393
  var MAX_LOAD_PER_CORE = 1.5;
6393
6394
  var DISK_RESERVE_BYTES = 3 * GB4;
6394
- function availableMemory() {
6395
- const linux = freeMemoryBytes();
6396
- if (linux !== null) return linux;
6395
+ function parseVmStat(text) {
6396
+ const header = /\(page size of (\d+) bytes\)/.exec(text.split(/\r?\n/, 1)[0] ?? "");
6397
+ if (!header) return null;
6398
+ const pageSize = Number(header[1]);
6399
+ if (!Number.isSafeInteger(pageSize) || pageSize <= 0) return null;
6400
+ const count2 = (name, absent) => {
6401
+ const raw = new RegExp(`^${name}:(.*)$`, "m").exec(text)?.[1];
6402
+ if (raw === void 0) return absent;
6403
+ const m = /^(\d+)\.?$/.exec(raw.trim());
6404
+ return m ? Number(m[1]) : null;
6405
+ };
6406
+ let pages = 0;
6407
+ for (const n of [count2("Pages free", null), count2("Pages inactive", null), count2("Pages speculative", 0), count2("Pages purgeable", 0)]) {
6408
+ if (n === null) return null;
6409
+ pages += n;
6410
+ }
6411
+ const bytes = pages * pageSize;
6412
+ return Number.isSafeInteger(bytes) ? bytes : null;
6413
+ }
6414
+ function readVmStat() {
6415
+ try {
6416
+ return execFileSync3("/usr/bin/vm_stat", { encoding: "utf8", timeout: 2e3, stdio: ["ignore", "pipe", "ignore"] });
6417
+ } catch {
6418
+ return null;
6419
+ }
6420
+ }
6421
+ function availableMemory({ platform = process.platform, vmStat = readVmStat, linux = freeMemoryBytes } = {}) {
6422
+ if (platform === "darwin") {
6423
+ const mac = vmStatBytes(vmStat);
6424
+ if (mac !== null) return Math.min(mac, os5.totalmem());
6425
+ } else {
6426
+ const kernel = linux();
6427
+ if (kernel !== null) return kernel;
6428
+ }
6397
6429
  const avail = process.availableMemory?.();
6398
6430
  return typeof avail === "number" && avail > 0 ? avail : os5.freemem();
6399
6431
  }
6432
+ function vmStatBytes(vmStat) {
6433
+ try {
6434
+ const text = vmStat();
6435
+ const bytes = text === null ? null : parseVmStat(text);
6436
+ return bytes !== null && bytes > 0 ? bytes : null;
6437
+ } catch {
6438
+ return null;
6439
+ }
6440
+ }
6400
6441
  function existingAncestor(dir) {
6401
6442
  let d = path12.resolve(dir);
6402
6443
  while (!fs15.existsSync(d)) {
@@ -7139,7 +7180,7 @@ async function runSdkEngine(grant, ctx) {
7139
7180
  }
7140
7181
 
7141
7182
  // src/jobs.ts
7142
- import { execFileSync as execFileSync3, spawn as nodeSpawn3 } from "child_process";
7183
+ import { execFileSync as execFileSync4, spawn as nodeSpawn3 } from "child_process";
7143
7184
  import fs19 from "fs";
7144
7185
  import path16 from "path";
7145
7186
  var NO_SUCH_JOB = "(this machine has no such job any more)";
@@ -7164,7 +7205,7 @@ function commandLineOf(pid, opts = {}) {
7164
7205
  }
7165
7206
  }
7166
7207
  try {
7167
- const out = execFileSync3(opts.ps ?? "ps", ["-ww", "-o", "command=", "-p", String(pid)], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 5e3 });
7208
+ const out = execFileSync4(opts.ps ?? "ps", ["-ww", "-o", "command=", "-p", String(pid)], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 5e3 });
7168
7209
  return out.trim() || null;
7169
7210
  } catch (err) {
7170
7211
  return err.status === 1 ? null : void 0;
@@ -8725,7 +8766,7 @@ function execStep(bin, args, o) {
8725
8766
  }
8726
8767
 
8727
8768
  // src/version.ts
8728
- var VERSION = "0.1.3";
8769
+ var VERSION = "0.1.4";
8729
8770
 
8730
8771
  // src/update.ts
8731
8772
  import { spawn as spawn5 } from "child_process";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bridex-worker",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Key your own machine into a Bridex instance as a worker: the instance schedules heavy runs onto it (a warm clone cache, a worktree per run, the task branch pushed back), with every credential issued per run.",
5
5
  "license": "MIT",
6
6
  "type": "module",