@typhons/sandbox-tools 0.4.0 → 0.4.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.
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@typhons/sandbox-tools",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "sandbox-relay-client": "./relay-client.js",
7
7
  "sandbox-session-proxy": "./session-proxy.js",
8
- "sandbox-watchdog": "./sandbox-watchdog.js",
9
- "sandbox-start-all": "./sandbox-start-all.js",
8
+ "sandbox-watchdog": "./sandbox-watchdog.sh",
9
+ "sandbox-start-all": "./sandbox-start-all.sh",
10
10
  "check-claude-active": "./check-claude-active.js",
11
11
  "stop-agents": "./stop-agents.js",
12
12
  "sandbox-clone": "./clone.js"
@@ -0,0 +1,27 @@
1
+ #!/bin/bash
2
+ # Start all sandbox services: sshd + watchdog + keepalive.
3
+ # Called on sandbox boot/resume.
4
+
5
+ BIN="$(cd "$(dirname "$(readlink -f "$0")")" && pwd)"
6
+
7
+ # Start sshd
8
+ mkdir -p /run/sshd
9
+ if ! pgrep -x sshd > /dev/null 2>&1; then
10
+ /usr/sbin/sshd 2>/dev/null || true
11
+ echo "[start-all] sshd started on port 2222"
12
+ fi
13
+
14
+ # Kill stale processes from snapshot
15
+ pkill -9 -f session-proxy.js 2>/dev/null || true
16
+ pkill -9 -f relay-client.js 2>/dev/null || true
17
+ pkill -9 -f sandbox-watchdog 2>/dev/null || true
18
+ pkill -9 -f check-claude-active 2>/dev/null || true
19
+ sleep 1
20
+
21
+ # Start watchdog (manages both session-proxy and relay-client)
22
+ nohup bash "$BIN/sandbox-watchdog.sh" >> /tmp/ssh-relay.log 2>&1 &
23
+
24
+ # Start keepalive daemon
25
+ if ! pgrep -f "check-claude-active.*--daemon" > /dev/null 2>&1; then
26
+ nohup node "$BIN/check-claude-active.js" --daemon >> /tmp/claude-keepalive.log 2>&1 &
27
+ fi
@@ -0,0 +1,32 @@
1
+ #!/bin/bash
2
+ # Watchdog: keeps both session-proxy and relay-client running.
3
+
4
+ BIN="$(cd "$(dirname "$(readlink -f "$0")")" && pwd)"
5
+ export SSH_PORT="${SSH_PORT:-2222}"
6
+
7
+ log() { echo "[watchdog $(date +%H:%M:%S)] $*"; }
8
+
9
+ # Start session-proxy with auto-restart
10
+ (
11
+ while true; do
12
+ node "$BIN/session-proxy.js" 2>&1
13
+ EXIT_CODE=$?
14
+ log "session-proxy exited (code $EXIT_CODE), restarting in 2s..."
15
+ sleep 2
16
+ done
17
+ ) >> /tmp/session-proxy.log 2>&1 &
18
+ SESSION_PROXY_PID=$!
19
+ log "session-proxy watchdog started (pid $SESSION_PROXY_PID)"
20
+
21
+ # Relay-client watchdog
22
+ while true; do
23
+ node "$BIN/relay-client.js" 2>&1
24
+ EXIT_CODE=$?
25
+ if [ "$EXIT_CODE" = "42" ]; then
26
+ log "relay-client replaced by newer connection (exit 42), stopping all"
27
+ kill $SESSION_PROXY_PID 2>/dev/null
28
+ exit 0
29
+ fi
30
+ log "relay-client exited (code $EXIT_CODE), restarting in 2s..."
31
+ sleep 2
32
+ done
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- import{execSync as e,spawn as n}from"child_process";import{dirname as a,join as r}from"path";import{fileURLToPath as d}from"url";import c from"fs";var i=a(d(import.meta.url));function s(o){try{e(o,{stdio:"inherit"})}catch{}}try{e("pgrep -x sshd",{stdio:"ignore"})}catch{e("mkdir -p /run/sshd",{stdio:"ignore"}),s("/usr/sbin/sshd"),console.log("[start-all] sshd started on port 2222")}s("pkill -9 -f sandbox-session-proxy");s("pkill -9 -f sandbox-relay-client");s("pkill -9 -f sandbox-watchdog");e("sleep 1");var t=c.openSync("/tmp/ssh-relay.log","a");n(process.execPath,[r(i,"sandbox-watchdog.js")],{stdio:["ignore",t,t],detached:!0,env:process.env}).unref();try{e('pgrep -f "check-claude-active.*--daemon"',{stdio:"ignore"})}catch{let o=c.openSync("/tmp/claude-keepalive.log","a");n(process.execPath,[r(i,"check-claude-active.js"),"--daemon"],{stdio:["ignore",o,o],detached:!0,env:process.env}).unref()}
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- import{spawn as l}from"child_process";import{dirname as y,join as p}from"path";import{fileURLToPath as f}from"url";import c from"fs";var a=y(f(import.meta.url));process.env.SSH_PORT=process.env.SSH_PORT||"2222";function s(e){console.log(`[watchdog ${new Date().toISOString().slice(11,19)}] ${e}`)}function d(e,o,i,t){let n=c.openSync(i,"a");l(process.execPath,[o],{stdio:["ignore",n,n],env:process.env}).on("exit",r=>{c.closeSync(n),!(t&&t(r))&&(s(`${e} exited (code ${r}), restarting in 2s...`),setTimeout(()=>d(e,o,i,t),2e3))})}d("session-proxy",p(a,"session-proxy.js"),"/tmp/session-proxy.log");s("session-proxy watchdog started");function m(){l(process.execPath,[p(a,"relay-client.js")],{stdio:"inherit",env:process.env}).on("exit",o=>{o===42&&(s("relay-client replaced by newer connection (exit 42), stopping all"),process.exit(0)),s(`relay-client exited (code ${o}), restarting in 2s...`),setTimeout(m,2e3)})}m();