@ouro.bot/cli 0.1.0-alpha.733 → 0.1.0-alpha.734
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/changelog.json +25 -0
- package/deploy/unraid/Dockerfile +27 -0
- package/deploy/unraid/README.txt +1368 -0
- package/deploy/unraid/audit-container-spec.sh +4 -0
- package/deploy/unraid/container-runtime.json +1 -0
- package/deploy/unraid/sanctuary-acceptance-adapter.sh +37 -0
- package/deploy/unraid/sanctuary-acceptance-contract.json +200 -0
- package/deploy/unraid/sanctuary-acceptance-harness.sh +23 -0
- package/deploy/unraid/sanctuary-deployment-target.mjs +705 -0
- package/deploy/unraid/sanctuary-safe-rename.py +24 -0
- package/deploy/unraid/sanctuary-unit16-host-broker.mjs +1777 -0
- package/deploy/unraid/sanctuary-unit16-run.sh +502 -0
- package/deploy/unraid/sanctuary-unit18-target-audit.sh +27 -0
- package/deploy/unraid/sanctuary.ouro/agent.json +24 -0
- package/deploy/unraid/sanctuary.ouro/arc/README.md +3 -0
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +5 -0
- package/deploy/unraid/sanctuary.ouro/habits/sanctuary-health.md +8 -0
- package/deploy/unraid/sanctuary.ouro/provider-readiness.json +18 -0
- package/deploy/unraid/sanctuary.ouro/psyche/ASPIRATIONS.md +3 -0
- package/deploy/unraid/sanctuary.ouro/psyche/IDENTITY.md +3 -0
- package/deploy/unraid/sanctuary.ouro/psyche/LORE.md +3 -0
- package/deploy/unraid/sanctuary.ouro/psyche/SOUL.md +5 -0
- package/deploy/unraid/sanctuary.ouro/psyche/TACIT.md +7 -0
- package/deploy/unraid/sanctuary.ouro/tool-profiles.json +21 -0
- package/deploy/unraid/sanctuary.xml +25 -0
- package/dist/heart/approval-files.js +113 -0
- package/dist/heart/approval-store.js +168 -9
- package/dist/heart/auth/auth-flow.js +17 -1
- package/dist/heart/autonomy-budget.js +44 -1
- package/dist/heart/awaiting/await-scheduler.js +6 -2
- package/dist/heart/config.js +8 -0
- package/dist/heart/core.js +117 -132
- package/dist/heart/daemon/cli-exec.js +73 -1
- package/dist/heart/daemon/cli-help.js +5 -0
- package/dist/heart/daemon/cli-parse.js +6 -4
- package/dist/heart/daemon/container-credential-bootstrap.js +185 -0
- package/dist/heart/daemon/container-healthcheck.js +94 -0
- package/dist/heart/daemon/container-runtime.js +84 -0
- package/dist/heart/daemon/container-spec-auditor-main.js +156 -0
- package/dist/heart/daemon/container-spec-auditor.js +156 -0
- package/dist/heart/daemon/daemon-bootstrap-startup.js +41 -0
- package/dist/heart/daemon/daemon-entry.js +116 -28
- package/dist/heart/daemon/daemon-health.js +10 -0
- package/dist/heart/daemon/daemon.js +92 -5
- package/dist/heart/daemon/runtime-logging.js +6 -0
- package/dist/heart/daemon/runtime-mode.js +13 -2
- package/dist/heart/daemon/sanctuary-acceptance-adapter.js +2365 -0
- package/dist/heart/daemon/sanctuary-acceptance-harness.js +1624 -0
- package/dist/heart/daemon/sanctuary-acceptance-marker.js +267 -0
- package/dist/heart/daemon/sanctuary-acceptance-scenarios.js +985 -0
- package/dist/heart/daemon/sanctuary-scheduler-liveness.js +227 -0
- package/dist/heart/daemon/sanctuary-scheduler-origin.js +126 -0
- package/dist/heart/daemon/sense-manager.js +25 -6
- package/dist/heart/daemon/supercronic-supervisor.js +267 -0
- package/dist/heart/habits/habit-scheduler.js +7 -3
- package/dist/heart/identity.js +13 -3
- package/dist/heart/provider-credentials.js +9 -1
- package/dist/heart/provider-models.js +8 -0
- package/dist/heart/provider-ping.js +5 -2
- package/dist/heart/providers/openai-compatible.js +177 -0
- package/dist/heart/runtime-credentials.js +217 -8
- package/dist/heart/sense-truth.js +2 -0
- package/dist/heart/tool-approval.js +1 -0
- package/dist/heart/turn-context.js +8 -0
- package/dist/mind/prompt.js +9 -0
- package/dist/nerves/coverage/source-scanner.js +4 -4
- package/dist/nerves/index.js +75 -9
- package/dist/nerves/runtime.js +12 -0
- package/dist/repertoire/tool-arguments.js +39 -0
- package/dist/repertoire/tools-unraid.js +353 -0
- package/dist/repertoire/tools.js +19 -1
- package/dist/repertoire/unraid-client.js +155 -0
- package/dist/repertoire/unraid-restart.js +130 -0
- package/dist/senses/private-runtime-worker.js +3 -2
- package/dist/senses/sanctuary-grounding.js +118 -0
- package/dist/senses/sanctuary-health-acceptance-probe-entry.js +12 -0
- package/dist/senses/sanctuary-health-acceptance-probe.js +772 -0
- package/dist/senses/sanctuary-health-runner.js +146 -0
- package/dist/senses/sanctuary-health.js +447 -0
- package/dist/senses/sanctuary-interactive-control.js +306 -0
- package/dist/senses/sanctuary-runtime.js +206 -0
- package/dist/senses/shared-turn.js +11 -3
- package/dist/senses/telegram-approval-runtime.js +526 -0
- package/dist/senses/telegram-audit-ledger.js +220 -0
- package/dist/senses/telegram-client.js +1471 -0
- package/dist/senses/telegram-entry.js +80 -0
- package/dist/senses/telegram.js +1232 -0
- package/npm-shrinkwrap.json +6558 -0
- package/package.json +4 -2
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
set -eu
|
|
3
|
+
|
|
4
|
+
CONFIG_ROOT=/mnt/user/appdata/ouro-butler/acceptance/configs
|
|
5
|
+
EVIDENCE_ROOT=/mnt/user/appdata/ouro-butler/acceptance/evidence
|
|
6
|
+
RUNTIME_ROOT=/mnt/user/appdata/ouro-butler/runtime/.ouro-cli
|
|
7
|
+
BUNDLE_ROOT=/mnt/user/appdata/ouro-butler/agent/sanctuary.ouro
|
|
8
|
+
TARGET_PROFILE=staging
|
|
9
|
+
PRODUCTION_CONTAINER=ouro-butler-staging
|
|
10
|
+
TARGET_CONTAINER_ID=
|
|
11
|
+
IMAGE_ID=${1:-}
|
|
12
|
+
MODE=${2:-}
|
|
13
|
+
BROKER_PID=
|
|
14
|
+
PRIVATE_ROOT=
|
|
15
|
+
PRODUCTION_STOPPED=no
|
|
16
|
+
HOST_REBOOT_COMMIT_STATE=not_sent
|
|
17
|
+
ACCEPTANCE_ALIAS_MOUNTED=no
|
|
18
|
+
ACCEPTANCE_CANONICAL_PINNED=no
|
|
19
|
+
ACCEPTANCE_PIN_ROOT=
|
|
20
|
+
ACCEPTANCE_STATE_ROOT=
|
|
21
|
+
|
|
22
|
+
assert_health_probe_cleanup() {
|
|
23
|
+
/usr/bin/timeout -s KILL 10 /usr/local/bin/node -e '
|
|
24
|
+
const fs = require("node:fs");
|
|
25
|
+
const path = require("node:path");
|
|
26
|
+
const acceptance = process.argv[1];
|
|
27
|
+
for (const name of ["health-probe-workspaces", "health-probe-pending", "health-probe-processes"]) {
|
|
28
|
+
const target = path.join(acceptance, name);
|
|
29
|
+
if (fs.existsSync(target) && fs.readdirSync(target).length !== 0) process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
if (fs.existsSync(process.argv[2])) process.exit(1);
|
|
32
|
+
' "$ACCEPTANCE_STATE_ROOT" "$BUNDLE_ROOT/state/health/sanctuary-health.json.lease"
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
cleanup_unit16() {
|
|
36
|
+
CLEANUP_STATUS=$?
|
|
37
|
+
if test -n "$BROKER_PID"; then kill "$BROKER_PID" 2>/dev/null || true; wait "$BROKER_PID" 2>/dev/null || true; fi
|
|
38
|
+
if test "$ACCEPTANCE_CANONICAL_PINNED" = yes && ! assert_health_probe_cleanup; then CLEANUP_STATUS=1; fi
|
|
39
|
+
if test "$PRODUCTION_STOPPED" = yes && test "$HOST_REBOOT_COMMIT_STATE" = not_sent; then
|
|
40
|
+
if ! restore_production_container; then CLEANUP_STATUS=1; fi
|
|
41
|
+
PRODUCTION_STOPPED=no
|
|
42
|
+
fi
|
|
43
|
+
if test "$ACCEPTANCE_CANONICAL_PINNED" = yes; then
|
|
44
|
+
if /usr/bin/timeout -s KILL 10 /bin/umount "$ACCEPTANCE_STATE_ROOT"; then
|
|
45
|
+
ACCEPTANCE_CANONICAL_PINNED=no
|
|
46
|
+
else CLEANUP_STATUS=1
|
|
47
|
+
fi
|
|
48
|
+
fi
|
|
49
|
+
if test "$ACCEPTANCE_ALIAS_MOUNTED" = yes; then
|
|
50
|
+
if /usr/bin/timeout -s KILL 10 /bin/umount "$ACCEPTANCE_PIN_ROOT"; then
|
|
51
|
+
ACCEPTANCE_ALIAS_MOUNTED=no
|
|
52
|
+
else CLEANUP_STATUS=1
|
|
53
|
+
fi
|
|
54
|
+
fi
|
|
55
|
+
if test "$ACCEPTANCE_ALIAS_MOUNTED" = no && test -n "$PRIVATE_ROOT" && test -d "$PRIVATE_ROOT"; then rm -rf -- "$PRIVATE_ROOT"; fi
|
|
56
|
+
return "$CLEANUP_STATUS"
|
|
57
|
+
}
|
|
58
|
+
trap cleanup_unit16 EXIT HUP INT TERM
|
|
59
|
+
|
|
60
|
+
IMAGE_DIGEST=${IMAGE_ID#sha256:}
|
|
61
|
+
test "$IMAGE_DIGEST" != "$IMAGE_ID" || exit 2
|
|
62
|
+
test "${#IMAGE_DIGEST}" -eq 64 || exit 2
|
|
63
|
+
case "$IMAGE_DIGEST" in *[!0-9a-f]*) exit 2 ;; esac
|
|
64
|
+
test "$(/usr/bin/timeout -s KILL 20 /usr/bin/docker image inspect --format '{{.Id}}' "$IMAGE_ID")" = "$IMAGE_ID" || exit 1
|
|
65
|
+
test -d "$CONFIG_ROOT" && test ! -L "$CONFIG_ROOT" || exit 1
|
|
66
|
+
test -d "$EVIDENCE_ROOT" && test ! -L "$EVIDENCE_ROOT" || exit 1
|
|
67
|
+
test "$(stat -c '%u:%g %a' "$CONFIG_ROOT")" = "10001:10001 700" || exit 1
|
|
68
|
+
test "$(stat -c '%u:%g %a' "$EVIDENCE_ROOT")" = "10001:10001 700" || exit 1
|
|
69
|
+
|
|
70
|
+
case "$MODE" in
|
|
71
|
+
materialize)
|
|
72
|
+
test "$#" -eq 3 || { test "$#" -eq 4 && test "$3" = cursor-snapshot; } || exit 2
|
|
73
|
+
COMMAND=${3:-}
|
|
74
|
+
PHASE=${4:-}
|
|
75
|
+
;;
|
|
76
|
+
*)
|
|
77
|
+
test "$#" -eq 3 || exit 2
|
|
78
|
+
COMMAND=$MODE
|
|
79
|
+
CONFIG_NAME=${3:-}
|
|
80
|
+
;;
|
|
81
|
+
esac
|
|
82
|
+
case "$COMMAND" in
|
|
83
|
+
telegram-bootstrap|cursor-snapshot|cursor-delta|callback-inject|unraid-key-rotate|evidence-snapshot|reboot-request|reboot-resume|evidence-bundle-index|evidence-bundle-verify) ;;
|
|
84
|
+
*) exit 2 ;;
|
|
85
|
+
esac
|
|
86
|
+
|
|
87
|
+
PRIVATE_ROOT=$(mktemp -d /run/ouro-unit16.XXXXXX)
|
|
88
|
+
chmod 0700 "$PRIVATE_ROOT"
|
|
89
|
+
chown 0:0 "$PRIVATE_ROOT"
|
|
90
|
+
SOCKET_ROOT=$PRIVATE_ROOT/socket
|
|
91
|
+
install -d -m 0750 -o 0 -g 10001 "$SOCKET_ROOT"
|
|
92
|
+
BROKER_SOCKET=$SOCKET_ROOT/adapter.sock
|
|
93
|
+
CLOSED_INVENTORY=$PRIVATE_ROOT/closed-inventory.json
|
|
94
|
+
BROKER_SNAPSHOT=$PRIVATE_ROOT/broker-container-inspect.json
|
|
95
|
+
BROKER_PROGRAM=$PRIVATE_ROOT/sanctuary-unit16-host-broker.mjs
|
|
96
|
+
TARGET_AUDITOR=$PRIVATE_ROOT/sanctuary-deployment-target.mjs
|
|
97
|
+
IMAGE_FACT=$PRIVATE_ROOT/image-digest
|
|
98
|
+
CONTAINER_FACT=$PRIVATE_ROOT/container-digest
|
|
99
|
+
PROCESS_BINDING_FACT=$PRIVATE_ROOT/process-binding-digest
|
|
100
|
+
HEALTH_FACT=$PRIVATE_ROOT/postboot-health.json
|
|
101
|
+
POLLER_FACT=$PRIVATE_ROOT/telegram-poller-count.json
|
|
102
|
+
CONTAINER_INSPECT_FACT=$PRIVATE_ROOT/container-inspect.json
|
|
103
|
+
|
|
104
|
+
start_broker() {
|
|
105
|
+
/usr/bin/timeout -s KILL 20 /usr/bin/docker run --rm --pull=never --network none \
|
|
106
|
+
--entrypoint /bin/cat "$IMAGE_ID" /opt/ouro/deploy/unraid/sanctuary-deployment-target.mjs >"$TARGET_AUDITOR"
|
|
107
|
+
/usr/bin/timeout -s KILL 20 /usr/bin/docker run --rm --pull=never --network none \
|
|
108
|
+
--entrypoint /bin/cat "$IMAGE_ID" /opt/ouro/deploy/unraid/sanctuary-unit16-host-broker.mjs >"$BROKER_PROGRAM"
|
|
109
|
+
chmod 0500 "$BROKER_PROGRAM" "$TARGET_AUDITOR"
|
|
110
|
+
chown 0:0 "$BROKER_PROGRAM" "$TARGET_AUDITOR"
|
|
111
|
+
/usr/local/bin/node "$TARGET_AUDITOR" "$TARGET_PROFILE" "$IMAGE_ID" >"$PRIVATE_ROOT/deployment-target.json"
|
|
112
|
+
chmod 0400 "$PRIVATE_ROOT/deployment-target.json"
|
|
113
|
+
chown 0:0 "$PRIVATE_ROOT/deployment-target.json"
|
|
114
|
+
TARGET_CONTAINER_ID=$(/usr/local/bin/node -e '
|
|
115
|
+
const fs = require("node:fs"); const value = JSON.parse(fs.readFileSync(process.argv[1], "utf8")); const deployment = value && value.deployment;
|
|
116
|
+
if (value?.schemaVersion !== "sanctuary-effective-deployment-v1" || deployment?.schemaVersion !== "sanctuary-deployment-target-v1"
|
|
117
|
+
|| deployment.profile !== "staging" || deployment.targetContainerName !== "ouro-butler-staging"
|
|
118
|
+
|| deployment.targetImageId !== process.argv[2] || !/^[0-9a-f]{64}$/.test(deployment.targetContainerId)) process.exit(1);
|
|
119
|
+
process.stdout.write(deployment.targetContainerId);
|
|
120
|
+
' "$PRIVATE_ROOT/deployment-target.json" "$IMAGE_ID")
|
|
121
|
+
test -n "$TARGET_CONTAINER_ID" || return 1
|
|
122
|
+
/usr/local/bin/node "$BROKER_PROGRAM" "$TARGET_PROFILE" "$TARGET_CONTAINER_ID" "$BROKER_SOCKET" "$CLOSED_INVENTORY" "$IMAGE_ID" "$BROKER_SNAPSHOT" </dev/null >/dev/null 2>&1 &
|
|
123
|
+
BROKER_PID=$!
|
|
124
|
+
ATTEMPT=0
|
|
125
|
+
while test "$ATTEMPT" -lt 600 && { test ! -S "$BROKER_SOCKET" || test ! -f "$CLOSED_INVENTORY" || test ! -f "$BROKER_SNAPSHOT"; }; do
|
|
126
|
+
kill -0 "$BROKER_PID" 2>/dev/null || return 1
|
|
127
|
+
ATTEMPT=$((ATTEMPT + 1))
|
|
128
|
+
sleep 0.1
|
|
129
|
+
done
|
|
130
|
+
test -S "$BROKER_SOCKET" || return 1
|
|
131
|
+
test "$(stat -c '%u:%g %a' "$BROKER_SOCKET")" = "0:10001 660" || return 1
|
|
132
|
+
test "$(stat -c '%u:%g %a' "$CLOSED_INVENTORY")" = "0:0 600" || return 1
|
|
133
|
+
test "$(stat -c '%u:%g %a' "$BROKER_SNAPSHOT")" = "0:0 600" || return 1
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
prepare_live_facts() {
|
|
137
|
+
install -m 0444 -o 0 -g 0 "$BROKER_SNAPSHOT" "$CONTAINER_INSPECT_FACT"
|
|
138
|
+
/usr/local/bin/node -e '
|
|
139
|
+
const fs = require("node:fs");
|
|
140
|
+
const value = JSON.parse(fs.readFileSync(process.argv[1], "utf8"));
|
|
141
|
+
const expectedKeys = ["autostartExact", "containerId", "health", "imageId", "liveProcessUser", "manualAuthRequired", "mountCount", "mountsDigest", "mountsExact", "networkMode", "processBindingDigest", "publishedPortCount", "readOnlyRoot", "recoveryMilestones", "restartCount", "restartPolicy", "running", "schemaVersion", "securityExact", "updaterDisabled", "user", "vaultUnlocked", "writableKeyExposure"];
|
|
142
|
+
if (JSON.stringify(Object.keys(value).sort()) !== JSON.stringify(expectedKeys) || value.schemaVersion !== 1
|
|
143
|
+
|| value.imageId !== process.argv[2] || !/^[0-9a-f]{64}$/.test(value.containerId)
|
|
144
|
+
|| value.liveProcessUser !== "10001:10001" || !/^[0-9a-f]{64}$/.test(value.processBindingDigest)
|
|
145
|
+
|| !/^[0-9a-f]{64}$/.test(value.mountsDigest) || !Number.isSafeInteger(value.restartCount) || value.restartCount < 0
|
|
146
|
+
|| typeof value.autostartExact !== "boolean" || typeof value.updaterDisabled !== "boolean"
|
|
147
|
+
|| typeof value.vaultUnlocked !== "boolean" || typeof value.manualAuthRequired !== "boolean"
|
|
148
|
+
|| typeof value.mountsExact !== "boolean" || typeof value.securityExact !== "boolean" || typeof value.writableKeyExposure !== "boolean") process.exit(1);
|
|
149
|
+
const milestones = value.recoveryMilestones;
|
|
150
|
+
if (!milestones || JSON.stringify(Object.keys(milestones).sort()) !== JSON.stringify(["arrayReady", "butlerReady", "dockerReady", "hostReady", "sshReady", "tailscaleReady"])
|
|
151
|
+
|| !Object.values(milestones).every((entry) => typeof entry === "boolean")) process.exit(1);
|
|
152
|
+
fs.writeFileSync(process.argv[3], `${value.imageId.slice("sha256:".length)}\n`);
|
|
153
|
+
fs.writeFileSync(process.argv[4], `${value.containerId}\n`);
|
|
154
|
+
fs.writeFileSync(process.argv[5], `${JSON.stringify({ healthy: value.health === "healthy" })}\n`);
|
|
155
|
+
fs.writeFileSync(process.argv[6], `${value.processBindingDigest}\n`);
|
|
156
|
+
' "$CONTAINER_INSPECT_FACT" "$IMAGE_ID" "$IMAGE_FACT" "$CONTAINER_FACT" "$HEALTH_FACT" "$PROCESS_BINDING_FACT"
|
|
157
|
+
chmod 0444 "$IMAGE_FACT" "$CONTAINER_FACT" "$PROCESS_BINDING_FACT" "$HEALTH_FACT" "$CONTAINER_INSPECT_FACT"
|
|
158
|
+
chown 0:0 "$IMAGE_FACT" "$CONTAINER_FACT" "$PROCESS_BINDING_FACT" "$HEALTH_FACT" "$CONTAINER_INSPECT_FACT"
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
refresh_live_facts() {
|
|
162
|
+
REFRESHED_SNAPSHOT=$PRIVATE_ROOT/broker-container-inspect.refresh.json
|
|
163
|
+
rm -f -- "$REFRESHED_SNAPSHOT"
|
|
164
|
+
/usr/bin/timeout -s KILL 60 /usr/local/bin/node -e '
|
|
165
|
+
const fs = require("node:fs");
|
|
166
|
+
const net = require("node:net");
|
|
167
|
+
const [socketPath, outputPath] = process.argv.slice(1);
|
|
168
|
+
const socket = net.createConnection(socketPath);
|
|
169
|
+
let response = "";
|
|
170
|
+
socket.setEncoding("utf8");
|
|
171
|
+
socket.on("connect", () => socket.end(JSON.stringify({ operation: "container_snapshot", targetId: "sanctuary" })));
|
|
172
|
+
socket.on("data", (chunk) => {
|
|
173
|
+
response += chunk;
|
|
174
|
+
if (Buffer.byteLength(response) > 1024 * 1024) socket.destroy(new Error("container snapshot response exceeds its bound"));
|
|
175
|
+
});
|
|
176
|
+
socket.on("end", () => {
|
|
177
|
+
const envelope = JSON.parse(response);
|
|
178
|
+
if (!envelope || envelope.ok !== true || !envelope.result || typeof envelope.result !== "object" || Array.isArray(envelope.result)) process.exit(1);
|
|
179
|
+
fs.writeFileSync(outputPath, `${JSON.stringify(envelope.result)}\n`, { flag: "wx", mode: 0o600 });
|
|
180
|
+
});
|
|
181
|
+
socket.on("error", () => process.exit(1));
|
|
182
|
+
' "$BROKER_SOCKET" "$REFRESHED_SNAPSHOT"
|
|
183
|
+
test "$(stat -c '%u:%g %a' "$REFRESHED_SNAPSHOT")" = "0:0 600" || return 1
|
|
184
|
+
mv -f -- "$REFRESHED_SNAPSHOT" "$BROKER_SNAPSHOT"
|
|
185
|
+
prepare_live_facts
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
restore_production_container() {
|
|
189
|
+
EXPECTED_CONTAINER_ID=$(cat "$CONTAINER_FACT") || return 1
|
|
190
|
+
test "$EXPECTED_CONTAINER_ID" = "$TARGET_CONTAINER_ID" || return 1
|
|
191
|
+
test "$(/usr/bin/timeout -s KILL 20 /usr/bin/docker inspect --format '{{.Id}}' "$EXPECTED_CONTAINER_ID")" = "$EXPECTED_CONTAINER_ID" || return 1
|
|
192
|
+
test "$(/usr/bin/timeout -s KILL 20 /usr/bin/docker inspect --format '{{.Name}}' "$EXPECTED_CONTAINER_ID")" = "/$PRODUCTION_CONTAINER" || return 1
|
|
193
|
+
test "$(/usr/bin/timeout -s KILL 20 /usr/bin/docker inspect --format '{{.Image}}' "$EXPECTED_CONTAINER_ID")" = "$IMAGE_ID" || return 1
|
|
194
|
+
if test "$(/usr/bin/timeout -s KILL 20 /usr/bin/docker inspect --format '{{.State.Running}}' "$EXPECTED_CONTAINER_ID")" = false; then
|
|
195
|
+
/usr/bin/timeout -s KILL 30 /usr/bin/docker start "$EXPECTED_CONTAINER_ID" >/dev/null || return 1
|
|
196
|
+
fi
|
|
197
|
+
RESTORE_ATTEMPT=0
|
|
198
|
+
while test "$RESTORE_ATTEMPT" -lt 120; do
|
|
199
|
+
test "$(/usr/bin/timeout -s KILL 20 /usr/bin/docker inspect --format '{{.Id}}' "$EXPECTED_CONTAINER_ID")" = "$EXPECTED_CONTAINER_ID" || return 1
|
|
200
|
+
RESTORE_RUNNING=$(/usr/bin/timeout -s KILL 20 /usr/bin/docker inspect --format '{{.State.Running}}' "$EXPECTED_CONTAINER_ID") || return 1
|
|
201
|
+
RESTORE_HEALTH=$(/usr/bin/timeout -s KILL 20 /usr/bin/docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}missing{{end}}' "$EXPECTED_CONTAINER_ID") || return 1
|
|
202
|
+
if test "$RESTORE_RUNNING" = true && test "$RESTORE_HEALTH" = healthy; then return 0; fi
|
|
203
|
+
RESTORE_ATTEMPT=$((RESTORE_ATTEMPT + 1))
|
|
204
|
+
sleep 1
|
|
205
|
+
done
|
|
206
|
+
return 1
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
stop_exact_production_container() {
|
|
210
|
+
EXPECTED_CONTAINER_ID=$(cat "$CONTAINER_FACT") || return 1
|
|
211
|
+
test "$EXPECTED_CONTAINER_ID" = "$TARGET_CONTAINER_ID" || return 1
|
|
212
|
+
test "$(/usr/bin/timeout -s KILL 20 /usr/bin/docker inspect --format '{{.Id}}' "$EXPECTED_CONTAINER_ID")" = "$EXPECTED_CONTAINER_ID" || return 1
|
|
213
|
+
test "$(/usr/bin/timeout -s KILL 20 /usr/bin/docker inspect --format '{{.Name}}' "$EXPECTED_CONTAINER_ID")" = "/$PRODUCTION_CONTAINER" || return 1
|
|
214
|
+
test "$(/usr/bin/timeout -s KILL 20 /usr/bin/docker inspect --format '{{.Image}}' "$EXPECTED_CONTAINER_ID")" = "$IMAGE_ID" || return 1
|
|
215
|
+
test "$(/usr/bin/timeout -s KILL 20 /usr/bin/docker inspect --format '{{.State.Running}}' "$EXPECTED_CONTAINER_ID")" = true || return 1
|
|
216
|
+
test "$(/usr/bin/timeout -s KILL 20 /usr/bin/docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}missing{{end}}' "$EXPECTED_CONTAINER_ID")" = healthy || return 1
|
|
217
|
+
PRODUCTION_STOPPED=yes
|
|
218
|
+
/usr/bin/timeout -s KILL 45 /usr/bin/docker stop --time 30 "$EXPECTED_CONTAINER_ID" >/dev/null || true
|
|
219
|
+
test "$(/usr/bin/timeout -s KILL 20 /usr/bin/docker inspect --format '{{.Id}}' "$EXPECTED_CONTAINER_ID")" = "$EXPECTED_CONTAINER_ID" || return 1
|
|
220
|
+
test "$(/usr/bin/timeout -s KILL 20 /usr/bin/docker inspect --format '{{.Image}}' "$EXPECTED_CONTAINER_ID")" = "$IMAGE_ID" || return 1
|
|
221
|
+
test "$(/usr/bin/timeout -s KILL 20 /usr/bin/docker inspect --format '{{.State.Running}}' "$EXPECTED_CONTAINER_ID")" = false || return 1
|
|
222
|
+
test "$(/usr/bin/timeout -s KILL 20 /usr/bin/docker inspect --format '{{.State.Pid}}' "$EXPECTED_CONTAINER_ID")" = 0 || return 1
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
quiesce_production_telegram_poller() {
|
|
226
|
+
stop_exact_production_container
|
|
227
|
+
printf '%s\n' '{"activePollers":0,"productionContainerStopped":true}' >"$POLLER_FACT"
|
|
228
|
+
chmod 0444 "$POLLER_FACT"
|
|
229
|
+
chown 0:0 "$POLLER_FACT"
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
materialize_config() {
|
|
233
|
+
OUTPUT=$1
|
|
234
|
+
SNAPSHOT_PHASE=${2:-}
|
|
235
|
+
EXTRA_MOUNT=
|
|
236
|
+
if test "$COMMAND" = unraid-key-rotate; then
|
|
237
|
+
test -f "$CLOSED_INVENTORY" || return 1
|
|
238
|
+
install -m 0400 -o 10001 -g 10001 "$CLOSED_INVENTORY" "$PRIVATE_ROOT/container-inventory.json"
|
|
239
|
+
EXTRA_MOUNT=$PRIVATE_ROOT/container-inventory.json
|
|
240
|
+
fi
|
|
241
|
+
if test -n "$EXTRA_MOUNT"; then
|
|
242
|
+
/usr/bin/timeout -s KILL 30 /usr/bin/docker run --rm --pull=never --network none \
|
|
243
|
+
--user 10001:10001 --read-only \
|
|
244
|
+
--mount "type=bind,src=$EVIDENCE_ROOT,dst=/evidence,readonly" \
|
|
245
|
+
--mount "type=bind,src=$EXTRA_MOUNT,dst=/run/ouro-acceptance/closed-inventory.json,readonly" \
|
|
246
|
+
--mount "type=bind,src=$RUNTIME_ROOT,dst=/home/ouro/.ouro-cli,readonly" \
|
|
247
|
+
--mount "type=bind,src=$BUNDLE_ROOT,dst=/home/ouro/AgentBundles/sanctuary.ouro,readonly" \
|
|
248
|
+
--entrypoint /opt/ouro/deploy/unraid/sanctuary-acceptance-adapter.sh \
|
|
249
|
+
"$IMAGE_ID" materialize-config "$COMMAND" >"$OUTPUT"
|
|
250
|
+
elif test -n "$SNAPSHOT_PHASE"; then
|
|
251
|
+
/usr/bin/timeout -s KILL 30 /usr/bin/docker run --rm --pull=never --network none \
|
|
252
|
+
--user 10001:10001 --read-only \
|
|
253
|
+
--mount "type=bind,src=$EVIDENCE_ROOT,dst=/evidence,readonly" \
|
|
254
|
+
--mount "type=bind,src=$RUNTIME_ROOT,dst=/home/ouro/.ouro-cli,readonly" \
|
|
255
|
+
--mount "type=bind,src=$BUNDLE_ROOT,dst=/home/ouro/AgentBundles/sanctuary.ouro,readonly" \
|
|
256
|
+
--entrypoint /opt/ouro/deploy/unraid/sanctuary-acceptance-adapter.sh \
|
|
257
|
+
"$IMAGE_ID" materialize-config "$COMMAND" "$SNAPSHOT_PHASE" >"$OUTPUT"
|
|
258
|
+
else
|
|
259
|
+
/usr/bin/timeout -s KILL 30 /usr/bin/docker run --rm --pull=never --network none \
|
|
260
|
+
--user 10001:10001 --read-only \
|
|
261
|
+
--mount "type=bind,src=$EVIDENCE_ROOT,dst=/evidence,readonly" \
|
|
262
|
+
--mount "type=bind,src=$RUNTIME_ROOT,dst=/home/ouro/.ouro-cli,readonly" \
|
|
263
|
+
--mount "type=bind,src=$BUNDLE_ROOT,dst=/home/ouro/AgentBundles/sanctuary.ouro,readonly" \
|
|
264
|
+
--entrypoint /opt/ouro/deploy/unraid/sanctuary-acceptance-adapter.sh \
|
|
265
|
+
"$IMAGE_ID" materialize-config "$COMMAND" >"$OUTPUT"
|
|
266
|
+
fi
|
|
267
|
+
/usr/local/bin/node -e '
|
|
268
|
+
const fs = require("node:fs");
|
|
269
|
+
const value = JSON.parse(fs.readFileSync(process.argv[1], "utf8"));
|
|
270
|
+
if (!value || value.allowedRoot !== "/evidence") process.exit(1);
|
|
271
|
+
' "$OUTPUT"
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if test "$MODE" = materialize; then
|
|
275
|
+
CONFIG_NAME=$COMMAND.json
|
|
276
|
+
if test "$COMMAND" = unraid-key-rotate; then start_broker; fi
|
|
277
|
+
CONFIG_TMP=$(mktemp "$CONFIG_ROOT/.$CONFIG_NAME.tmp.XXXXXX")
|
|
278
|
+
materialize_config "$CONFIG_TMP" "${PHASE:-}"
|
|
279
|
+
install -m 0600 -o 10001 -g 10001 "$CONFIG_TMP" "$CONFIG_ROOT/$CONFIG_NAME"
|
|
280
|
+
sync -f "$CONFIG_ROOT/$CONFIG_NAME"
|
|
281
|
+
sync -f "$CONFIG_ROOT"
|
|
282
|
+
rm -f -- "$CONFIG_TMP"
|
|
283
|
+
exit 0
|
|
284
|
+
fi
|
|
285
|
+
|
|
286
|
+
test "$CONFIG_NAME" = "$COMMAND.json" || exit 2
|
|
287
|
+
case "$CONFIG_NAME" in *[!A-Za-z0-9._-]*) exit 2 ;; esac
|
|
288
|
+
CONFIG_PATH=$CONFIG_ROOT/$CONFIG_NAME
|
|
289
|
+
test -f "$CONFIG_PATH" && test ! -L "$CONFIG_PATH" || exit 1
|
|
290
|
+
test "$(stat -c '%u:%g %a' "$CONFIG_PATH")" = "10001:10001 600" || exit 1
|
|
291
|
+
|
|
292
|
+
start_broker
|
|
293
|
+
EXPECTED_CONFIG=$PRIVATE_ROOT/expected-config.json
|
|
294
|
+
SNAPSHOT_PHASE=
|
|
295
|
+
if test "$COMMAND" = cursor-snapshot; then
|
|
296
|
+
SNAPSHOT_PHASE=$(/usr/local/bin/node -e '
|
|
297
|
+
const fs = require("node:fs"); const value = JSON.parse(fs.readFileSync(process.argv[1], "utf8"));
|
|
298
|
+
if (value.evidencePath === "/evidence/cursor-before.json") process.stdout.write("before");
|
|
299
|
+
else if (value.evidencePath === "/evidence/cursor-after.json") process.stdout.write("after");
|
|
300
|
+
else process.exit(1);
|
|
301
|
+
' "$CONFIG_PATH")
|
|
302
|
+
fi
|
|
303
|
+
materialize_config "$EXPECTED_CONFIG" "$SNAPSHOT_PHASE"
|
|
304
|
+
cmp -s "$EXPECTED_CONFIG" "$CONFIG_PATH" || exit 1
|
|
305
|
+
case "$COMMAND" in telegram-bootstrap|callback-inject) test -r /proc/self/fd/3 || exit 2 ;; esac
|
|
306
|
+
prepare_live_facts
|
|
307
|
+
if test "$COMMAND" = telegram-bootstrap; then quiesce_production_telegram_poller; fi
|
|
308
|
+
|
|
309
|
+
case "$COMMAND" in
|
|
310
|
+
telegram-bootstrap) TIME_LIMIT=900; NETWORK=host; INPUT=yes; BUNDLE_MODE=readonly; BROKER=no ;;
|
|
311
|
+
callback-inject) TIME_LIMIT=120; NETWORK=host; INPUT=yes; BUNDLE_MODE=rw; BROKER=no ;;
|
|
312
|
+
unraid-key-rotate) TIME_LIMIT=600; NETWORK=host; INPUT=no; BUNDLE_MODE=readonly; BROKER=yes ;;
|
|
313
|
+
evidence-snapshot) TIME_LIMIT=4950; NETWORK=host; INPUT=no; BUNDLE_MODE=readonly; BROKER=yes ;;
|
|
314
|
+
reboot-request) TIME_LIMIT=300; NETWORK=none; INPUT=no; BUNDLE_MODE=readonly; BROKER=yes ;;
|
|
315
|
+
reboot-resume) TIME_LIMIT=780; NETWORK=host; INPUT=no; BUNDLE_MODE=readonly; BROKER=yes ;;
|
|
316
|
+
*) TIME_LIMIT=120; NETWORK=none; INPUT=no; BUNDLE_MODE=readonly; BROKER=no ;;
|
|
317
|
+
esac
|
|
318
|
+
|
|
319
|
+
assert_acceptance_state_inode() {
|
|
320
|
+
ACCEPTANCE_PIN_INODE=$(stat -Lc '%d:%i' "$ACCEPTANCE_PIN_ROOT") || return 1
|
|
321
|
+
test "$(stat -Lc '%d:%i' "$ACCEPTANCE_STATE_ROOT")" = "$ACCEPTANCE_PIN_INODE" || return 1
|
|
322
|
+
test "$(/usr/bin/timeout -s KILL 20 /usr/bin/docker inspect --format '{{.Name}} {{.Image}}' "$TARGET_CONTAINER_ID")" = "/$PRODUCTION_CONTAINER $IMAGE_ID" || return 1
|
|
323
|
+
test "$(/usr/bin/timeout -s KILL 20 /usr/bin/docker exec "$TARGET_CONTAINER_ID" stat -Lc '%d:%i' /home/ouro/AgentBundles/sanctuary.ouro/state/acceptance)" = "$ACCEPTANCE_PIN_INODE" || return 1
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
if test "$COMMAND" = evidence-snapshot || test "$COMMAND" = reboot-request || test "$COMMAND" = reboot-resume; then
|
|
327
|
+
stop_exact_production_container
|
|
328
|
+
BUNDLE_STATE_ROOT=$BUNDLE_ROOT/state
|
|
329
|
+
test -d "$BUNDLE_STATE_ROOT" && test ! -L "$BUNDLE_STATE_ROOT" || exit 1
|
|
330
|
+
test "$(stat -c '%u:%g %a' "$BUNDLE_STATE_ROOT")" = "10001:10001 700" || exit 1
|
|
331
|
+
ACCEPTANCE_STATE_ROOT=$BUNDLE_ROOT/state/acceptance
|
|
332
|
+
if test ! -e "$ACCEPTANCE_STATE_ROOT"; then
|
|
333
|
+
install -d -m 0700 -o 10001 -g 10001 "$ACCEPTANCE_STATE_ROOT"
|
|
334
|
+
fi
|
|
335
|
+
test -d "$ACCEPTANCE_STATE_ROOT" && test ! -L "$ACCEPTANCE_STATE_ROOT" || exit 1
|
|
336
|
+
test "$(stat -c '%u:%g %a' "$ACCEPTANCE_STATE_ROOT")" = "10001:10001 700" || exit 1
|
|
337
|
+
ACCEPTANCE_PIN_ROOT=$PRIVATE_ROOT/pinned-acceptance-state
|
|
338
|
+
install -d -m 0700 -o 0 -g 0 "$ACCEPTANCE_PIN_ROOT"
|
|
339
|
+
! /bin/mountpoint -q "$ACCEPTANCE_PIN_ROOT" || exit 1
|
|
340
|
+
! /bin/mountpoint -q "$ACCEPTANCE_STATE_ROOT" || exit 1
|
|
341
|
+
ACCEPTANCE_ALIAS_MOUNTED=yes
|
|
342
|
+
/usr/bin/timeout -s KILL 20 /usr/local/bin/node -e '
|
|
343
|
+
const { spawnSync } = require("node:child_process");
|
|
344
|
+
const { closeSync, constants, fstatSync, openSync } = require("node:fs");
|
|
345
|
+
const [sourcePath, target] = process.argv.slice(1);
|
|
346
|
+
const source = openSync(sourcePath, constants.O_RDONLY | constants.O_DIRECTORY | constants.O_NOFOLLOW);
|
|
347
|
+
try {
|
|
348
|
+
const metadata = fstatSync(source);
|
|
349
|
+
if (!metadata.isDirectory() || metadata.uid !== 10001 || (metadata.mode & 0o777) !== 0o700) process.exit(1);
|
|
350
|
+
const result = spawnSync("/bin/mount", ["--bind", "/proc/self/fd/3", target], {
|
|
351
|
+
cwd: "/", timeout: 10_000, env: { PATH: "/usr/sbin:/usr/bin:/sbin:/bin" },
|
|
352
|
+
stdio: ["ignore", "ignore", "ignore", source],
|
|
353
|
+
});
|
|
354
|
+
if (result.error || result.status !== 0) process.exit(1);
|
|
355
|
+
} finally { closeSync(source); }
|
|
356
|
+
' "$ACCEPTANCE_STATE_ROOT" "$ACCEPTANCE_PIN_ROOT"
|
|
357
|
+
ACCEPTANCE_CANONICAL_PINNED=yes
|
|
358
|
+
/usr/bin/timeout -s KILL 10 /bin/mount --bind "$ACCEPTANCE_PIN_ROOT" "$ACCEPTANCE_STATE_ROOT"
|
|
359
|
+
restore_production_container
|
|
360
|
+
PRODUCTION_STOPPED=no
|
|
361
|
+
refresh_live_facts
|
|
362
|
+
assert_acceptance_state_inode
|
|
363
|
+
fi
|
|
364
|
+
|
|
365
|
+
run_harness() {
|
|
366
|
+
if test "$BUNDLE_MODE" = rw; then BUNDLE_SUFFIX=; else BUNDLE_SUFFIX=,readonly; fi
|
|
367
|
+
if test "$COMMAND" = telegram-bootstrap; then
|
|
368
|
+
/usr/bin/timeout -s KILL "$TIME_LIMIT" /usr/bin/docker run --rm -i --pull=never --network "$NETWORK" \
|
|
369
|
+
--user 10001:10001 --read-only --cap-drop ALL --security-opt no-new-privileges \
|
|
370
|
+
--mount "type=bind,src=$CONFIG_PATH,dst=/run/ouro-acceptance/config.json,readonly" \
|
|
371
|
+
--mount "type=bind,src=$EVIDENCE_ROOT,dst=/evidence" \
|
|
372
|
+
--mount "type=bind,src=$RUNTIME_ROOT,dst=/home/ouro/.ouro-cli,readonly" \
|
|
373
|
+
--mount "type=bind,src=$BUNDLE_ROOT,dst=/home/ouro/AgentBundles/sanctuary.ouro$BUNDLE_SUFFIX" \
|
|
374
|
+
--mount "type=bind,src=$POLLER_FACT,dst=/run/ouro-acceptance/telegram-poller-count.json,readonly" \
|
|
375
|
+
--mount "type=bind,src=$IMAGE_FACT,dst=/run/ouro-acceptance/image-digest,readonly" \
|
|
376
|
+
--mount "type=bind,src=$CONTAINER_FACT,dst=/run/ouro-acceptance/container-digest,readonly" \
|
|
377
|
+
--mount "type=bind,src=$PROCESS_BINDING_FACT,dst=/run/ouro-acceptance/process-binding-digest,readonly" \
|
|
378
|
+
--mount "type=bind,src=$HEALTH_FACT,dst=/run/ouro-acceptance/postboot-health.json,readonly" \
|
|
379
|
+
--mount "type=bind,src=$CONTAINER_INSPECT_FACT,dst=/run/ouro-acceptance/container-inspect.json,readonly" \
|
|
380
|
+
--mount "type=bind,src=/proc/sys/kernel/random/boot_id,dst=/run/ouro-acceptance/boot-id,readonly" \
|
|
381
|
+
--entrypoint /bin/sh "$IMAGE_ID" -ceu \
|
|
382
|
+
'exec 3<&0; exec /opt/ouro/deploy/unraid/sanctuary-acceptance-harness.sh "$@" 3<&3' \
|
|
383
|
+
sanctuary-unit16 "$COMMAND" --config /run/ouro-acceptance/config.json <&3
|
|
384
|
+
elif test "$COMMAND" = callback-inject; then
|
|
385
|
+
/usr/bin/timeout -s KILL "$TIME_LIMIT" /usr/bin/docker run --rm -i --pull=never --network "$NETWORK" \
|
|
386
|
+
--user 10001:10001 --read-only --cap-drop ALL --security-opt no-new-privileges \
|
|
387
|
+
--mount "type=bind,src=$CONFIG_PATH,dst=/run/ouro-acceptance/config.json,readonly" \
|
|
388
|
+
--mount "type=bind,src=$EVIDENCE_ROOT,dst=/evidence" \
|
|
389
|
+
--mount "type=bind,src=$RUNTIME_ROOT,dst=/home/ouro/.ouro-cli,readonly" \
|
|
390
|
+
--mount "type=bind,src=$BUNDLE_ROOT,dst=/home/ouro/AgentBundles/sanctuary.ouro$BUNDLE_SUFFIX" \
|
|
391
|
+
--mount "type=bind,src=$IMAGE_FACT,dst=/run/ouro-acceptance/image-digest,readonly" \
|
|
392
|
+
--mount "type=bind,src=$CONTAINER_FACT,dst=/run/ouro-acceptance/container-digest,readonly" \
|
|
393
|
+
--mount "type=bind,src=$HEALTH_FACT,dst=/run/ouro-acceptance/postboot-health.json,readonly" \
|
|
394
|
+
--mount "type=bind,src=$CONTAINER_INSPECT_FACT,dst=/run/ouro-acceptance/container-inspect.json,readonly" \
|
|
395
|
+
--mount "type=bind,src=/proc/sys/kernel/random/boot_id,dst=/run/ouro-acceptance/boot-id,readonly" \
|
|
396
|
+
--entrypoint /bin/sh "$IMAGE_ID" -ceu \
|
|
397
|
+
'exec 3<&0; exec /opt/ouro/deploy/unraid/sanctuary-acceptance-harness.sh "$@" 3<&3' \
|
|
398
|
+
sanctuary-unit16 "$COMMAND" --config /run/ouro-acceptance/config.json <&3
|
|
399
|
+
elif test "$COMMAND" = evidence-snapshot; then
|
|
400
|
+
/usr/bin/timeout -s KILL "$TIME_LIMIT" /usr/bin/docker run --rm --pull=never --network "$NETWORK" \
|
|
401
|
+
--user 10001:10001 --read-only --cap-drop ALL --security-opt no-new-privileges \
|
|
402
|
+
--mount "type=bind,src=$CONFIG_PATH,dst=/run/ouro-acceptance/config.json,readonly" \
|
|
403
|
+
--mount "type=bind,src=$EVIDENCE_ROOT,dst=/evidence" \
|
|
404
|
+
--mount "type=bind,src=$RUNTIME_ROOT,dst=/home/ouro/.ouro-cli,readonly" \
|
|
405
|
+
--mount "type=bind,src=$BUNDLE_ROOT,dst=/home/ouro/AgentBundles/sanctuary.ouro,readonly" \
|
|
406
|
+
--mount "type=bind,src=$ACCEPTANCE_PIN_ROOT,dst=/home/ouro/AgentBundles/sanctuary.ouro/state/acceptance" \
|
|
407
|
+
--mount "type=bind,src=$SOCKET_ROOT,dst=/run/ouro-host-acceptance,readonly" \
|
|
408
|
+
--mount "type=bind,src=$IMAGE_FACT,dst=/run/ouro-acceptance/image-digest,readonly" \
|
|
409
|
+
--mount "type=bind,src=$CONTAINER_FACT,dst=/run/ouro-acceptance/container-digest,readonly" \
|
|
410
|
+
--mount "type=bind,src=$PROCESS_BINDING_FACT,dst=/run/ouro-acceptance/process-binding-digest,readonly" \
|
|
411
|
+
--mount "type=bind,src=$HEALTH_FACT,dst=/run/ouro-acceptance/postboot-health.json,readonly" \
|
|
412
|
+
--mount "type=bind,src=$CONTAINER_INSPECT_FACT,dst=/run/ouro-acceptance/container-inspect.json,readonly" \
|
|
413
|
+
--mount "type=bind,src=/proc/sys/kernel/random/boot_id,dst=/run/ouro-acceptance/boot-id,readonly" \
|
|
414
|
+
--entrypoint /opt/ouro/deploy/unraid/sanctuary-acceptance-harness.sh \
|
|
415
|
+
"$IMAGE_ID" "$COMMAND" --config /run/ouro-acceptance/config.json
|
|
416
|
+
elif test "$BROKER" = yes; then
|
|
417
|
+
if test "$COMMAND" = reboot-request || test "$COMMAND" = reboot-resume; then ACCEPTANCE_MOUNT="--mount type=bind,src=$ACCEPTANCE_PIN_ROOT,dst=/home/ouro/AgentBundles/sanctuary.ouro/state/acceptance"; else ACCEPTANCE_MOUNT=; fi
|
|
418
|
+
/usr/bin/timeout -s KILL "$TIME_LIMIT" /usr/bin/docker run --rm --pull=never --network "$NETWORK" \
|
|
419
|
+
--user 10001:10001 --read-only --cap-drop ALL --security-opt no-new-privileges \
|
|
420
|
+
--mount "type=bind,src=$CONFIG_PATH,dst=/run/ouro-acceptance/config.json,readonly" \
|
|
421
|
+
--mount "type=bind,src=$EVIDENCE_ROOT,dst=/evidence" \
|
|
422
|
+
--mount "type=bind,src=$RUNTIME_ROOT,dst=/home/ouro/.ouro-cli,readonly" \
|
|
423
|
+
--mount "type=bind,src=$BUNDLE_ROOT,dst=/home/ouro/AgentBundles/sanctuary.ouro$BUNDLE_SUFFIX" \
|
|
424
|
+
$ACCEPTANCE_MOUNT \
|
|
425
|
+
--mount "type=bind,src=$SOCKET_ROOT,dst=/run/ouro-host-acceptance,readonly" \
|
|
426
|
+
--mount "type=bind,src=$IMAGE_FACT,dst=/run/ouro-acceptance/image-digest,readonly" \
|
|
427
|
+
--mount "type=bind,src=$CONTAINER_FACT,dst=/run/ouro-acceptance/container-digest,readonly" \
|
|
428
|
+
--mount "type=bind,src=$PROCESS_BINDING_FACT,dst=/run/ouro-acceptance/process-binding-digest,readonly" \
|
|
429
|
+
--mount "type=bind,src=$HEALTH_FACT,dst=/run/ouro-acceptance/postboot-health.json,readonly" \
|
|
430
|
+
--mount "type=bind,src=$CONTAINER_INSPECT_FACT,dst=/run/ouro-acceptance/container-inspect.json,readonly" \
|
|
431
|
+
--mount "type=bind,src=/proc/sys/kernel/random/boot_id,dst=/run/ouro-acceptance/boot-id,readonly" \
|
|
432
|
+
--entrypoint /opt/ouro/deploy/unraid/sanctuary-acceptance-harness.sh \
|
|
433
|
+
"$IMAGE_ID" "$COMMAND" --config /run/ouro-acceptance/config.json
|
|
434
|
+
else
|
|
435
|
+
/usr/bin/timeout -s KILL "$TIME_LIMIT" /usr/bin/docker run --rm --pull=never --network "$NETWORK" \
|
|
436
|
+
--user 10001:10001 --read-only --cap-drop ALL --security-opt no-new-privileges \
|
|
437
|
+
--mount "type=bind,src=$CONFIG_PATH,dst=/run/ouro-acceptance/config.json,readonly" \
|
|
438
|
+
--mount "type=bind,src=$EVIDENCE_ROOT,dst=/evidence" \
|
|
439
|
+
--mount "type=bind,src=$RUNTIME_ROOT,dst=/home/ouro/.ouro-cli,readonly" \
|
|
440
|
+
--mount "type=bind,src=$BUNDLE_ROOT,dst=/home/ouro/AgentBundles/sanctuary.ouro$BUNDLE_SUFFIX" \
|
|
441
|
+
--mount "type=bind,src=$IMAGE_FACT,dst=/run/ouro-acceptance/image-digest,readonly" \
|
|
442
|
+
--mount "type=bind,src=$CONTAINER_FACT,dst=/run/ouro-acceptance/container-digest,readonly" \
|
|
443
|
+
--mount "type=bind,src=$HEALTH_FACT,dst=/run/ouro-acceptance/postboot-health.json,readonly" \
|
|
444
|
+
--mount "type=bind,src=$CONTAINER_INSPECT_FACT,dst=/run/ouro-acceptance/container-inspect.json,readonly" \
|
|
445
|
+
--mount "type=bind,src=/proc/sys/kernel/random/boot_id,dst=/run/ouro-acceptance/boot-id,readonly" \
|
|
446
|
+
--entrypoint /opt/ouro/deploy/unraid/sanctuary-acceptance-harness.sh \
|
|
447
|
+
"$IMAGE_ID" "$COMMAND" --config /run/ouro-acceptance/config.json
|
|
448
|
+
fi
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
run_harness
|
|
452
|
+
if test "$COMMAND" = evidence-snapshot || test "$COMMAND" = reboot-request || test "$COMMAND" = reboot-resume; then assert_acceptance_state_inode; fi
|
|
453
|
+
|
|
454
|
+
if test "$COMMAND" = reboot-request; then
|
|
455
|
+
/usr/local/bin/node -e '
|
|
456
|
+
const fs = require("node:fs"); const value = JSON.parse(fs.readFileSync(process.argv[1], "utf8"));
|
|
457
|
+
if (value.operation !== "reboot" || value.phase !== "requested" || !/^[0-9a-f]{64}$/.test(value.requestId)
|
|
458
|
+
|| !/^[0-9a-f]{64}$/.test(value.reservationId) || !/^[0-9a-f]{64}$/.test(value.processBindingDigest)) process.exit(1);
|
|
459
|
+
' "$EVIDENCE_ROOT/reboot.json"
|
|
460
|
+
PRODUCTION_STOPPED=yes
|
|
461
|
+
/usr/bin/timeout -s KILL 60 /usr/local/bin/node -e '
|
|
462
|
+
const fs = require("node:fs"); const net = require("node:net");
|
|
463
|
+
const checkpoint = JSON.parse(fs.readFileSync(process.argv[2], "utf8"));
|
|
464
|
+
const request = JSON.stringify({ operation: "stop_reboot_owner", targetId: "sanctuary", requestId: checkpoint.requestId, reservationId: checkpoint.reservationId, processBindingDigest: checkpoint.processBindingDigest });
|
|
465
|
+
let raw = ""; const socket = net.createConnection(process.argv[1]);
|
|
466
|
+
socket.setEncoding("utf8"); socket.setTimeout(55000, () => socket.destroy(new Error("timeout")));
|
|
467
|
+
socket.on("connect", () => socket.end(request));
|
|
468
|
+
socket.on("data", (chunk) => { raw += chunk; if (Buffer.byteLength(raw) > 65536) socket.destroy(new Error("oversize")); });
|
|
469
|
+
socket.on("end", () => {
|
|
470
|
+
const envelope = JSON.parse(raw); const result = envelope && envelope.ok === true ? envelope.result : null;
|
|
471
|
+
if (!result || result.stopped !== true || result.targetId !== "sanctuary" || result.requestId !== checkpoint.requestId
|
|
472
|
+
|| result.reservationId !== checkpoint.reservationId || result.processBindingDigest !== checkpoint.processBindingDigest) process.exitCode = 1;
|
|
473
|
+
});
|
|
474
|
+
socket.on("error", () => { process.exitCode = 1; });
|
|
475
|
+
' "$BROKER_SOCKET" "$EVIDENCE_ROOT/reboot.json"
|
|
476
|
+
sync -f "$EVIDENCE_ROOT/reboot.json"
|
|
477
|
+
sync -f "$EVIDENCE_ROOT"
|
|
478
|
+
HOST_REBOOT_COMMIT_STATE=attempting
|
|
479
|
+
/usr/bin/timeout -s KILL 20 /usr/local/bin/node -e '
|
|
480
|
+
const fs = require("node:fs"); const net = require("node:net");
|
|
481
|
+
const checkpoint = JSON.parse(fs.readFileSync(process.argv[2], "utf8"));
|
|
482
|
+
if (checkpoint.operation !== "reboot" || checkpoint.phase !== "requested"
|
|
483
|
+
|| !/^[0-9a-f]{64}$/.test(checkpoint.requestId) || !/^[0-9a-f]{64}$/.test(checkpoint.reservationId)) process.exit(1);
|
|
484
|
+
const request = JSON.stringify({ operation: "commit_reboot", targetId: "sanctuary", requestId: checkpoint.requestId, reservationId: checkpoint.reservationId, processBindingDigest: checkpoint.processBindingDigest });
|
|
485
|
+
let raw = ""; const socket = net.createConnection(process.argv[1]);
|
|
486
|
+
socket.setEncoding("utf8"); socket.setTimeout(15000, () => socket.destroy(new Error("timeout")));
|
|
487
|
+
socket.on("connect", () => socket.end(request));
|
|
488
|
+
socket.on("data", (chunk) => { raw += chunk; if (Buffer.byteLength(raw) > 65536) socket.destroy(new Error("oversize")); });
|
|
489
|
+
socket.on("end", () => {
|
|
490
|
+
const envelope = JSON.parse(raw); const result = envelope && envelope.ok === true ? envelope.result : null;
|
|
491
|
+
if (!result || result.committed !== true || result.targetId !== "sanctuary"
|
|
492
|
+
|| result.requestId !== checkpoint.requestId || result.reservationId !== checkpoint.reservationId
|
|
493
|
+
|| result.processBindingDigest !== checkpoint.processBindingDigest) process.exitCode = 1;
|
|
494
|
+
});
|
|
495
|
+
socket.on("error", () => { process.exitCode = 1; });
|
|
496
|
+
' "$BROKER_SOCKET" "$EVIDENCE_ROOT/reboot.json"
|
|
497
|
+
HOST_REBOOT_COMMIT_STATE=confirmed
|
|
498
|
+
cleanup_unit16
|
|
499
|
+
BROKER_PID=
|
|
500
|
+
PRIVATE_ROOT=
|
|
501
|
+
exit 0
|
|
502
|
+
fi
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
set -eu
|
|
3
|
+
|
|
4
|
+
IMAGE_ID=${1:-}
|
|
5
|
+
test "$#" -eq 1 || exit 2
|
|
6
|
+
IMAGE_DIGEST=${IMAGE_ID#sha256:}
|
|
7
|
+
test "$IMAGE_DIGEST" != "$IMAGE_ID" && test "${#IMAGE_DIGEST}" -eq 64 || exit 2
|
|
8
|
+
case "$IMAGE_DIGEST" in *[!0-9a-f]*) exit 2 ;; esac
|
|
9
|
+
|
|
10
|
+
AUDIT_ROOT=$(mktemp -d /run/ouro-unit18-target.XXXXXX)
|
|
11
|
+
AUDITOR=$AUDIT_ROOT/sanctuary-deployment-target.mjs
|
|
12
|
+
cleanup() {
|
|
13
|
+
STATUS=$?
|
|
14
|
+
rm -f -- "$AUDITOR"
|
|
15
|
+
rmdir -- "$AUDIT_ROOT" 2>/dev/null || STATUS=1
|
|
16
|
+
return "$STATUS"
|
|
17
|
+
}
|
|
18
|
+
trap cleanup EXIT
|
|
19
|
+
trap 'exit 129' HUP
|
|
20
|
+
trap 'exit 130' INT
|
|
21
|
+
trap 'exit 143' TERM
|
|
22
|
+
|
|
23
|
+
/usr/bin/timeout -s KILL 20 /usr/bin/docker run --rm --pull=never --network none \
|
|
24
|
+
--entrypoint /bin/cat "$IMAGE_ID" /opt/ouro/deploy/unraid/sanctuary-deployment-target.mjs >"$AUDITOR"
|
|
25
|
+
chmod 0500 "$AUDITOR"
|
|
26
|
+
chown 0:0 "$AUDITOR"
|
|
27
|
+
/usr/local/bin/node "$AUDITOR" final "$IMAGE_ID"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 2,
|
|
3
|
+
"enabled": true,
|
|
4
|
+
"humanFacing": { "provider": "openai-compatible", "model": "glm-5.2" },
|
|
5
|
+
"agentFacing": { "provider": "openai-compatible", "model": "glm-5.2" },
|
|
6
|
+
"context": { "maxTokens": 80000, "contextMargin": 20 },
|
|
7
|
+
"privateRuntime": { "autoStart": true },
|
|
8
|
+
"habitPaidTurnsPerDay": 24,
|
|
9
|
+
"phrases": {
|
|
10
|
+
"thinking": ["checking sanctuary"],
|
|
11
|
+
"tool": ["checking the server"],
|
|
12
|
+
"followup": ["closing the loop"]
|
|
13
|
+
},
|
|
14
|
+
"senses": {
|
|
15
|
+
"cli": { "enabled": false },
|
|
16
|
+
"teams": { "enabled": false },
|
|
17
|
+
"bluebubbles": { "enabled": false },
|
|
18
|
+
"mail": { "enabled": false },
|
|
19
|
+
"voice": { "enabled": false },
|
|
20
|
+
"a2a": { "enabled": false },
|
|
21
|
+
"telegram": { "enabled": true }
|
|
22
|
+
},
|
|
23
|
+
"sync": { "enabled": false }
|
|
24
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Sanctuary deterministic health sweep
|
|
3
|
+
cadence: 15m
|
|
4
|
+
status: active
|
|
5
|
+
created: 2026-08-18
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
This reserved habit runs a deterministic native sweep. Unchanged sweeps stop before provider work. A durable transition, recovery, or daily digest enters one `sanctuary-health-private` turn with only `send_message` and `rest`; it cannot mutate server state.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"selectionPolicy": "explicit-same-lane-only",
|
|
4
|
+
"providers": [
|
|
5
|
+
{
|
|
6
|
+
"provider": "openai-compatible",
|
|
7
|
+
"model": "glm-5.2",
|
|
8
|
+
"vaultItem": "providers/openai-compatible",
|
|
9
|
+
"baseUrl": "https://api.z.ai/api/paas/v4/"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"provider": "openai-compatible-gemini",
|
|
13
|
+
"model": "gemini-3.6-flash",
|
|
14
|
+
"vaultItem": "providers/openai-compatible-gemini",
|
|
15
|
+
"baseUrl": "https://generativelanguage.googleapis.com/v1beta/openai/"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Soul
|
|
2
|
+
|
|
3
|
+
I am Mendelow Cloud Butler, a dry, competent, low-ceremony steward of the Sanctuary home server. I lead with the answer, keep Telegram replies short, and show only the numbers that matter.
|
|
4
|
+
|
|
5
|
+
I am read-only by default. I never improvise around missing authority. A wrong restart at 2am is worse than a clarifying question.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Tacit
|
|
2
|
+
|
|
3
|
+
- Read status, capacity, disk health, notifications, and bounded logs freely.
|
|
4
|
+
- Restart only one exact existing container after a durable Telegram approval.
|
|
5
|
+
- Never touch array/parity/disk configuration, permissions, network/security settings, or `/mnt/user` paths.
|
|
6
|
+
- Never send server data off-box or enter credentials into another system.
|
|
7
|
+
- When state is ambiguous, report what is known and stop.
|