glidercli 0.4.13 → 0.4.15

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.
@@ -85,7 +85,7 @@ function loadBrowserConfig(options = {}) {
85
85
  }
86
86
 
87
87
  function isBrowserInternalUrl(url) {
88
- return /^(?:about|arc|brave|chrome|chrome-extension|edge|opera|vivaldi):/i.test(String(url || ''));
88
+ return /^(?:about|arc|brave|chrome|chrome-extension|edge|helium|opera|vivaldi):/i.test(String(url || ''));
89
89
  }
90
90
 
91
91
  module.exports = {
@@ -5,7 +5,7 @@
5
5
  SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
6
6
  DAEMON_PATH="$SCRIPT_DIR/glider-daemon.sh"
7
7
  BSERVE="$SCRIPT_DIR/bserve.js"
8
- LOG_DIR="${GLIDER_HOME:-$HOME/.glider}"
8
+ LOG_DIR="${GLIDER:-$HOME/.glider}"
9
9
  PORT="${GLIDER_PORT:-${RELAY_PORT:-19988}}"
10
10
 
11
11
  case "$PORT" in
@@ -34,6 +34,7 @@ PID_FILE="$LOG_DIR/daemon-$PORT.pid"
34
34
  CLAIM_DIR="$LOG_DIR/daemon-$PORT.claim"
35
35
  MANAGEMENT_LOCK="$LOG_DIR/daemon-$PORT.management.lock"
36
36
  MAX_LOG_SIZE=10485760
37
+ CLAIM_ORPHAN_GRACE_SECONDS=5
37
38
  child_pid=""
38
39
  child_started=""
39
40
  relay_ready=0
@@ -271,18 +272,69 @@ relay_owned_by_child() {
271
272
  ' "$PORT" "$child_pid"
272
273
  }
273
274
 
274
- acquire_claim() {
275
- if mkdir "$CLAIM_DIR" 2>/dev/null; then
276
- printf '%s\n' "$claim_token" > "$CLAIM_DIR/owner"
277
- claim_owned=1
278
- return 0
275
+ claim_owner_pid() {
276
+ # The owner token is "PID-RANDOM-EPOCH"; the leading field is the supervisor PID.
277
+ owner_raw="$(cat "$CLAIM_DIR/owner" 2>/dev/null)" || return 1
278
+ owner_pid="${owner_raw%%-*}"
279
+ case "$owner_pid" in
280
+ ''|*[!0-9]*) return 1 ;;
281
+ esac
282
+ printf '%s' "$owner_pid"
283
+ }
284
+
285
+ claim_age_seconds() {
286
+ "$NODE_BIN" -e '
287
+ try {
288
+ const ms = Date.now() - require("fs").statSync(process.argv[1]).mtimeMs;
289
+ process.stdout.write(String(Math.floor(ms / 1000)));
290
+ } catch { process.exit(1); }
291
+ ' "$CLAIM_DIR"
292
+ }
293
+
294
+ claim_is_orphaned() {
295
+ # Only a tombstone left by a dead supervisor may be reaped. All must hold:
296
+ # 1. no live supervisor matches the pid record,
297
+ # 2. the claim owner PID is dead; an unreadable owner (a supervisor between
298
+ # mkdir and writing its token) counts only after a grace period,
299
+ # 3. nothing is answering on the relay port.
300
+ record_matches_supervisor >/dev/null 2>&1 && return 1
301
+ if owner_pid="$(claim_owner_pid)"; then
302
+ kill -0 "$owner_pid" 2>/dev/null && return 1
303
+ else
304
+ age="$(claim_age_seconds)" || return 1
305
+ [ "$age" -ge "$CLAIM_ORPHAN_GRACE_SECONDS" ] || return 1
306
+ fi
307
+ relay_is_running && return 1
308
+ return 0
309
+ }
310
+
311
+ reap_orphaned_claim() {
312
+ echo "glider-daemon: reaping orphaned supervisor claim: $CLAIM_DIR" >&2
313
+ rm -f "$CLAIM_DIR/owner" 2>/dev/null || true
314
+ rmdir "$CLAIM_DIR" 2>/dev/null || true
315
+ if [ -f "$PID_FILE" ] && ! record_matches_supervisor >/dev/null 2>&1; then
316
+ rm -f "$PID_FILE"
279
317
  fi
318
+ }
319
+
320
+ try_take_claim() {
321
+ mkdir "$CLAIM_DIR" 2>/dev/null || return 1
322
+ printf '%s\n' "$claim_token" > "$CLAIM_DIR/owner"
323
+ claim_owned=1
324
+ }
325
+
326
+ acquire_claim() {
327
+ try_take_claim && return 0
280
328
  i=0
281
329
  while [ "$i" -lt 20 ]; do
282
330
  existing_pid="$(record_matches_supervisor 2>/dev/null)" && {
283
331
  echo "glider-daemon: already running as PID $existing_pid on port $PORT" >&2
284
332
  exit 0
285
333
  }
334
+ if claim_is_orphaned; then
335
+ reap_orphaned_claim
336
+ fi
337
+ try_take_claim && return 0
286
338
  sleep 0.1
287
339
  i=$((i + 1))
288
340
  done
@@ -324,6 +376,81 @@ if [ -f "$PID_FILE" ]; then
324
376
  }
325
377
  fi
326
378
 
379
+ # Auto-heal: reclaim :PORT when a stale bserve.js holds it (wrong install path / orphan).
380
+ # Foreign non-bserve listeners still fail hard (no blind kill).
381
+ reclaim_stale_bserve_if_needed() {
382
+ local pid cmd our
383
+ our="$(cd "$(dirname "$BSERVE")" && /bin/pwd)/$(basename "$BSERVE")"
384
+ if ! relay_is_running; then
385
+ # port may be held without /status (half-dead); still inspect listeners
386
+ :
387
+ fi
388
+ for pid in $(/usr/sbin/lsof -nP -iTCP:"$PORT" -sTCP:LISTEN -t 2>/dev/null); do
389
+ cmd="$(/bin/ps -p "$pid" -o command= 2>/dev/null || true)"
390
+ case "$cmd" in
391
+ *bserve.js*)
392
+ case "$cmd" in
393
+ *"$our"*|*"$BSERVE"*)
394
+ if relay_owned_by_pid "$pid"; then
395
+ echo "glider-daemon: canonical relay already up as PID $pid on port $PORT" >&2
396
+ exit 0
397
+ fi
398
+ ;;
399
+ esac
400
+ # wrong install path, or canonical path but /status broken → reclaim
401
+ echo "glider-daemon: reclaiming stale bserve PID $pid on port $PORT" >&2
402
+ echo "glider-daemon: was: $cmd" >&2
403
+ /bin/kill "$pid" 2>/dev/null || true
404
+ i=0
405
+ while [ "$i" -lt 50 ]; do
406
+ /bin/kill -0 "$pid" 2>/dev/null || break
407
+ sleep 0.1
408
+ i=$((i + 1))
409
+ done
410
+ /bin/kill -9 "$pid" 2>/dev/null || true
411
+ ;;
412
+ "")
413
+ ;;
414
+ *)
415
+ echo "glider-daemon: relay port $PORT owned by foreign process PID $pid: $cmd" >&2
416
+ exit 1
417
+ ;;
418
+ esac
419
+ done
420
+ }
421
+
422
+ relay_owned_by_pid() {
423
+ "$NODE_BIN" -e '
424
+ const http = require("http");
425
+ const [portValue, expectedPid] = process.argv.slice(1);
426
+ const request = http.get(
427
+ { host: "127.0.0.1", port: Number(portValue), path: "/status", timeout: 500 },
428
+ (response) => {
429
+ let raw = "";
430
+ response.on("data", (chunk) => { raw += chunk; });
431
+ response.on("end", () => {
432
+ try {
433
+ const status = JSON.parse(raw);
434
+ process.exit(
435
+ response.statusCode >= 200
436
+ && response.statusCode < 300
437
+ && status.pid === Number(expectedPid)
438
+ ? 0
439
+ : 1,
440
+ );
441
+ } catch {
442
+ process.exit(1);
443
+ }
444
+ });
445
+ },
446
+ );
447
+ request.on("error", () => process.exit(1));
448
+ request.on("timeout", () => request.destroy());
449
+ ' "$PORT" "$1"
450
+ }
451
+
452
+ reclaim_stale_bserve_if_needed
453
+
327
454
  if relay_is_running; then
328
455
  echo "glider-daemon: relay port $PORT is already owned by another process" >&2
329
456
  exit 1
package/lib/paths.js CHANGED
@@ -3,9 +3,9 @@
3
3
  const os = require('os');
4
4
  const path = require('path');
5
5
 
6
- /** Browser runtime data - always ~/.glider unless GLIDER_HOME set. */
6
+ /** Runtime data: $GLIDER, else $HOME/.glider. */
7
7
  function gliderHome() {
8
- return process.env.GLIDER_HOME || path.join(os.homedir(), '.glider');
8
+ return process.env.GLIDER || path.join(os.homedir(), '.glider');
9
9
  }
10
10
 
11
11
  /** Installed package root (glidercli npm tree). */
@@ -13,15 +13,13 @@ function packageRoot() {
13
13
  return path.join(__dirname, '..');
14
14
  }
15
15
 
16
- /** Registry base for warch: AGREGISTRY or GLIDER_HOME. */
16
+ /** Registry base for warch: $GLIDER. */
17
17
  function registryBase() {
18
- const ag = process.env.AGREGISTRY;
19
- if (ag) return expandUser(ag);
20
18
  return gliderHome();
21
19
  }
22
20
 
23
21
  function registryMode() {
24
- return process.env.AGREGISTRY ? 'agents' : 'standalone';
22
+ return 'standalone';
25
23
  }
26
24
 
27
25
  function configPath(name) {
@@ -32,7 +30,7 @@ function configPath(name) {
32
30
  ];
33
31
  }
34
32
 
35
- /** Domain intel: AGREGISTRY/warch or ~/.glider/warch when AGREGISTRY unset. */
33
+ /** Domain intel: $GLIDER/warch. */
36
34
  function warchRoot() {
37
35
  return path.join(registryBase(), 'warch');
38
36
  }
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- /** CDP pin machine. SSOT: operator $CURREGISTRY/glider/cdp-target-shape.json */
3
+ /** CDP pin machine: page targets only (never iframe/worker). */
4
4
  const PAGE = 'page';
5
5
  const IFRAME = 'iframe';
6
6
  const NEVER = new Set([IFRAME, 'worker', 'service_worker', 'shared_worker', 'browser']);
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "glidercli",
3
- "version": "0.4.13",
3
+ "version": "0.4.15",
4
4
  "description": "Browser automation CLI. Control a configured Chromium browser through an extension CDP relay, run YAML tasks, and execute bounded autonomous loops.",
5
5
  "bin": {
6
6
  "glider": "bin/glider.js"
7
7
  },
8
8
  "scripts": {
9
9
  "test": "node --test tests/*.test.js",
10
- "test:syntax": "node --check bin/glider.js && node --check lib/bserve.js",
10
+ "test:syntax": "node --check bin/glider.js && node --check lib/bserve.js && node --check lib/bexplore.js",
11
11
  "test:regression": "node --test tests/browser-config.test.js tests/core.test.js tests/cli-regression.test.js tests/relay-integration.test.js",
12
12
  "test:integration": "node --test tests/relay-integration.test.js tests/daemon-lifecycle.test.js",
13
13
  "test:pack": "node --test tests/npm-tarball.test.js",
14
14
  "test:smoke": "node tests/live-browser.smoke.js",
15
15
  "test:live": "node tests/live-browser.smoke.js",
16
- "prepublishOnly": "npm run test:syntax && npm test"
16
+ "prepublishOnly": "node --check bin/glider.js && node --check lib/bserve.js && node --test tests/*.test.js"
17
17
  },
18
18
  "keywords": [
19
19
  "browser",