dsh-dot-life 0.23.0 → 0.23.1

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/README.en.md CHANGED
@@ -124,9 +124,9 @@ flowchart LR
124
124
  ## ⌨️ Commands
125
125
 
126
126
  ```text
127
- /phone [accept|restart|screenshot]
127
+ /phone [doctor|accept|restart|screenshot]
128
128
  /interlude [now|advance|seed|preset <code>|canon]
129
- /dot [test|check|doctor]
129
+ /dot [test|check|doctor|prompts [stop]]
130
130
  /dot memory [now|diary|handoff|recall …]
131
131
  /dot people [approve <id>|drop <id>|forget <name>]
132
132
  /qq [install|account|start|qr|backend|owner]
package/README.md CHANGED
@@ -204,7 +204,7 @@ flowchart LR
204
204
  ## ⌨️ 命令与文件
205
205
 
206
206
  ```text
207
- /phone [accept|restart|screenshot]
207
+ /phone [doctor|accept|restart|screenshot]
208
208
  /interlude [now|advance|seed|preset <code>|canon]
209
209
  /dot [test|check|doctor|prompts [stop]]
210
210
  /dot memory [now|diary|handoff|recall …]
package/docs/computer.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  Give [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) (dsh) its own computer: a persistent Linux microVM with a browser, a live desktop view, and approval gates. No Docker required.
8
8
 
9
- ![dsh-computer demo](docs/demo.gif)
9
+ ![dsh-computer demo](demo.gif)
10
10
 
11
11
  *The agent runs commands and opens a page inside its own VM; the Computer panel in dsh shows its desktop live. (Recorded with a scripted model.)*
12
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-dot-life",
3
- "version": "0.23.0",
3
+ "version": "0.23.1",
4
4
  "description": "dot — a character who lives on her own phone, for DeepSeek Harness (dsh): an Android phone the plugin installs and runs, her own QQ, memory and a diary from real events, a life between conversations (幕间), an optional microVM computer with approval gates. One plugin, seven components; lives next to qq-bridge.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -51,7 +51,7 @@
51
51
  "files": [
52
52
  "src",
53
53
  "lib",
54
- "scripts",
54
+ "scripts/prompts.mjs",
55
55
  "examples",
56
56
  "cordis.patch.yml",
57
57
  "README.md",
@@ -8,7 +8,6 @@ import { join, dirname, resolve } from 'node:path';
8
8
  import { tmpdir } from 'node:os';
9
9
  import { fileURLToPath } from 'node:url';
10
10
 
11
- const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
12
11
  // dsh's own packages are peer dependencies: present where the plugin runs, usually absent in a bare
13
12
  // source checkout. The prompts never need them, so a missing one is replaced by a stub.
14
13
  {
@@ -9,7 +9,6 @@ import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'n
9
9
  import { homedir } from 'node:os';
10
10
  import { dirname, join } from 'node:path';
11
11
 
12
- export const KEY_ENV = 'SANDBOX_API_KEY';
13
12
  /** Header the image documents for the key; it leaves `Authorization` free for the proxied service. */
14
13
  export const KEY_HEADER = 'X-AIO-API-Key';
15
14
 
@@ -117,7 +117,6 @@ export const defaults = {
117
117
  imTarget: '',
118
118
  };
119
119
 
120
- const dshHome = () => process.env.DSH_HOME || join(homedir(), '.dsh');
121
120
  /** dsh-im tags messages it relays with an rpcId of `<channel>-<uuid>`; the desktop UI does not. */
122
121
  export const IM_RPC = /^(weixin|wechat|qq|feishu|lark|dingtalk|wecom|wework|telegram|discord|slack|whatsapp|email|office)-/i;
123
122
  export const isImMessage = (m) => IM_RPC.test(String(m?.source?.rpcId ?? ''));
@@ -25,7 +25,7 @@
25
25
  // off.
26
26
  // Passwords and keys never reach the index, the cloud, or her prompt (store.js's filter).
27
27
  import { spawn } from 'node:child_process';
28
- import { appendFileSync, chmodSync, existsSync, mkdirSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
28
+ import { appendFileSync, chmodSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
29
29
  import { createRequire } from 'node:module';
30
30
  import { homedir } from 'node:os';
31
31
  import { dirname, join } from 'node:path';
@@ -46,19 +46,6 @@ export function jaccard(a, b) {
46
46
  return inter / (A.size + B.size - inter);
47
47
  }
48
48
 
49
- /**
50
- * Character-bigram Jaccard: looser than the 3-gram one, for "is this the same fact said again"
51
- * about one person (Chinese paraphrases share bigrams far more than trigrams).
52
- */
53
- export function similar2(a, b) {
54
- const grams = (t) => { const s = normText(t); const out = new Set(); for (let i = 0; i + 2 <= s.length; i++) out.add(s.slice(i, i + 2)); if (s.length < 2 && s) out.add(s); return out; };
55
- const A = grams(a), B = grams(b);
56
- if (!A.size || !B.size) return 0;
57
- let inter = 0;
58
- for (const g of A) if (B.has(g)) inter++;
59
- return inter / (A.size + B.size - inter);
60
- }
61
-
62
49
  /** Chinese runs ~1.4–1.6 characters per token; estimate conservatively. */
63
50
  export const estimateTokens = (text) => Math.ceil(String(text ?? '').length / 1.5);
64
51
 
@@ -146,9 +133,6 @@ export function handleOf(platform, { uid = '', name = '' } = {}) {
146
133
  const n = String(name ?? '').trim();
147
134
  return n ? `${p}:name:${n}` : '';
148
135
  }
149
- /** Kept for callers that still build "<platform>:name:<x>" handles directly. */
150
- export const personId = (platform, handle) => `${String(platform ?? '').trim().toLowerCase() || 'unknown'}:${String(handle ?? '').trim()}`;
151
-
152
136
  const platformOf = (handle) => String(handle).split(':')[0];
153
137
  const nameOfHandle = (handle) => { const m = /^[^:]+:name:(.+)$/.exec(String(handle)); return m ? m[1] : ''; };
154
138
 
package/src/settings.js CHANGED
@@ -9,8 +9,6 @@ import { copyFileSync, existsSync, mkdirSync, readFileSync, renameSync, writeFil
9
9
  import { homedir } from 'node:os';
10
10
  import { dirname, join } from 'node:path';
11
11
 
12
- export const SECTIONS = ['phone', 'computer', 'gate', 'qq', 'memory', 'interlude', 'dot', 'compat'];
13
-
14
12
  export const dshHome = () => process.env.DSH_HOME || join(homedir(), '.dsh');
15
13
  export const settingsPath = () => join(dshHome(), 'dsh-dot.json');
16
14
 
@@ -1,73 +0,0 @@
1
- #!/usr/bin/env bash
2
- # dsh-computer: second-stage macOS check. msb `create` boots its own agent as PID 1 and does not run
3
- # the image ENTRYPOINT, so the AIO services (supervisord, Chrome, nginx, VNC, MCP) are started here
4
- # as a runtime-owned job with `msb exec -d`. Also re-tests port forwarding with a detached server.
5
- # bash check-mac-aio.sh
6
- set -u
7
- HERE="$(cd "$(dirname "$0")" && pwd)"
8
- LOG="$HERE/dsh-computer-aio.log"
9
- exec > >(tee "$LOG") 2>&1
10
-
11
- IMAGE="${IMAGE:-ghcr.io/agent-infra/sandbox:latest}"
12
- PORT="${PORT:-18080}"
13
- WORK="${TMPDIR:-/tmp}/dsh-computer-check"
14
- MSB="$(find "$WORK/node_modules" -type f -name msb -perm -u+x 2>/dev/null | head -1)"
15
- [ -n "$MSB" ] || { echo "msb not found; run check-mac.sh first"; exit 1; }
16
- SHARED="$HOME/dsh-computer-check-share"; mkdir -p "$SHARED"; echo hello-from-mac > "$SHARED/from-host.txt"
17
-
18
- declare -a RES
19
- step() { local tag; if [ "$2" = 1 ]; then tag=PASS; printf '\033[32m'; else tag=FAIL; printf '\033[31m'; fi
20
- printf '[%s] %s %s\033[0m\n' "$tag" "$1" "${3:-}"; RES+=("$(printf '%-34s %s' "$1" "$tag")"); }
21
- code() { curl -s -o /dev/null -w '%{http_code}' --noproxy '*' --max-time 5 "$1" 2>/dev/null || echo 000; }
22
- waitfor() { local i=0; while [ $i -lt "$2" ]; do [ "$(code "$1")" = 200 ] && return 0; sleep 2; i=$((i+2)); done; return 1; }
23
- secs() { echo $(( $(date +%s) - $1 )); }
24
- X() { "$MSB" exec "$N" --no-tty "$@" 2>&1; }
25
-
26
- echo "== Port forward with a detached server (alpine)"
27
- S=dsh-computer-smoke; SP=$((PORT+1))
28
- "$MSB" rm -f -q "$S" >/dev/null 2>&1
29
- "$MSB" create --name "$S" -m 512M -c 1 -p "127.0.0.1:$SP:8080" alpine:3.20 >/dev/null 2>&1
30
- "$MSB" exec "$S" --no-tty -- sh -c 'mkdir -p /www && echo smoke-ok > /www/index.html' >/dev/null 2>&1
31
- "$MSB" exec -d "$S" -- busybox httpd -f -p 8080 -h /www
32
- sleep 2
33
- curl -s --noproxy '*' --max-time 5 "http://127.0.0.1:$SP/" | grep -q smoke-ok && step 'port forward (detached server)' 1 || {
34
- step 'port forward (detached server)' 0
35
- echo "-- inside VM:"; "$MSB" exec "$S" --no-tty -- sh -c 'wget -q -O - http://127.0.0.1:8080/ ; netstat -ltn 2>/dev/null | head' 2>&1
36
- "$MSB" inspect "$S" --format json 2>&1 | grep -iE -A3 '"port' | head -20
37
- }
38
- "$MSB" rm -f -q "$S" >/dev/null 2>&1
39
-
40
- N=dsh-computer-check; B="http://127.0.0.1:$PORT"
41
- echo "== Create AIO VM (agent only)"
42
- "$MSB" rm -f -q "$N" >/dev/null 2>&1
43
- t=$(date +%s)
44
- "$MSB" create --name "$N" --hostname dsh-computer -m 4G -c 2 -p "127.0.0.1:$PORT:8080" \
45
- --mount-dir "$SHARED:$SHARED:uid=1000,gid=1000" \
46
- -e DISABLE_JUPYTER=true -e DISABLE_CODE_SERVER=true -e DISABLE_NODEJS_REPL=true "$IMAGE" \
47
- && step 'AIO create' 1 "($(secs $t)s)" || { step 'AIO create' 0; printf '%s\n' "${RES[@]}"; exit 1; }
48
-
49
- echo "== Start image entrypoint as a detached job"
50
- t=$(date +%s)
51
- "$MSB" exec -d "$N" -u root -e DISABLE_JUPYTER=true -e DISABLE_CODE_SERVER=true -e DISABLE_NODEJS_REPL=true -- /opt/gem/run.sh
52
- if waitfor "$B/v1/sandbox" 240; then
53
- step 'AIO services healthy' 1 "($(secs $t)s)"
54
- else
55
- step 'AIO services healthy' 0 "($(secs $t)s)"
56
- echo "-- diagnostics"
57
- X -u root -- sh -c 'supervisorctl -c /opt/gem/supervisord.conf status 2>&1 | head -25; echo ---; tail -5 /var/log/nginx/error.log 2>/dev/null; echo ---; ls /proc/sys/net/ipv6 >/dev/null 2>&1 && echo ipv6:yes || echo ipv6:no'
58
- # Same fix as on hosts without IPv6: drop nginx "listen [::]" lines and restart it.
59
- echo "-- retry with IPv6 listeners removed"
60
- X -u root -- sh -c 'for f in $(grep -rln "listen \[::\]" /opt/gem /etc/nginx 2>/dev/null); do sed -i "/listen \[::\]/d" $f; done; supervisorctl -c /opt/gem/supervisord.conf restart nginx'
61
- waitfor "$B/v1/sandbox" 60 && step 'AIO services healthy (ipv6 patch)' 1 || step 'AIO services healthy (ipv6 patch)' 0
62
- fi
63
- W="$(X -u gem -- sh -c 'whoami; hostname' | tr '\n' ' ')"; echo "$W" | grep -q gem && step 'shell exec as gem' 1 "($W)" || step 'shell exec as gem' 0 "($W)"
64
- X -u gem -- cat "$SHARED/from-host.txt" | grep -q hello-from-mac && step 'AIO shared folder' 1 || step 'AIO shared folder' 0
65
- waitfor "$B/cdp/json/version" 60 && step 'browser CDP' 1 || step 'browser CDP' 0
66
- curl -s --noproxy '*' --max-time 10 -X POST -H 'content-type: application/json' -H 'accept: application/json, text/event-stream' \
67
- -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"check","version":"1"}}}' "$B/mcp" \
68
- | grep -q protocolVersion && step 'browser MCP' 1 || step 'browser MCP' 0
69
- [ "$(code "$B/vnc/index.html")" = 200 ] && step 'live view (noVNC page)' 1 || step 'live view (noVNC page)' 0
70
- "$MSB" metrics "$N" 2>&1 | head -3
71
- echo; echo "Live view: $B/vnc/index.html?autoconnect=true&resize=scale"
72
- echo "VM left running. Remove later with: \"$MSB\" rm -f $N"
73
- echo "== Summary"; printf '%s\n' "${RES[@]}"; echo "Log saved to: $LOG"
@@ -1,116 +0,0 @@
1
- #!/usr/bin/env bash
2
- # dsh-computer: macOS (Apple silicon) feasibility check for the microsandbox backend.
3
- # bash check-mac.sh # smoke test (tiny image) + full AIO test
4
- # bash check-mac.sh --smoke # only the quick microVM smoke test
5
- # Writes a full log next to this script: dsh-computer-check.log
6
- set -u
7
- HERE="$(cd "$(dirname "$0")" && pwd)"
8
- LOG="$HERE/dsh-computer-check.log"
9
- exec > >(tee "$LOG") 2>&1
10
-
11
- IMAGE="${IMAGE:-ghcr.io/agent-infra/sandbox:latest}"
12
- SMOKE_IMAGE="${SMOKE_IMAGE:-alpine:3.20}"
13
- PORT="${PORT:-18080}"
14
- SMOKE_ONLY=0; [ "${1:-}" = "--smoke" ] && SMOKE_ONLY=1
15
-
16
- declare -a RES
17
- step() { # name ok detail
18
- local tag; if [ "$2" = 1 ]; then tag=PASS; printf '\033[32m'; else tag=FAIL; printf '\033[31m'; fi
19
- printf '[%s] %s %s\033[0m\n' "$tag" "$1" "${3:-}"; RES+=("$(printf '%-34s %s' "$1" "$tag")")
20
- }
21
- summary() { echo "== Summary"; printf '%s\n' "${RES[@]}"; echo "Log saved to: $LOG"; }
22
- code() { curl -s -o /dev/null -w '%{http_code}' --noproxy '*' --max-time 5 "$1" 2>/dev/null || echo 000; }
23
- waitfor() { local i=0; while [ $i -lt "$2" ]; do [ "$(code "$1")" = 200 ] && return 0; sleep 2; i=$((i+2)); done; return 1; }
24
- secs() { echo $(( $(date +%s) - $1 )); }
25
-
26
- echo "== Environment"
27
- sw_vers 2>/dev/null | tr '\n' ' '; echo; echo "arch: $(uname -m), RAM: $(( $(sysctl -n hw.memsize) / 1073741824 )) GB"
28
- df -h "$HOME" | tail -1
29
- NODE_V="$(node -v 2>/dev/null || true)"; NODE_MAJOR="${NODE_V#v}"; NODE_MAJOR="${NODE_MAJOR%%.*}"
30
- [ -n "$NODE_V" ] && [ "${NODE_MAJOR:-0}" -ge 22 ] && step 'node>=22' 1 "($NODE_V)" || { step 'node>=22' 0 "($NODE_V) — install with: brew install node"; summary; exit 1; }
31
- [ "$(uname -m)" = arm64 ] && step 'apple silicon' 1 || { step 'apple silicon' 0 '(microsandbox needs Apple silicon on macOS)'; summary; exit 1; }
32
-
33
- echo "== Install microsandbox (temp folder)"
34
- WORK="${TMPDIR:-/tmp}/dsh-computer-check"; mkdir -p "$WORK"
35
- ( cd "$WORK" && [ -f package.json ] || npm init -y >/dev/null; cd "$WORK" && npm i microsandbox@0.7.8 --no-fund --no-audit 2>&1 | tail -2 )
36
- MSB="$(find "$WORK/node_modules" -type f -name msb -perm -u+x 2>/dev/null | head -1)"
37
- [ -n "$MSB" ] && step 'msb bundled binary' 1 "($MSB)" || { step 'msb bundled binary' 0; summary; exit 1; }
38
-
39
- echo "== Host virtualization (msb doctor)"
40
- "$MSB" doctor && step 'hypervisor available' 1 || { step 'hypervisor available' 0; summary; exit 1; }
41
-
42
- echo "== Proxy"
43
- # msb (reqwest) reads HTTPS_PROXY, not the macOS system proxy that Clash/Surge set.
44
- if [ -z "${HTTPS_PROXY:-}" ]; then
45
- P="$(scutil --proxy 2>/dev/null)"
46
- if echo "$P" | grep -q 'HTTPSEnable : 1'; then
47
- H="$(echo "$P" | awk '/HTTPSProxy :/{print $3}')"; PT="$(echo "$P" | awk '/HTTPSPort :/{print $3}')"
48
- export HTTPS_PROXY="http://$H:$PT" HTTP_PROXY="http://$H:$PT"
49
- elif echo "$P" | grep -q 'HTTPEnable : 1'; then
50
- H="$(echo "$P" | awk '/HTTPProxy :/{print $3}')"; PT="$(echo "$P" | awk '/HTTPPort :/{print $3}')"
51
- export HTTPS_PROXY="http://$H:$PT" HTTP_PROXY="http://$H:$PT"
52
- fi
53
- fi
54
- export NO_PROXY="localhost,127.0.0.1"
55
- echo "HTTPS_PROXY=${HTTPS_PROXY:-<none, direct download>}"
56
-
57
- SHARED="$HOME/dsh-computer-check-share"; mkdir -p "$SHARED"; echo hello-from-mac > "$SHARED/from-host.txt"; rm -f "$SHARED/from-vm.txt"
58
-
59
- echo "== Smoke test: tiny microVM ($SMOKE_IMAGE)"
60
- S=dsh-computer-smoke; SP=$((PORT+1))
61
- t=$(date +%s); "$MSB" pull "$SMOKE_IMAGE" && step 'smoke image pull' 1 "($(secs $t)s)" || step 'smoke image pull' 0
62
- "$MSB" rm -f -q "$S" >/dev/null 2>&1
63
- t=$(date +%s)
64
- if "$MSB" create --name "$S" -m 512M -c 1 -p "127.0.0.1:$SP:8080" --mount-dir "$SHARED:$SHARED" "$SMOKE_IMAGE"; then
65
- step 'microVM boot' 1 "($(secs $t)s)"
66
- U="$("$MSB" exec "$S" --no-tty -- uname -sr 2>&1)"; echo "$U" | grep -q Linux && step 'microVM exec' 1 "($U)" || step 'microVM exec' 0 "($U)"
67
- R="$("$MSB" exec "$S" --no-tty -- cat "$SHARED/from-host.txt" 2>&1)"; echo "$R" | grep -q hello-from-mac && step 'shared folder host->VM' 1 || step 'shared folder host->VM' 0 "($R)"
68
- "$MSB" exec "$S" --no-tty -- sh -c "echo hello-from-vm > $SHARED/from-vm.txt" >/dev/null 2>&1
69
- grep -q hello-from-vm "$SHARED/from-vm.txt" 2>/dev/null && step 'shared folder VM->host' 1 || step 'shared folder VM->host' 0
70
- "$MSB" exec "$S" --no-tty -- sh -c 'mkdir -p /www && echo smoke-ok > /www/index.html && (busybox httpd -p 8080 -h /www &) ; sleep 1' >/dev/null 2>&1
71
- curl -s --noproxy '*' --max-time 5 "http://127.0.0.1:$SP/" | grep -q smoke-ok && step 'port forward host->VM' 1 || step 'port forward host->VM' 0
72
- "$MSB" exec "$S" --no-tty -- sh -c 'wget -q -O /dev/null -T 10 https://www.bing.com && echo net-ok' 2>&1 | grep -q net-ok && step 'VM internet access' 1 || step 'VM internet access' 0
73
- "$MSB" metrics "$S" 2>&1 | head -4
74
- t=$(date +%s); "$MSB" stop "$S" >/dev/null 2>&1; "$MSB" start "$S" >/dev/null 2>&1
75
- "$MSB" exec "$S" --no-tty -- cat "$SHARED/from-host.txt" >/dev/null 2>&1 && step 'stop/start (persistence)' 1 "($(secs $t)s)" || step 'stop/start (persistence)' 0
76
- "$MSB" rm -f -q "$S" >/dev/null 2>&1
77
- else
78
- step 'microVM boot' 0
79
- fi
80
- [ $SMOKE_ONLY = 1 ] && { summary; exit 0; }
81
-
82
- echo "== Pull AIO image (~3.6 GB download the first time)"
83
- t=$(date +%s); ok=0
84
- for try in 1 2 3; do
85
- [ $try -gt 1 ] && echo "retry $try/3 (finished layers are kept)…"
86
- "$MSB" pull "$IMAGE" && { ok=1; break; }
87
- done
88
- step 'AIO image pull' $ok "($(secs $t)s)"
89
- [ $ok = 1 ] || { summary; exit 1; }
90
-
91
- N=dsh-computer-check; B="http://127.0.0.1:$PORT"; booted=0
92
- for init in "" "--init auto"; do
93
- echo "== Boot AIO VM (${init:-image entrypoint})"
94
- "$MSB" rm -f -q "$N" >/dev/null 2>&1
95
- t=$(date +%s)
96
- # shellcheck disable=SC2086
97
- "$MSB" create --name "$N" --hostname dsh-computer -m 4G -c 2 -p "127.0.0.1:$PORT:8080" \
98
- --mount-dir "$SHARED:$SHARED:uid=1000,gid=1000" \
99
- -e DISABLE_JUPYTER=true -e DISABLE_CODE_SERVER=true -e DISABLE_NODEJS_REPL=true $init "$IMAGE" || continue
100
- if waitfor "$B/v1/sandbox" 240; then step "AIO boot (${init:-entrypoint})" 1 "($(secs $t)s)"; booted=1; break; fi
101
- step "AIO boot (${init:-entrypoint})" 0 "($(secs $t)s)"; "$MSB" logs --tail 40 "$N" 2>&1
102
- done
103
- if [ $booted = 1 ]; then
104
- W="$("$MSB" exec "$N" -u gem --no-tty -- sh -c 'whoami; hostname' 2>&1 | tr '\n' ' ')"
105
- echo "$W" | grep -q gem && step 'shell exec as gem' 1 "($W)" || step 'shell exec as gem' 0 "($W)"
106
- "$MSB" exec "$N" -u gem --no-tty -- cat "$SHARED/from-host.txt" 2>&1 | grep -q hello-from-mac && step 'AIO shared folder' 1 || step 'AIO shared folder' 0
107
- waitfor "$B/cdp/json/version" 60 && step 'browser CDP' 1 || step 'browser CDP' 0
108
- curl -s --noproxy '*' --max-time 10 -X POST -H 'content-type: application/json' -H 'accept: application/json, text/event-stream' \
109
- -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"check","version":"1"}}}' "$B/mcp" \
110
- | grep -q protocolVersion && step 'browser MCP' 1 || step 'browser MCP' 0
111
- [ "$(code "$B/vnc/index.html")" = 200 ] && step 'live view (noVNC page)' 1 || step 'live view (noVNC page)' 0
112
- "$MSB" metrics "$N" 2>&1 | head -4
113
- echo; echo "Live view: $B/vnc/index.html?autoconnect=true&resize=scale"
114
- echo "VM left running. Remove later with: \"$MSB\" rm -f $N"
115
- fi
116
- summary
@@ -1,226 +0,0 @@
1
- # dsh-computer: Windows feasibility check for the microsandbox backend.
2
- # Run in PowerShell (no admin needed unless the hypervisor check asks for it):
3
- # powershell -ExecutionPolicy Bypass -File .\check-windows.ps1
4
- # It installs microsandbox into a temp folder, boots the AIO sandbox image as a microVM,
5
- # and checks shell, browser (CDP), MCP, live view (noVNC) and a shared folder.
6
- # A full log is written next to this script: dsh-computer-check.log
7
-
8
- param(
9
- [string]$Image = 'ghcr.io/agent-infra/sandbox:latest',
10
- [int]$Port = 18080,
11
- [string]$Memory = '4G',
12
- [int]$Cpus = 2,
13
- [string]$Proxy = '', # e.g. http://127.0.0.1:7890 ; empty = use the Windows system proxy if one is set
14
- [string]$SmokeImage = 'alpine:3.20',
15
- [switch]$SkipAio, # only run the quick microVM smoke test
16
- [switch]$KeepVm
17
- )
18
-
19
- $ErrorActionPreference = 'Continue'
20
- # msb prints UTF-8; without this a Chinese-locale console shows mojibake.
21
- [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
22
- $OutputEncoding = [System.Text.Encoding]::UTF8
23
- $here = Split-Path -Parent $MyInvocation.MyCommand.Path
24
- $log = Join-Path $here 'dsh-computer-check.log'
25
- Start-Transcript -Path $log -Force | Out-Null
26
-
27
- $results = [ordered]@{}
28
- function Step($name, $ok, $detail) {
29
- $results[$name] = if ($ok) { 'PASS' } else { 'FAIL' }
30
- $color = if ($ok) { 'Green' } else { 'Red' }
31
- Write-Host ("[{0}] {1} {2}" -f $results[$name], $name, $detail) -ForegroundColor $color
32
- }
33
- function Code($url) {
34
- $c = & curl.exe -s -o NUL -w "%{http_code}" --noproxy "*" --max-time 5 -X GET $url 2>$null
35
- if (-not $c) { return '000' } else { return $c }
36
- }
37
- function WaitFor($url, $seconds) {
38
- for ($i = 0; $i -lt $seconds; $i += 2) { if ((Code $url) -eq '200') { return $true }; Start-Sleep 2 }
39
- return $false
40
- }
41
-
42
- Write-Host "== Environment" -ForegroundColor Cyan
43
- $os = Get-CimInstance Win32_OperatingSystem
44
- Write-Host ("Windows: {0} build {1}, RAM {2:N1} GB" -f $os.Caption, $os.BuildNumber, ($os.TotalVisibleMemorySize / 1MB))
45
- $drive = (Get-Item $env:TEMP).PSDrive
46
- Write-Host ("Free disk on {0}: {1:N1} GB" -f $drive.Name, ($drive.Free / 1GB))
47
- $nodeVer = (& node -v) 2>$null
48
- Step 'node>=22' ($nodeVer -and ([int]($nodeVer.TrimStart('v').Split('.')[0]) -ge 22)) "($nodeVer)"
49
-
50
- Write-Host "== Install microsandbox (temp folder)" -ForegroundColor Cyan
51
- $work = Join-Path $env:TEMP 'dsh-computer-check'
52
- New-Item -ItemType Directory -Force -Path $work | Out-Null
53
- Push-Location $work
54
- if (-not (Test-Path package.json)) { & npm init -y | Out-Null }
55
- & npm i microsandbox@0.7.8 --no-fund --no-audit 2>&1 | Select-Object -Last 3
56
- Pop-Location
57
- $msb = Get-ChildItem -Path (Join-Path $work 'node_modules') -Recurse -Filter 'msb.exe' -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
58
- Step 'msb bundled binary' ([bool]$msb) "($msb)"
59
- if (-not $msb) { Stop-Transcript | Out-Null; exit 1 }
60
- # Windows PowerShell 5.1 turns native stderr into red NativeCommandError records; print it as plain text instead.
61
- function Msb([string[]]$a) {
62
- & $msb @a 2>&1 | ForEach-Object { if ($_ -is [System.Management.Automation.ErrorRecord]) { $_.Exception.Message } else { $_ } }
63
- }
64
-
65
- Write-Host "== Host virtualization (msb doctor)" -ForegroundColor Cyan
66
- Msb @('doctor')
67
- $doctorOk = $LASTEXITCODE -eq 0
68
- Step 'hypervisor available' $doctorOk ''
69
- if (-not $doctorOk) {
70
- Write-Host "Fix: open PowerShell as Administrator and run these two lines, then REBOOT:" -ForegroundColor Yellow
71
- Write-Host " Enable-WindowsOptionalFeature -Online -FeatureName HypervisorPlatform -All -NoRestart" -ForegroundColor Yellow
72
- Write-Host " bcdedit /set hypervisorlaunchtype auto" -ForegroundColor Yellow
73
- Write-Host "Also make sure CPU virtualization (Intel VT-x / AMD SVM) is enabled in BIOS. Then run this script again." -ForegroundColor Yellow
74
- Stop-Transcript | Out-Null; exit 1
75
- }
76
-
77
- Write-Host "== Proxy" -ForegroundColor Cyan
78
- # msb downloads with reqwest, which reads HTTPS_PROXY but not the Windows system proxy (e.g. set by Clash).
79
- if (-not $Proxy -and -not $env:HTTPS_PROXY) {
80
- $is = Get-ItemProperty 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -ErrorAction SilentlyContinue
81
- if ($is -and $is.ProxyEnable -eq 1 -and $is.ProxyServer) {
82
- $ps = [string]$is.ProxyServer
83
- if ($ps -match 'https=([^;]+)') { $ps = $Matches[1] } elseif ($ps -match 'http=([^;]+)') { $ps = $Matches[1] }
84
- if ($ps -notmatch '^[a-z]+://') { $ps = "http://$ps" }
85
- $Proxy = $ps
86
- }
87
- }
88
- if ($Proxy) {
89
- $env:HTTPS_PROXY = $Proxy; $env:HTTP_PROXY = $Proxy; $env:NO_PROXY = 'localhost,127.0.0.1'
90
- Write-Host "Using proxy for image downloads: $Proxy"
91
- } elseif ($env:HTTPS_PROXY) {
92
- Write-Host "Using HTTPS_PROXY from environment: $env:HTTPS_PROXY"
93
- } else {
94
- Write-Host "No proxy detected; downloading directly (ghcr.io may be slow or drop)." -ForegroundColor Yellow
95
- }
96
-
97
- Write-Host "== Smoke test: tiny microVM ($SmokeImage)" -ForegroundColor Cyan
98
- $smoke = 'dsh-computer-smoke'
99
- $smokePort = $Port + 1
100
- $t0 = Get-Date
101
- Msb @('pull', $SmokeImage)
102
- Step 'smoke image pull' ($LASTEXITCODE -eq 0) ("({0:N0}s)" -f ((Get-Date) - $t0).TotalSeconds)
103
- $smokeMount = $null
104
- foreach ($spec in @("${shared}:${guest}:uid=1000,gid=1000", (($shared -replace '\\','/') + ":${guest}:uid=1000,gid=1000"))) {
105
- Msb @('rm', '-f', '-q', $smoke) | Out-Null
106
- $t0 = Get-Date
107
- Msb @('create', '--name', $smoke, '-m', '512M', '-c', '1', '-p', "127.0.0.1:${smokePort}:8080", '--mount-dir', $spec, $SmokeImage)
108
- if ($LASTEXITCODE -eq 0) { $smokeMount = $spec; break }
109
- Write-Host "mount spelling rejected: $spec" -ForegroundColor Yellow
110
- }
111
- if (-not $smokeMount) {
112
- Msb @('rm', '-f', '-q', $smoke) | Out-Null
113
- $t0 = Get-Date
114
- Msb @('create', '--name', $smoke, '-m', '512M', '-c', '1', '-p', "127.0.0.1:${smokePort}:8080", $SmokeImage)
115
- }
116
- $smokeUp = $LASTEXITCODE -eq 0
117
- Step 'microVM boot' $smokeUp ("({0:N1}s)" -f ((Get-Date) - $t0).TotalSeconds)
118
- if ($smokeUp) {
119
- $u = (Msb @('exec', $smoke, '--no-tty', '--', 'uname', '-sr')) -join ' '
120
- Step 'microVM exec' ($u -match 'Linux') "($u)"
121
- if ($smokeMount) {
122
- $r = (Msb @('exec', $smoke, '--no-tty', '--', 'cat', "$guest/from-host.txt")) -join ''
123
- Step 'smoke shared folder host->VM' ($r -match 'hello-from-windows') "($smokeMount)"
124
- Msb @('exec', $smoke, '--no-tty', '--', 'sh', '-c', "echo hello-from-vm > $guest/from-vm.txt") | Out-Null
125
- $b = if (Test-Path (Join-Path $shared 'from-vm.txt')) { Get-Content (Join-Path $shared 'from-vm.txt') } else { '' }
126
- Step 'smoke shared folder VM->host' ($b -match 'hello-from-vm') ''
127
- } else { Step 'smoke shared folder' $false '(no mount spelling accepted)' }
128
- Msb @('exec', $smoke, '--no-tty', '--', 'sh', '-c', 'mkdir -p /www && echo smoke-ok > /www/index.html && (busybox httpd -p 8080 -h /www &) ; sleep 1') | Out-Null
129
- $hp = & curl.exe -s --noproxy "*" --max-time 5 "http://127.0.0.1:$smokePort/"
130
- Step 'port forward host->VM' ($hp -match 'smoke-ok') ''
131
- $net = (Msb @('exec', $smoke, '--no-tty', '--', 'sh', '-c', 'wget -q -O /dev/null -T 10 https://www.bing.com && echo net-ok')) -join ''
132
- Step 'VM internet access' ($net -match 'net-ok') ''
133
- Msb @('metrics', $smoke) | Select-Object -First 6
134
- Msb @('rm', '-f', '-q', $smoke) | Out-Null
135
- }
136
- if ($SkipAio) {
137
- Write-Host "== Summary" -ForegroundColor Cyan
138
- $results.GetEnumerator() | ForEach-Object { Write-Host ("{0,-34} {1}" -f $_.Key, $_.Value) }
139
- Stop-Transcript | Out-Null; Write-Host "Log saved to: $log"; exit 0
140
- }
141
-
142
- Write-Host "== Pull AIO image (first time: ~3.6 GB download)" -ForegroundColor Cyan
143
- $t0 = Get-Date
144
- $pulled = $false
145
- for ($try = 1; $try -le 3 -and -not $pulled; $try++) {
146
- if ($try -gt 1) { Write-Host "retry $try/3 (finished layers are kept)…" -ForegroundColor Yellow }
147
- Msb @('pull', $Image)
148
- $pulled = $LASTEXITCODE -eq 0
149
- }
150
- Step 'image pull' $pulled ("({0:N0}s)" -f ((Get-Date) - $t0).TotalSeconds)
151
-
152
- # Shared folder, translated the WSL way: C:\Users\me\x -> /mnt/c/Users/me/x
153
- $shared = Join-Path $env:USERPROFILE 'dsh-computer-check-share'
154
- New-Item -ItemType Directory -Force -Path $shared | Out-Null
155
- Set-Content -Path (Join-Path $shared 'from-host.txt') -Value 'hello-from-windows'
156
- $guest = '/mnt/' + $shared.Substring(0,1).ToLower() + ($shared.Substring(2) -replace '\\','/')
157
-
158
- $name = 'dsh-computer-check'
159
- $base = "http://127.0.0.1:$Port"
160
- # Windows paths contain a drive-letter colon, which may clash with SOURCE:DEST parsing,
161
- # so several spellings are tried; "none" still validates the VM itself.
162
- $mountVariants = @(
163
- @{ label = 'backslash path'; spec = "${shared}:${guest}:uid=1000,gid=1000" },
164
- @{ label = 'forward-slash path'; spec = (($shared -replace '\\','/') + ":${guest}:uid=1000,gid=1000") },
165
- @{ label = 'no shared folder'; spec = $null }
166
- )
167
- $initVariants = @(
168
- @{ label = 'image entrypoint'; extra = @() },
169
- @{ label = 'init auto'; extra = @('--init', 'auto') }
170
- )
171
- $booted = $false
172
- $mounted = $null
173
- foreach ($init in $initVariants) {
174
- foreach ($m in $mountVariants) {
175
- Write-Host ("== Boot VM ({0}, {1})" -f $init.label, $m.label) -ForegroundColor Cyan
176
- Msb @('rm', '-f', '-q', $name) 2>$null | Out-Null
177
- $createArgs = @('create', '--name', $name, '--hostname', 'dsh-computer', '-m', $Memory, '-c', "$Cpus",
178
- '-p', "127.0.0.1:${Port}:8080",
179
- '-e', 'DISABLE_JUPYTER=true', '-e', 'DISABLE_CODE_SERVER=true', '-e', 'DISABLE_NODEJS_REPL=true')
180
- if ($m.spec) { $createArgs += @('--mount-dir', $m.spec) }
181
- $createArgs += $init.extra + @($Image)
182
- $t0 = Get-Date
183
- Msb $createArgs
184
- if ($LASTEXITCODE -ne 0) { Write-Host ("create failed with {0}; trying next variant" -f $m.label) -ForegroundColor Yellow; continue }
185
- $healthy = WaitFor "$base/v1/sandbox" 240
186
- Step ("boot ({0}, {1})" -f $init.label, $m.label) $healthy ("({0:N0}s)" -f ((Get-Date) - $t0).TotalSeconds)
187
- if ($healthy) { $booted = $true; $mounted = $m.spec; break }
188
- Write-Host "-- last VM logs:" -ForegroundColor Yellow
189
- Msb @('logs', '--tail', '40', $name) 2>&1
190
- break # created but unhealthy: the mount spelling is not the problem, try the next init mode
191
- }
192
- if ($booted) { break }
193
- }
194
-
195
- if ($booted) {
196
- Write-Host "== Checks" -ForegroundColor Cyan
197
- $who = (Msb @('exec', $name, '-u', 'gem', '--no-tty', '--', 'sh', '-c', 'whoami; hostname')) -join ' '
198
- Step 'shell exec as gem' ($who -match 'gem') "($who)"
199
- if (-not $mounted) { Step 'shared folder' $false '(no mount spelling was accepted)' } else {
200
- $read = (Msb @('exec', $name, '-u', 'gem', '--no-tty', '--', 'cat', "$guest/from-host.txt")) -join ''
201
- Step 'shared folder host->VM' ($read -match 'hello-from-windows') "($guest)"
202
- Msb @('exec', $name, '-u', 'gem', '--no-tty', '--', 'sh', '-c', "echo hello-from-vm > $guest/from-vm.txt") | Out-Null
203
- $back = if (Test-Path (Join-Path $shared 'from-vm.txt')) { Get-Content (Join-Path $shared 'from-vm.txt') } else { '' }
204
- Step 'shared folder VM->host' ($back -match 'hello-from-vm') ''
205
- }
206
- Step 'browser CDP' (WaitFor "$base/cdp/json/version" 60) ''
207
- $body = Join-Path $work 'mcp-init.json'
208
- Set-Content -Path $body -Encoding ascii -Value '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"check","version":"1"}}}'
209
- $mcp = & curl.exe -s --noproxy "*" --max-time 10 -X POST -H "content-type: application/json" -H "accept: application/json, text/event-stream" --data-binary "@$body" "$base/mcp"
210
- Step 'browser MCP' ($mcp -match 'protocolVersion') ''
211
- Step 'live view (noVNC page)' ((Code "$base/vnc/index.html") -eq '200') ''
212
- $net = (Msb @('exec', $name, '--no-tty', '--', 'sh', '-c', 'curl -s -o /dev/null -w "%{http_code}" --max-time 10 https://www.bing.com')) -join ''
213
- Step 'VM internet access' ($net -match '^(200|301|302)$') "($net)"
214
- Write-Host "== Resource usage" -ForegroundColor Cyan
215
- Msb @('metrics', $name) 2>&1 | Select-Object -First 15
216
- Write-Host ""
217
- Write-Host "Live view (open in your browser): $base/vnc/index.html?autoconnect=true&resize=scale" -ForegroundColor Green
218
- }
219
-
220
- Write-Host "== Summary" -ForegroundColor Cyan
221
- $results.GetEnumerator() | ForEach-Object { Write-Host ("{0,-34} {1}" -f $_.Key, $_.Value) }
222
- if ($booted -and -not $KeepVm) {
223
- Write-Host "VM left running for you to look at. Remove later with: `"$msb`" rm -f $name" -ForegroundColor Yellow
224
- }
225
- Stop-Transcript | Out-Null
226
- Write-Host "Log saved to: $log"