@moondeck/station 1.0.1 → 1.0.3
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/images/standard/Dockerfile +6 -2
- package/images/standard/container/uai-create-node-data +20 -0
- package/images/standard/container/uai-repair-node-data.py +207 -0
- package/images/standard/container/uai-write-node-data +71 -0
- package/lib/agent-cli.ts +26 -5
- package/lib/browser-testing.ts +33 -23
- package/lib/codex-auth.ts +89 -92
- package/lib/docker-exec.ts +1 -1
- package/lib/engine-accounts.ts +102 -64
- package/lib/git-identity.ts +49 -20
- package/lib/machine-provider-local.ts +2 -0
- package/lib/node-home.fixture.ts +155 -0
- package/lib/node-state.ts +85 -0
- package/lib/orchestrator.ts +29 -42
- package/lib/preview-ports.ts +3 -0
- package/lib/preview-upstream.ts +61 -0
- package/lib/runtime-archive.ts +3 -0
- package/lib/runtime-authority.ts +97 -1
- package/lib/task-container-cli.ts +1 -1
- package/lib/task-environment/machine-task-up.ts +27 -0
- package/lib/task-environment/self.ts +59 -16
- package/package.json +1 -1
- package/scripts/agent/task-up.sh +156 -90
- package/src/index.ts +13 -3
- package/src/main.ts +28 -6
- package/src/preview-upstream.ts +41 -0
- package/src/protocol.ts +5 -0
|
@@ -51,6 +51,7 @@ ENV DEBIAN_FRONTEND=noninteractive
|
|
|
51
51
|
RUN apt-get update \
|
|
52
52
|
&& apt-get install -y --no-install-recommends \
|
|
53
53
|
build-essential \
|
|
54
|
+
avahi-utils \
|
|
54
55
|
ca-certificates \
|
|
55
56
|
curl \
|
|
56
57
|
direnv \
|
|
@@ -71,6 +72,7 @@ RUN apt-get update \
|
|
|
71
72
|
openssh-client \
|
|
72
73
|
pkg-config \
|
|
73
74
|
procps \
|
|
75
|
+
python3-minimal \
|
|
74
76
|
ripgrep \
|
|
75
77
|
tk-dev \
|
|
76
78
|
tmux \
|
|
@@ -89,7 +91,7 @@ RUN apt-get update \
|
|
|
89
91
|
# uai-playwright volume (downloaded once per host); these are its deps.
|
|
90
92
|
RUN apt-get update \
|
|
91
93
|
&& apt-get install -y --no-install-recommends \
|
|
92
|
-
libnss3 libnspr4 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 \
|
|
94
|
+
libnss3 libnss3-tools libnspr4 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 \
|
|
93
95
|
libxkbcommon0 libatspi2.0-0 libxcomposite1 libxdamage1 libxfixes3 \
|
|
94
96
|
libxrandr2 libgbm1 libasound2 libpango-1.0-0 libcairo2 \
|
|
95
97
|
fonts-liberation fonts-unifont \
|
|
@@ -119,7 +121,9 @@ RUN curl -LsSf https://astral.sh/uv/install.sh | env UV_INSTALL_DIR=/usr/local/b
|
|
|
119
121
|
# ---------------------------------------------------------------------------
|
|
120
122
|
|
|
121
123
|
RUN groupadd --gid 1000 node \
|
|
122
|
-
&& useradd --uid 1000 --gid 1000 --create-home --home-dir /home/node --shell /bin/bash node
|
|
124
|
+
&& useradd --uid 1000 --gid 1000 --create-home --home-dir /home/node --shell /bin/bash node \
|
|
125
|
+
&& install -d -o node -g node -m 0755 /home/node/.local \
|
|
126
|
+
&& install -d -o node -g node -m 0700 /home/node/.local/state
|
|
123
127
|
|
|
124
128
|
# ---------------------------------------------------------------------------
|
|
125
129
|
# 3. asdf.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# Run only as node. Root never transfers ownership of a directory it finds
|
|
3
|
+
# here (uai-repair-node-data.py): its provenance cannot be proven. A share,
|
|
4
|
+
# OpenCode or state directory an older root-run step left owned by someone
|
|
5
|
+
# else is moved aside by node within its node-owned parent, keeping its owner
|
|
6
|
+
# and mode (nothing inside becomes readable), then recreated node-owned.
|
|
7
|
+
# ~/.local itself holds installed tools and is never moved.
|
|
8
|
+
umask 077
|
|
9
|
+
node_owns() { [ -O "$1" ]; }
|
|
10
|
+
for path in /home/node/.local /home/node/.local/share /home/node/.local/share/opencode /home/node/.local/state; do
|
|
11
|
+
if [ "$path" != /home/node/.local ] && [ -d "$path" ] && [ ! -L "$path" ] && ! node_owns "$path"; then
|
|
12
|
+
aside=$path.uai-not-node-owned.$$.$(/bin/date +%s)
|
|
13
|
+
if /bin/mv -T -- "$path" "$aside"; then
|
|
14
|
+
printf 'node data setup: moved %s aside to %s (not owned by node; root never transfers ownership)\n' "$path" "$aside" >&2
|
|
15
|
+
else
|
|
16
|
+
printf 'node data setup: %s is not owned by node and could not be moved aside; operator inspection required\n' "$path" >&2
|
|
17
|
+
fi
|
|
18
|
+
fi
|
|
19
|
+
/bin/mkdir -p -m 0700 -- "$path" || printf 'node data setup: could not create %s; checking existing directory metadata\n' "$path" >&2
|
|
20
|
+
done
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# Root only: never create directories or follow a task-controlled symlink.
|
|
2
|
+
#
|
|
3
|
+
# With no arguments: the fixed ~/.local application-data targets (LEGACY_TARGETS).
|
|
4
|
+
# With "<path>:<mode>:<walk>" arguments (path relative to /home/node, mode in
|
|
5
|
+
# octal or "-" to keep, walk "r" to recurse or "-"): normalize node's own
|
|
6
|
+
# entries. Both modes log every skip and always exit 0.
|
|
7
|
+
import os
|
|
8
|
+
import pwd
|
|
9
|
+
import stat
|
|
10
|
+
import sys
|
|
11
|
+
|
|
12
|
+
flags = os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW | os.O_CLOEXEC
|
|
13
|
+
node = pwd.getpwnam("node")
|
|
14
|
+
home_chain = ("home", "node")
|
|
15
|
+
|
|
16
|
+
# Targets mode. Root acts only through descriptors opened relative to the
|
|
17
|
+
# pinned / -> home -> node chain: directories with O_DIRECTORY|O_NOFOLLOW,
|
|
18
|
+
# files with O_NOFOLLOW|O_NONBLOCK, then fchown/fchmod on that descriptor.
|
|
19
|
+
# Root never transfers ownership: a directory or regular file is touched only
|
|
20
|
+
# when node ALREADY owns it, so root's fchown can at most reset node's own
|
|
21
|
+
# group and its fchmod only does what node could do itself. Provenance cannot
|
|
22
|
+
# be proven from inside node's home: a link count read after open cannot show
|
|
23
|
+
# that a hardlink to a system file was not just removed, and node can rename a
|
|
24
|
+
# root-owned directory it holds the parent of into a target name. Root-owned
|
|
25
|
+
# leftovers of older root-run steps are instead moved aside by node itself
|
|
26
|
+
# (uai-create-node-data, uai-write-node-data) and recreated. Regular files must
|
|
27
|
+
# also have a single link. Symlinks, sockets, FIFOs, devices, other owners and
|
|
28
|
+
# other filesystems are skipped with a log line.
|
|
29
|
+
file_flags = os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK | os.O_NOCTTY | os.O_CLOEXEC
|
|
30
|
+
max_depth = 64
|
|
31
|
+
name_chars = frozenset("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._-")
|
|
32
|
+
|
|
33
|
+
def skip(display, reason):
|
|
34
|
+
print("node data repair: skipped " + display + " (" + reason + ")", file=sys.stderr)
|
|
35
|
+
|
|
36
|
+
def parse_target(spec):
|
|
37
|
+
parts = spec.split(":")
|
|
38
|
+
if len(parts) != 3 or parts[2] not in ("r", "-"):
|
|
39
|
+
return None
|
|
40
|
+
names = parts[0].split("/")
|
|
41
|
+
for name in names:
|
|
42
|
+
if name in ("", ".", "..") or not set(name) <= name_chars:
|
|
43
|
+
return None
|
|
44
|
+
mode = None
|
|
45
|
+
if parts[1] != "-":
|
|
46
|
+
if not parts[1] or not set(parts[1]) <= set("01234567") or int(parts[1], 8) > 0o777:
|
|
47
|
+
return None
|
|
48
|
+
mode = int(parts[1], 8)
|
|
49
|
+
return names, mode, parts[2] == "r"
|
|
50
|
+
|
|
51
|
+
def open_entry(parent, name, display, quiet_missing):
|
|
52
|
+
"""Open one entry of a pinned directory without following it."""
|
|
53
|
+
try:
|
|
54
|
+
before = os.stat(name, dir_fd=parent, follow_symlinks=False)
|
|
55
|
+
except FileNotFoundError:
|
|
56
|
+
if not quiet_missing:
|
|
57
|
+
skip(display, "removed during repair")
|
|
58
|
+
return None, None
|
|
59
|
+
except OSError as error:
|
|
60
|
+
skip(display, os.strerror(error.errno))
|
|
61
|
+
return None, None
|
|
62
|
+
if stat.S_ISLNK(before.st_mode):
|
|
63
|
+
skip(display, "symlink")
|
|
64
|
+
return None, None
|
|
65
|
+
if stat.S_ISDIR(before.st_mode):
|
|
66
|
+
open_flags = flags
|
|
67
|
+
elif stat.S_ISREG(before.st_mode):
|
|
68
|
+
open_flags = file_flags
|
|
69
|
+
else:
|
|
70
|
+
skip(display, "not a regular file or directory")
|
|
71
|
+
return None, None
|
|
72
|
+
try:
|
|
73
|
+
fd = os.open(name, open_flags, dir_fd=parent)
|
|
74
|
+
except OSError as error:
|
|
75
|
+
# ELOOP/ENOTDIR: swapped for a symlink or file; EAGAIN: a lease.
|
|
76
|
+
skip(display, "changed during repair: " + os.strerror(error.errno))
|
|
77
|
+
return None, None
|
|
78
|
+
try:
|
|
79
|
+
current = os.fstat(fd)
|
|
80
|
+
except OSError as error:
|
|
81
|
+
os.close(fd)
|
|
82
|
+
skip(display, os.strerror(error.errno))
|
|
83
|
+
return None, None
|
|
84
|
+
if stat.S_IFMT(current.st_mode) != stat.S_IFMT(before.st_mode):
|
|
85
|
+
os.close(fd)
|
|
86
|
+
skip(display, "changed during repair")
|
|
87
|
+
return None, None
|
|
88
|
+
return fd, current
|
|
89
|
+
|
|
90
|
+
def fix(fd, current, display, mode, home_dev):
|
|
91
|
+
"""fchown/fchmod one pinned entry; False when it was skipped."""
|
|
92
|
+
if current.st_dev != home_dev:
|
|
93
|
+
skip(display, "on another filesystem")
|
|
94
|
+
return False
|
|
95
|
+
if stat.S_ISDIR(current.st_mode):
|
|
96
|
+
if current.st_uid != node.pw_uid:
|
|
97
|
+
skip(display, "directory not owned by node; root never transfers ownership")
|
|
98
|
+
return False
|
|
99
|
+
elif not stat.S_ISREG(current.st_mode):
|
|
100
|
+
skip(display, "not a regular file")
|
|
101
|
+
return False
|
|
102
|
+
elif current.st_nlink != 1:
|
|
103
|
+
skip(display, "hardlinked file")
|
|
104
|
+
return False
|
|
105
|
+
elif current.st_uid != node.pw_uid:
|
|
106
|
+
skip(display, "file not owned by node")
|
|
107
|
+
return False
|
|
108
|
+
if current.st_uid != node.pw_uid or current.st_gid != node.pw_gid:
|
|
109
|
+
os.fchown(fd, node.pw_uid, node.pw_gid)
|
|
110
|
+
if mode is not None and stat.S_IMODE(current.st_mode) != mode:
|
|
111
|
+
os.fchmod(fd, mode)
|
|
112
|
+
return True
|
|
113
|
+
|
|
114
|
+
def walk(directory, display, home_dev, depth):
|
|
115
|
+
if depth > max_depth:
|
|
116
|
+
skip(display, "nested too deeply")
|
|
117
|
+
return
|
|
118
|
+
try:
|
|
119
|
+
names = sorted(os.listdir(directory))
|
|
120
|
+
except OSError as error:
|
|
121
|
+
skip(display, os.strerror(error.errno))
|
|
122
|
+
return
|
|
123
|
+
for name in names:
|
|
124
|
+
child_display = display + "/" + name
|
|
125
|
+
fd, current = open_entry(directory, name, child_display, False)
|
|
126
|
+
if fd is None:
|
|
127
|
+
continue
|
|
128
|
+
try:
|
|
129
|
+
if fix(fd, current, child_display, None, home_dev) and stat.S_ISDIR(current.st_mode):
|
|
130
|
+
walk(fd, child_display, home_dev, depth + 1)
|
|
131
|
+
except OSError as error:
|
|
132
|
+
skip(child_display, os.strerror(error.errno))
|
|
133
|
+
finally:
|
|
134
|
+
os.close(fd)
|
|
135
|
+
|
|
136
|
+
def repair_target(home, home_dev, names, mode, recursive):
|
|
137
|
+
display = "/home/node/" + "/".join(names)
|
|
138
|
+
opened = []
|
|
139
|
+
try:
|
|
140
|
+
parent = home
|
|
141
|
+
for name in names[:-1]:
|
|
142
|
+
try:
|
|
143
|
+
parent = os.open(name, flags, dir_fd=parent)
|
|
144
|
+
except FileNotFoundError:
|
|
145
|
+
return
|
|
146
|
+
except OSError as error:
|
|
147
|
+
skip(display, "parent is a symlink or not a directory: " + os.strerror(error.errno))
|
|
148
|
+
return
|
|
149
|
+
opened.append(parent)
|
|
150
|
+
if os.fstat(parent).st_dev != home_dev:
|
|
151
|
+
skip(display, "parent on another filesystem")
|
|
152
|
+
return
|
|
153
|
+
fd, current = open_entry(parent, names[-1], display, True)
|
|
154
|
+
if fd is None:
|
|
155
|
+
return
|
|
156
|
+
opened.append(fd)
|
|
157
|
+
if fix(fd, current, display, mode, home_dev) and recursive and stat.S_ISDIR(current.st_mode):
|
|
158
|
+
walk(fd, display, home_dev, 1)
|
|
159
|
+
except OSError as error:
|
|
160
|
+
skip(display, os.strerror(error.errno))
|
|
161
|
+
finally:
|
|
162
|
+
for fd in reversed(opened):
|
|
163
|
+
os.close(fd)
|
|
164
|
+
|
|
165
|
+
def repair_targets(specs):
|
|
166
|
+
targets = []
|
|
167
|
+
for spec in specs:
|
|
168
|
+
target = parse_target(spec)
|
|
169
|
+
if target is None:
|
|
170
|
+
skip(repr(spec), "invalid target")
|
|
171
|
+
else:
|
|
172
|
+
targets.append(target)
|
|
173
|
+
pinned = []
|
|
174
|
+
try:
|
|
175
|
+
parent = os.open("/", flags)
|
|
176
|
+
pinned.append(parent)
|
|
177
|
+
for component in home_chain:
|
|
178
|
+
parent = os.open(component, flags, dir_fd=parent)
|
|
179
|
+
pinned.append(parent)
|
|
180
|
+
home = os.fstat(parent)
|
|
181
|
+
if home.st_uid != node.pw_uid:
|
|
182
|
+
skip("/home/node", "home is not owned by node")
|
|
183
|
+
return
|
|
184
|
+
for names, mode, recursive in targets:
|
|
185
|
+
repair_target(parent, home.st_dev, names, mode, recursive)
|
|
186
|
+
except OSError as error:
|
|
187
|
+
skip("home anchor", "missing or redirected: " + os.strerror(error.errno))
|
|
188
|
+
finally:
|
|
189
|
+
for fd in reversed(pinned):
|
|
190
|
+
os.close(fd)
|
|
191
|
+
|
|
192
|
+
# The no-argument targets: shared application data that task startup creates
|
|
193
|
+
# as node (uai-create-node-data) and the OpenCode credentials it copies in.
|
|
194
|
+
LEGACY_TARGETS = (
|
|
195
|
+
".local:0755:-",
|
|
196
|
+
".local/share:0755:-",
|
|
197
|
+
".local/share/opencode:0755:-",
|
|
198
|
+
".local/share/opencode/auth.json:0600:-",
|
|
199
|
+
".local/share/opencode/config.json:0600:-",
|
|
200
|
+
".local/state:0700:-",
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
try:
|
|
204
|
+
repair_targets(sys.argv[1:] or LEGACY_TARGETS)
|
|
205
|
+
except Exception as error:
|
|
206
|
+
print("node data repair: stopped early (" + type(error).__name__ + ")", file=sys.stderr)
|
|
207
|
+
sys.exit(0)
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# Run only as node. Root must never create or write a path inside /home/node:
|
|
3
|
+
# node can plant a symlink or hardlink there in advance, or swap one in while
|
|
4
|
+
# root works. Host copies therefore arrive on stdin and land with node's own
|
|
5
|
+
# authority; root afterwards only repairs metadata through pinned descriptors
|
|
6
|
+
# (uai-repair-node-data.py), and only on entries node already owns.
|
|
7
|
+
#
|
|
8
|
+
# A directory on the destination path that node does not own (an older
|
|
9
|
+
# root-run mkdir or docker cp whose chown never ran) is not handed over by
|
|
10
|
+
# root: its provenance cannot be proven. Node moves it aside within its own
|
|
11
|
+
# parent, keeping its owner and mode, and recreates it; the caller then
|
|
12
|
+
# delivers the content again. ~/.local itself holds installed tools and is
|
|
13
|
+
# never moved.
|
|
14
|
+
#
|
|
15
|
+
# file <dest> <mode> [<parent-mode>] stdin bytes, written atomically
|
|
16
|
+
# tar <dest-dir> [<dir-mode>] a tar stream, extracted into dest-dir
|
|
17
|
+
umask 022
|
|
18
|
+
op=${1-}
|
|
19
|
+
dest=${2-}
|
|
20
|
+
case $dest in
|
|
21
|
+
/home/node/*) ;;
|
|
22
|
+
*) printf 'node data write: refusing %s (outside /home/node)\n' "$dest" >&2; exit 64 ;;
|
|
23
|
+
esac
|
|
24
|
+
case $dest/ in
|
|
25
|
+
*/../* | */./* | *//*) printf 'node data write: refusing %s (not a normalized path)\n' "$dest" >&2; exit 64 ;;
|
|
26
|
+
esac
|
|
27
|
+
node_owns() { [ -O "$1" ]; }
|
|
28
|
+
set_aside() {
|
|
29
|
+
path=/home/node
|
|
30
|
+
case $1 in /home/node/*) rest=${1#/home/node/} ;; *) return 0 ;; esac
|
|
31
|
+
while [ -n "$rest" ]; do
|
|
32
|
+
part=${rest%%/*}
|
|
33
|
+
case $rest in */*) rest=${rest#*/} ;; *) rest= ;; esac
|
|
34
|
+
path=$path/$part
|
|
35
|
+
if [ -L "$path" ] || [ ! -d "$path" ]; then return 0; fi
|
|
36
|
+
node_owns "$path" && continue
|
|
37
|
+
if [ "$path" = /home/node/.local ]; then
|
|
38
|
+
printf 'node data write: %s is not owned by node; operator inspection required\n' "$path" >&2
|
|
39
|
+
return 1
|
|
40
|
+
fi
|
|
41
|
+
aside=$path.uai-not-node-owned.$$.$(/bin/date +%s)
|
|
42
|
+
/bin/mv -T -- "$path" "$aside" || return 1
|
|
43
|
+
printf 'node data write: moved %s aside to %s (not owned by node; root never transfers ownership)\n' "$path" "$aside" >&2
|
|
44
|
+
return 0
|
|
45
|
+
done
|
|
46
|
+
}
|
|
47
|
+
case $op in
|
|
48
|
+
file)
|
|
49
|
+
mode=${3-}
|
|
50
|
+
dir=${dest%/*}
|
|
51
|
+
set_aside "$dir" || exit 1
|
|
52
|
+
/bin/mkdir -p -- "$dir" || exit 1
|
|
53
|
+
if [ -n "${4-}" ]; then /bin/chmod "$4" -- "$dir" || exit 1; fi
|
|
54
|
+
tmp=$(/bin/mktemp -- "$dir/.uai-write.XXXXXX") || exit 1
|
|
55
|
+
if /usr/bin/tee -- "$tmp" >/dev/null && /bin/chmod "$mode" -- "$tmp" && /bin/mv -f -T -- "$tmp" "$dest"; then
|
|
56
|
+
exit 0
|
|
57
|
+
fi
|
|
58
|
+
/bin/rm -f -- "$tmp"
|
|
59
|
+
exit 1
|
|
60
|
+
;;
|
|
61
|
+
tar)
|
|
62
|
+
set_aside "$dest" || exit 1
|
|
63
|
+
/bin/mkdir -p -- "$dest" || exit 1
|
|
64
|
+
if [ -n "${3-}" ]; then /bin/chmod "$3" -- "$dest" || exit 1; fi
|
|
65
|
+
exec /bin/tar -C "$dest" --no-same-owner -xpf -
|
|
66
|
+
;;
|
|
67
|
+
*)
|
|
68
|
+
printf 'node data write: unknown operation %s\n' "$op" >&2
|
|
69
|
+
exit 64
|
|
70
|
+
;;
|
|
71
|
+
esac
|
package/lib/agent-cli.ts
CHANGED
|
@@ -1272,12 +1272,30 @@ async function main() {
|
|
|
1272
1272
|
out(action + " #" + t.shortId + ": " + t.text);
|
|
1273
1273
|
break;
|
|
1274
1274
|
}
|
|
1275
|
-
case "preview add":
|
|
1275
|
+
case "preview add":
|
|
1276
|
+
case "preview update": {
|
|
1276
1277
|
const name = pos[0] || flags.name;
|
|
1277
1278
|
const port = Number(pos[1] || flags.port);
|
|
1278
|
-
if (!name || !Number.isInteger(port)) { console.error("moondeck: preview
|
|
1279
|
-
|
|
1280
|
-
|
|
1279
|
+
if (!name || !Number.isInteger(port) || port < 1 || port > 65535) { console.error("moondeck: preview " + action + " <name> <containerPort>"); process.exit(1); }
|
|
1280
|
+
if (Object.keys(flags).some(k => !["name", "port", "upstream-host", "https"].includes(k)) || (flags.https !== undefined && flags.https !== "true") || (flags["upstream-host"] !== undefined && !flagValue(flags["upstream-host"]))) {
|
|
1281
|
+
console.error("moondeck: preview " + action + " <name> <port> [--upstream-host <hostname>] [--https]"); process.exit(1);
|
|
1282
|
+
}
|
|
1283
|
+
const upstream = {
|
|
1284
|
+
...(flags["upstream-host"] !== undefined ? { upstreamHost: flags["upstream-host"] } : {}),
|
|
1285
|
+
...(flags.https === "true" ? { upstreamTls: true } : {}),
|
|
1286
|
+
};
|
|
1287
|
+
const r = action === "add"
|
|
1288
|
+
? await api("POST", "/api/agent/previews", { name, containerPort: port, ...upstream })
|
|
1289
|
+
: await api("PATCH", "/api/agent/previews/" + encodeURIComponent(name), { containerPort: port, ...upstream });
|
|
1290
|
+
out("preview '" + r.name + "' on port " + r.containerPort + (action === "add" ? " — turn it on with: moondeck preview enable " + r.name : " — updated"));
|
|
1291
|
+
if (upstream.upstreamHost || upstream.upstreamTls) console.error("Portless users: outside self tasks, start with portless proxy start --lan (or PORTLESS_LAN=1; enables mDNS). Check for LAN mode disabled; if printed, use an updated Moondeck image with avahi-utils, or ask the operator to install it and fix any reported LAN-IP problem, then restart. Use its printed LAN hostname (usually mta.local) and proxy port: HTTPS 443, HTTP 80, or your explicit -p port (e.g. 1355).");
|
|
1292
|
+
break;
|
|
1293
|
+
}
|
|
1294
|
+
case "preview remove": {
|
|
1295
|
+
const name = pos[0] || flags.name;
|
|
1296
|
+
if (!name) { console.error("moondeck: preview remove <name>"); process.exit(1); }
|
|
1297
|
+
await api("DELETE", "/api/agent/previews/" + encodeURIComponent(name));
|
|
1298
|
+
out("removed preview '" + name + "'");
|
|
1281
1299
|
break;
|
|
1282
1300
|
}
|
|
1283
1301
|
case "preview enable":
|
|
@@ -1465,7 +1483,10 @@ async function main() {
|
|
|
1465
1483
|
" moondeck review report --pr <number|URL> --head <full-sha> --must <n> --should <n> --nits <n> --verdict approve|changes [--summary text] [--assignment id] [--revision n]",
|
|
1466
1484
|
" moondeck crew outcome @agent accepted|reworked|failed [--note text] [--assignment id] [--revision n]",
|
|
1467
1485
|
" Review reports require an authorized exact-head assignment. Outcomes are Secretary assessments, never human acceptance.",
|
|
1468
|
-
" moondeck preview add <name> <containerPort>",
|
|
1486
|
+
" moondeck preview add <name> <containerPort> [--upstream-host <h>] [--https]",
|
|
1487
|
+
" moondeck preview update <name> <containerPort> [--upstream-host <h>] [--https]",
|
|
1488
|
+
" moondeck preview remove <name>",
|
|
1489
|
+
" Portless outside self: portless proxy start --lan or PORTLESS_LAN=1 (mDNS); use printed *.local Host and proxy port 443/80, or explicit -p 1355. Check for LAN mode disabled; update the image/install avahi-utils and resolve the reported LAN issue, then restart.",
|
|
1469
1490
|
" moondeck preview enable|disable <name> (turn it on; prints its URL)",
|
|
1470
1491
|
" moondeck preview public|private <name> (public: a link anyone can open)",
|
|
1471
1492
|
" moondeck project list | show <id|slug>",
|
package/lib/browser-testing.ts
CHANGED
|
@@ -49,9 +49,14 @@ import {
|
|
|
49
49
|
taskContainerCli,
|
|
50
50
|
} from "./task-container-cli";
|
|
51
51
|
import { MCP_CONFIG_LOCK_PATH } from "./mcp-config-lock";
|
|
52
|
+
import { nodeHomeRepairArgv } from "./node-state";
|
|
52
53
|
import {
|
|
53
54
|
MACHINE_RUNTIME_AUTHORITY_ENV,
|
|
55
|
+
ROOT_NPM_STATE_DIR,
|
|
54
56
|
RUNTIME_AUTHORITY_ENV,
|
|
57
|
+
rootAuthorityEnv,
|
|
58
|
+
rootNpmStateGuardCommand,
|
|
59
|
+
rootRuntimeAuthorityDockerExecArgs,
|
|
55
60
|
runtimeAuthorityDockerExecArgs,
|
|
56
61
|
} from "./runtime-authority";
|
|
57
62
|
import { STANDARD_DEFAULT_NODE_VERSION } from "./standard-image";
|
|
@@ -1063,9 +1068,12 @@ const ROOT_RUNTIME_PATH =
|
|
|
1063
1068
|
// absolute path made this worker exit 127 on every task machine, so its
|
|
1064
1069
|
// done-marker was never written and each ensure re-ran it (live 2026-09-09).
|
|
1065
1070
|
// The path lists the asdf bin first and never the shims, so a container
|
|
1066
|
-
// resolves exactly what it did before.
|
|
1071
|
+
// resolves exactly what it did before. The absolute node bin also means no
|
|
1072
|
+
// asdf lookup depends on the working directory, so root's npx runs from its
|
|
1073
|
+
// own root-only state directory: npm then finds no project `.npmrc` that node
|
|
1074
|
+
// could write (as it could in /workspace).
|
|
1067
1075
|
const APT_DEPS_CMD =
|
|
1068
|
-
`PATH=${ROOT_RUNTIME_PATH} npx ` +
|
|
1076
|
+
`cd ${ROOT_NPM_STATE_DIR} && PATH=${ROOT_RUNTIME_PATH} npx ` +
|
|
1069
1077
|
"-y playwright@latest install-deps chromium";
|
|
1070
1078
|
const APT_VIEWER_CMD =
|
|
1071
1079
|
"/usr/bin/apt-get install -y --no-install-recommends xvfb x11vnc novnc websockify";
|
|
@@ -1198,7 +1206,7 @@ export async function setupBrowserTesting(
|
|
|
1198
1206
|
projectEnvProfile: "maintenance",
|
|
1199
1207
|
argv: ["/usr/bin/chown", "node:node", "/opt/pw-browsers"],
|
|
1200
1208
|
user: "root",
|
|
1201
|
-
env: authorityEnv,
|
|
1209
|
+
env: rootAuthorityEnv(authorityEnv),
|
|
1202
1210
|
timeoutMs: 5_000,
|
|
1203
1211
|
maxOutputBytes: 64 * 1024,
|
|
1204
1212
|
});
|
|
@@ -1223,7 +1231,7 @@ export async function setupBrowserTesting(
|
|
|
1223
1231
|
"exec",
|
|
1224
1232
|
"-u",
|
|
1225
1233
|
"root",
|
|
1226
|
-
...
|
|
1234
|
+
...rootRuntimeAuthorityDockerExecArgs(),
|
|
1227
1235
|
container,
|
|
1228
1236
|
"/usr/bin/chown",
|
|
1229
1237
|
"node:node",
|
|
@@ -1451,12 +1459,20 @@ export async function setupBrowserTesting(
|
|
|
1451
1459
|
const viewerSetup = VIEWER_STEPS.map((step) => `( ${step} )`).join("; ");
|
|
1452
1460
|
const aptWorker = [
|
|
1453
1461
|
"set -e",
|
|
1454
|
-
|
|
1462
|
+
// Root's npm state must be proved root-controlled first. If it is not,
|
|
1463
|
+
// skip only the npx step (logged); never run root npm from a location
|
|
1464
|
+
// node could have prepared, and never fail the rest of the worker.
|
|
1465
|
+
// A failing npx still ends the worker (set -e), so the next ensure
|
|
1466
|
+
// retries, exactly as before.
|
|
1467
|
+
`if ( ${rootNpmStateGuardCommand()} ); then ( ${APT_DEPS_CMD} ); ` +
|
|
1468
|
+
`else echo "uai: skipped playwright install-deps (root npm state unproved)" >&2; fi`,
|
|
1455
1469
|
APT_VIEWER_CMD,
|
|
1456
1470
|
// Close lock fd 9 before starting long-lived viewer grandchildren, or
|
|
1457
1471
|
// they inherit it and keep the apt lock forever after this worker exits.
|
|
1458
1472
|
`/usr/bin/su -s /bin/sh node -c ${shellQuote(viewerSetup)} 9>&-`,
|
|
1459
|
-
|
|
1473
|
+
// Hand back entries an older root npx left in node's ~/.npm — through
|
|
1474
|
+
// pinned no-follow descriptors only; never a path-based chown -R there.
|
|
1475
|
+
`${nodeHomeRepairArgv([{ path: "/home/node/.npm", recursive: true }]).map(shellQuote).join(" ")} || true`,
|
|
1460
1476
|
`/usr/bin/touch ${aptGuard.done}`,
|
|
1461
1477
|
].join("; ");
|
|
1462
1478
|
const guardedAptStart = [
|
|
@@ -1470,12 +1486,13 @@ export async function setupBrowserTesting(
|
|
|
1470
1486
|
">/tmp/uai-pw-deps.log 2>&1 &",
|
|
1471
1487
|
].join("; ");
|
|
1472
1488
|
|
|
1489
|
+
// Root form of the authority: npm prefix/cache/logs under /root, no
|
|
1490
|
+
// user/global npmrc (node writes ~/.npmrc), no PATH entry in node's home.
|
|
1491
|
+
// HOME remains node's; root-run tools must keep their XDG state out of
|
|
1492
|
+
// the task user's home.
|
|
1473
1493
|
const rootWorkerEnv = {
|
|
1474
|
-
...authorityEnv,
|
|
1475
|
-
|
|
1476
|
-
npm_config_cache: "/tmp/uai-root-npm-cache",
|
|
1477
|
-
NPM_CONFIG_LOGS_DIR: "/tmp/uai-root-npm-cache/_logs",
|
|
1478
|
-
npm_config_logs_dir: "/tmp/uai-root-npm-cache/_logs",
|
|
1494
|
+
...rootAuthorityEnv(authorityEnv),
|
|
1495
|
+
XDG_STATE_HOME: "/root/.local/state",
|
|
1479
1496
|
};
|
|
1480
1497
|
if (environment) {
|
|
1481
1498
|
await environment.exec({
|
|
@@ -1499,19 +1516,12 @@ export async function setupBrowserTesting(
|
|
|
1499
1516
|
// the MCP server). Found live 2026-07-08.
|
|
1500
1517
|
"-w",
|
|
1501
1518
|
"/workspace",
|
|
1502
|
-
|
|
1503
|
-
//
|
|
1504
|
-
//
|
|
1505
|
-
|
|
1506
|
-
// fall back to node's private cache or logs directory.
|
|
1507
|
-
"-e",
|
|
1508
|
-
"NPM_CONFIG_CACHE=/tmp/uai-root-npm-cache",
|
|
1509
|
-
"-e",
|
|
1510
|
-
"npm_config_cache=/tmp/uai-root-npm-cache",
|
|
1511
|
-
"-e",
|
|
1512
|
-
"NPM_CONFIG_LOGS_DIR=/tmp/uai-root-npm-cache/_logs",
|
|
1519
|
+
// The root authority carries root-only npm settings in both
|
|
1520
|
+
// spellings, so npm's case-insensitive lookup cannot fall back to
|
|
1521
|
+
// node's cache, logs, prefix or npmrc.
|
|
1522
|
+
...rootRuntimeAuthorityDockerExecArgs(),
|
|
1513
1523
|
"-e",
|
|
1514
|
-
"
|
|
1524
|
+
"XDG_STATE_HOME=/root/.local/state",
|
|
1515
1525
|
container,
|
|
1516
1526
|
"/bin/sh",
|
|
1517
1527
|
"-c",
|