@ouro.bot/cli 0.1.0-alpha.1635 → 0.1.0-alpha.1637
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 +15 -1
- package/deploy/unraid/migrate-sanctuary-bundle.mjs +8 -3
- package/deploy/unraid/sanctuary-butler-upgrade.mjs +237 -66
- package/deploy/unraid/sanctuary-replay-gate.mjs +42 -21
- package/deploy/unraid/sanctuary-sync-cutover.sh +19 -1
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
- package/deploy/unraid/sanctuary.ouro/mcp/media-mcp.mjs +18 -5
- package/deploy/unraid/sanctuary.ouro/product/PRODUCT.md +1 -1
- package/deploy/unraid/sanctuary.xml +1 -1
- package/dist/heart/butler-agent.js +14 -0
- package/dist/heart/daemon/container-spec-auditor.js +49 -39
- package/dist/heart/daemon/daemon-entry.js +3 -0
- package/dist/heart/daemon/sanctuary-authority-root-lifecycle.js +36 -17
- package/dist/heart/daemon/sanctuary-bundle-migration.js +73 -8
- package/dist/heart/external-events/router.js +94 -13
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -35,7 +35,18 @@ export const DEFAULT_TRUST_DIR = "/mnt/user/appdata/ouro-butler/trust/sanctuary"
|
|
|
35
35
|
// bundle: the Butler's user can neither write it nor move it, so nothing in it can be planted. Only this folder and the trust directory's replay
|
|
36
36
|
// list may supply replay friend ids and DIDs; a file in the bundle never does.
|
|
37
37
|
export const DEFAULT_CLIENT_DIR = "/mnt/user/appdata/ouro-butler/replay-client"
|
|
38
|
-
|
|
38
|
+
// The host folder above never moves. Inside the container the bundle sits under the Butler name the image runs (its ENTRYPOINT's
|
|
39
|
+
// `--package-managed-agent <name>`, read from the live container by main), so every container path below is built from that name.
|
|
40
|
+
export const BUTLER_NAMES = ["butler", "sanctuary"]
|
|
41
|
+
/** The Butler name an image's ENTRYPOINT runs; anything else is sanctuary (as src/heart/butler-agent.ts butlerNameFromEntrypoint). */
|
|
42
|
+
export function butlerNameFromEntrypoint(entrypoint) {
|
|
43
|
+
if (!Array.isArray(entrypoint)) return "sanctuary"
|
|
44
|
+
const flag = entrypoint.indexOf("--package-managed-agent")
|
|
45
|
+
const name = flag >= 0 ? entrypoint[flag + 1] : undefined
|
|
46
|
+
return BUTLER_NAMES.includes(name) ? name : "sanctuary"
|
|
47
|
+
}
|
|
48
|
+
export const containerBundle = (name) => `/home/ouro/AgentBundles/${name}.ouro`
|
|
49
|
+
export const CONTAINER_BUNDLE = containerBundle("sanctuary")
|
|
39
50
|
export const CONTAINER = "ouro-butler"
|
|
40
51
|
// The uid the A2A sense runs as inside the container; the trust probe must see the window exactly as that process does.
|
|
41
52
|
export const BUTLER_USER = "10001:10001"
|
|
@@ -169,7 +180,8 @@ export function findHedges(text, terms) {
|
|
|
169
180
|
export const mentionsWord = (haystack, name) => new RegExp(`(?<![\\p{L}\\p{N}])${escapeRegExp(name)}(?![\\p{L}\\p{N}])`, "iu").test(String(haystack ?? ""))
|
|
170
181
|
/** The release's own name finder (src/heart/source-grounding.ts, the one the runtime gates replies with), run inside the container. */
|
|
171
182
|
// Loads the house's own names first, as every Butler turn does, so the gate and the runtime agree on what counts as a name.
|
|
172
|
-
export const
|
|
183
|
+
export const namesScript = (agentRoot) => `const [t,o]=JSON.parse(require("fs").readFileSync(0,"utf8"));const g=require("/opt/ouro/dist/heart/source-grounding.js");const h=require("/opt/ouro/dist/senses/sanctuary-house.js").readSanctuaryHouse(${JSON.stringify(agentRoot)});g.addHouseVocabulary([h.ownerName,h.butlerName,h.householdName]);console.log(JSON.stringify(g.namesIn(t,o)))`
|
|
184
|
+
export const NAMES_SCRIPT = namesScript(CONTAINER_BUNDLE)
|
|
173
185
|
|
|
174
186
|
/** HH:MM (UTC) of the whole minute `minutes` after the start of `now`'s minute. */
|
|
175
187
|
export function utcMinuteAhead(now, minutes) {
|
|
@@ -1826,8 +1838,14 @@ export const RETIRE_RECORD_SCRIPT = [
|
|
|
1826
1838
|
'fs.writeFileSync(file,JSON.stringify(rec,null,2)+"\\n");',
|
|
1827
1839
|
].join("")
|
|
1828
1840
|
|
|
1829
|
-
function retireRecordInContainer(friendId, did) {
|
|
1830
|
-
|
|
1841
|
+
export function retireRecordInContainer(friendId, did, agentRoot = CONTAINER_BUNDLE, run = sh) {
|
|
1842
|
+
run("docker", ["exec", "-u", BUTLER_USER, CONTAINER, "node", "-e", RETIRE_RECORD_SCRIPT, agentRoot, friendId, did ?? ""])
|
|
1843
|
+
}
|
|
1844
|
+
|
|
1845
|
+
/** The Butler name the live container's image runs. Throws when docker cannot say, so the gate never guesses a path. */
|
|
1846
|
+
export function liveButlerName(run = sh) {
|
|
1847
|
+
const imageId = String(run("docker", ["inspect", "--format", "{{.Image}}", CONTAINER])).trim()
|
|
1848
|
+
return butlerNameFromEntrypoint(JSON.parse(String(run("docker", ["image", "inspect", "--format", "{{json .Config.Entrypoint}}", imageId])).trim() || "null"))
|
|
1831
1849
|
}
|
|
1832
1850
|
|
|
1833
1851
|
/**
|
|
@@ -1836,9 +1854,9 @@ function retireRecordInContainer(friendId, did) {
|
|
|
1836
1854
|
* that command must run with no more than the Butler's own rights. It runs no hooks and no fsmonitor, and takes no optional lock.
|
|
1837
1855
|
* `env` adds `-e NAME=value` pairs (ls-remote's ssh). This is the gate's only git call.
|
|
1838
1856
|
*/
|
|
1839
|
-
export function bundleGit(args, run = sh, { env = [], timeout = 120_000 } = {}) {
|
|
1857
|
+
export function bundleGit(args, run = sh, { env = [], timeout = 120_000, agentRoot = CONTAINER_BUNDLE } = {}) {
|
|
1840
1858
|
const envArgs = ["GIT_OPTIONAL_LOCKS=0", ...env].flatMap((pair) => ["-e", pair])
|
|
1841
|
-
return run("docker", ["exec", "-u", BUTLER_USER, ...envArgs, CONTAINER, "git", "-c", "core.hooksPath=/dev/null", "-c", "core.fsmonitor=false", "-C",
|
|
1859
|
+
return run("docker", ["exec", "-u", BUTLER_USER, ...envArgs, CONTAINER, "git", "-c", "core.hooksPath=/dev/null", "-c", "core.fsmonitor=false", "-C", agentRoot, ...args], { timeout, maxBuffer: 256 * 1024 * 1024 })
|
|
1842
1860
|
}
|
|
1843
1861
|
|
|
1844
1862
|
/** The untracked, unignored paths in the bundle and a hash of each (git's, with no filter run), read in the container. */
|
|
@@ -1857,10 +1875,9 @@ export function untrackedFiles(git) {
|
|
|
1857
1875
|
* The host side of bundle sync for the gate: the cutover marker, sync's own pause marker, the lock, one `ouro sync` in the container,
|
|
1858
1876
|
* and read-only git. `sleep` and `now` come from the host, so tests drive the clock.
|
|
1859
1877
|
*/
|
|
1860
|
-
export function makeSyncHost({ bundle, backupDir = DEFAULT_BACKUP_DIR, exec = sh, git = (args) => bundleGit(args, exec), sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)), now = () => Date.now(), pollMs = SYNC_LOCK_POLL_MS }) {
|
|
1878
|
+
export function makeSyncHost({ bundle, backupDir = DEFAULT_BACKUP_DIR, exec = sh, agentName = path.basename(bundle, ".ouro"), git = (args) => bundleGit(args, exec, { agentRoot: containerBundle(agentName) }), sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)), now = () => Date.now(), pollMs = SYNC_LOCK_POLL_MS }) {
|
|
1861
1879
|
const state = path.join(bundle, "state")
|
|
1862
1880
|
const marker = path.join(state, "sync-paused")
|
|
1863
|
-
const agentName = path.basename(bundle, ".ouro")
|
|
1864
1881
|
const branch = () => {
|
|
1865
1882
|
try { return readJsonNoFollow(path.join(bundle, "agent.json"))?.sync?.branch ?? "main" } catch { return "main" }
|
|
1866
1883
|
}
|
|
@@ -1930,7 +1947,7 @@ export function makeSyncHost({ bundle, backupDir = DEFAULT_BACKUP_DIR, exec = sh
|
|
|
1930
1947
|
* not move.
|
|
1931
1948
|
*/
|
|
1932
1949
|
agentChanges(head) {
|
|
1933
|
-
const listed = bundleGit(["ls-remote", "origin", `refs/heads/${branch()}`], exec, { env: [`GIT_SSH_COMMAND=${SYNC_SSH_COMMAND}`, "GIT_SSH_VARIANT=ssh"], timeout: 60_000 })
|
|
1950
|
+
const listed = bundleGit(["ls-remote", "origin", `refs/heads/${branch()}`], exec, { env: [`GIT_SSH_COMMAND=${SYNC_SSH_COMMAND}`, "GIT_SSH_VARIANT=ssh"], timeout: 60_000, agentRoot: containerBundle(agentName) })
|
|
1934
1951
|
const remoteHead = /^([0-9a-f]{40})\s/u.exec(listed)?.[1]
|
|
1935
1952
|
if (!remoteHead) throw new Error(`git ls-remote origin refs/heads/${branch()} listed no head`)
|
|
1936
1953
|
const commits = lines(git(["log", "--no-merges", `--author=<${agentName}@ouro.local>`, "--format=%H", `${head}..${remoteHead}`]))
|
|
@@ -1960,7 +1977,7 @@ export function makeSyncHost({ bundle, backupDir = DEFAULT_BACKUP_DIR, exec = sh
|
|
|
1960
1977
|
const entry = JSON.parse(line)
|
|
1961
1978
|
const at = Date.parse(entry.ts)
|
|
1962
1979
|
if (typeof entry.event !== "string" || !(at >= sinceMs)) continue
|
|
1963
|
-
if (entry.meta?.agentRoot !== undefined && entry.meta.agentRoot !==
|
|
1980
|
+
if (entry.meta?.agentRoot !== undefined && entry.meta.agentRoot !== containerBundle(agentName)) continue
|
|
1964
1981
|
out.push({ event: entry.event, at })
|
|
1965
1982
|
} catch { /* a torn line */ }
|
|
1966
1983
|
}
|
|
@@ -1970,7 +1987,8 @@ export function makeSyncHost({ bundle, backupDir = DEFAULT_BACKUP_DIR, exec = sh
|
|
|
1970
1987
|
}
|
|
1971
1988
|
}
|
|
1972
1989
|
|
|
1973
|
-
export function makeHost({ bundle = DEFAULT_BUNDLE, trustDir = DEFAULT_TRUST_DIR, clientDir = DEFAULT_CLIENT_DIR, backupDir = DEFAULT_BACKUP_DIR, chainRoot, cardUrl, log = console.error, exec = sh, stage = dockerStage(exec), rootUid = 0, rootGid = 0 } = {}) {
|
|
1990
|
+
export function makeHost({ bundle = DEFAULT_BUNDLE, trustDir = DEFAULT_TRUST_DIR, clientDir = DEFAULT_CLIENT_DIR, backupDir = DEFAULT_BACKUP_DIR, chainRoot, cardUrl, log = console.error, exec = sh, stage = dockerStage(exec), rootUid = 0, rootGid = 0, agentName = "sanctuary" } = {}) {
|
|
1991
|
+
const agentRoot = containerBundle(agentName)
|
|
1974
1992
|
const state = path.join(bundle, "state")
|
|
1975
1993
|
const replayDir = path.join(state, "replay")
|
|
1976
1994
|
const clientIssue = rootOwnedDirectoryIssue(clientDir, rootUid)
|
|
@@ -2005,7 +2023,7 @@ export function makeHost({ bundle = DEFAULT_BUNDLE, trustDir = DEFAULT_TRUST_DIR
|
|
|
2005
2023
|
}
|
|
2006
2024
|
return {
|
|
2007
2025
|
friends: { principal: provisioned.principal.friendId, stranger: provisioned.stranger.friendId, escalation: provisioned.escalation.friendId },
|
|
2008
|
-
sync: makeSyncHost({ bundle, backupDir, exec }),
|
|
2026
|
+
sync: makeSyncHost({ bundle, backupDir, exec, agentName }),
|
|
2009
2027
|
now: () => Date.now(),
|
|
2010
2028
|
sleep: (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
|
2011
2029
|
/** The Butler's A2A card must answer before the window opens: a fresh container needs a moment after it turns healthy. */
|
|
@@ -2051,7 +2069,7 @@ export function makeHost({ bundle = DEFAULT_BUNDLE, trustDir = DEFAULT_TRUST_DIR
|
|
|
2051
2069
|
/** Asks the Butler's own replay code, inside the container, whether it opens the window for both peers. */
|
|
2052
2070
|
async windowTrusted() {
|
|
2053
2071
|
const ids = replayPeers
|
|
2054
|
-
const script = `const h=require("/opt/ouro/dist/a2a/replay-harness.js");const o={};for(const id of ${JSON.stringify(ids)})o[id]=h.isReplayWindowOpen(${JSON.stringify(
|
|
2072
|
+
const script = `const h=require("/opt/ouro/dist/a2a/replay-harness.js");const o={};for(const id of ${JSON.stringify(ids)})o[id]=h.isReplayWindowOpen(${JSON.stringify(agentRoot)},id);console.log(JSON.stringify(o))`
|
|
2055
2073
|
try {
|
|
2056
2074
|
const seen = JSON.parse(exec("docker", ["exec", "-u", BUTLER_USER, CONTAINER, "node", "-e", script], { timeout: 60_000 }).trim().split("\n").at(-1))
|
|
2057
2075
|
const closed = ids.filter((id) => seen[id] !== true)
|
|
@@ -2096,7 +2114,7 @@ export function makeHost({ bundle = DEFAULT_BUNDLE, trustDir = DEFAULT_TRUST_DIR
|
|
|
2096
2114
|
}
|
|
2097
2115
|
},
|
|
2098
2116
|
names(text, options) {
|
|
2099
|
-
return JSON.parse(exec("docker", ["exec", "-i", "-u", BUTLER_USER, CONTAINER, "node", "-e",
|
|
2117
|
+
return JSON.parse(exec("docker", ["exec", "-i", "-u", BUTLER_USER, CONTAINER, "node", "-e", namesScript(agentRoot)], { input: JSON.stringify([text, options]), stdio: ["pipe", "pipe", "pipe"], timeout: 60_000 }).trim().split("\n").at(-1))
|
|
2100
2118
|
},
|
|
2101
2119
|
async readSession(context) {
|
|
2102
2120
|
const root = path.join(state, "sessions")
|
|
@@ -2604,7 +2622,7 @@ function trustedReplayList(trustDir) {
|
|
|
2604
2622
|
* the record in the root-owned replay folder (`clientDir`). Nothing in the bundle's state/replay-client or state/replay supplies either, because
|
|
2605
2623
|
* the Butler's user writes the bundle.
|
|
2606
2624
|
*/
|
|
2607
|
-
export function provision({ bundle = DEFAULT_BUNDLE, trustDir = DEFAULT_TRUST_DIR, clientDir = DEFAULT_CLIENT_DIR, chainRoot, cardUrl, log = console.log, run = ctr, discover = discoverCardUrl, stage = dockerStage(), retireRecord = retireRecordInContainer, retire = [], rootUid = 0, rootGid = 0, rotate = false, now = new Date() } = {}) {
|
|
2625
|
+
export function provision({ bundle = DEFAULT_BUNDLE, trustDir = DEFAULT_TRUST_DIR, clientDir = DEFAULT_CLIENT_DIR, chainRoot, cardUrl, log = console.log, run = ctr, discover = discoverCardUrl, stage = dockerStage(), retireRecord = retireRecordInContainer, retire = [], rootUid = 0, rootGid = 0, rotate = false, now = new Date(), agentName = "sanctuary" } = {}) {
|
|
2608
2626
|
const state = path.join(bundle, "state")
|
|
2609
2627
|
const replayDir = path.join(state, "replay")
|
|
2610
2628
|
refuseLinkOrWrongType(state, "directory")
|
|
@@ -2640,8 +2658,8 @@ export function provision({ bundle = DEFAULT_BUNDLE, trustDir = DEFAULT_TRUST_DI
|
|
|
2640
2658
|
// The record lives in the Butler-writable bundle, so a missing or mangled one must not stop the rotation: the trust-dir revokes
|
|
2641
2659
|
// above are what take authority away, and they have already happened.
|
|
2642
2660
|
try {
|
|
2643
|
-
run(["friend", "update", friendId, "--agent",
|
|
2644
|
-
retireRecord(friendId, did)
|
|
2661
|
+
run(["friend", "update", friendId, "--agent", agentName, "--admission", "revoked", "--trust", "stranger"])
|
|
2662
|
+
retireRecord(friendId, did, containerBundle(agentName))
|
|
2645
2663
|
log(`retired friend ${friendId}`)
|
|
2646
2664
|
} catch (error) {
|
|
2647
2665
|
log(`revoked friend ${friendId}'s grants, but could not demote its record: ${error instanceof Error ? error.message.split("\n")[0] : String(error)}`)
|
|
@@ -2667,11 +2685,11 @@ export function provision({ bundle = DEFAULT_BUNDLE, trustDir = DEFAULT_TRUST_DI
|
|
|
2667
2685
|
handOverFile(hostIdentity, { uid: rootUid, gid: rootGid, mode: 0o600 })
|
|
2668
2686
|
let friendId = previous[who]?.did === did ? previous[who].friendId : null
|
|
2669
2687
|
if (!friendId) {
|
|
2670
|
-
const onboarded = run(["a2a", "onboard", "--agent",
|
|
2688
|
+
const onboarded = run(["a2a", "onboard", "--agent", agentName, "--did", did, "--name", name, "--trust", trust])
|
|
2671
2689
|
friendId = /friend id:\s*(\S+)/.exec(onboarded)?.[1]
|
|
2672
2690
|
if (!friendId) throw new Error(`could not read the friend id from: ${onboarded}`)
|
|
2673
2691
|
}
|
|
2674
|
-
run(["friend", "update", friendId, "--agent",
|
|
2692
|
+
run(["friend", "update", friendId, "--agent", agentName, "--admission", "active", "--initiative", "reactive_only", "--profile", PEER_PROFILE])
|
|
2675
2693
|
const record = readJsonNoFollow(friendFile(bundle, friendId))
|
|
2676
2694
|
// The record's own delegationGrant is only a hint the Butler ignores; nobody here may hold one.
|
|
2677
2695
|
if (record.delegationGrant && !grant) throw new Error(`${name} must not hold a delegation grant`)
|
|
@@ -2749,12 +2767,15 @@ export async function main(argv, io = { out: (text) => console.log(text), err: (
|
|
|
2749
2767
|
for (const file of statusProblems((deps.readStdin ?? (() => readFileSync(0, "utf8")))())) io.out(file)
|
|
2750
2768
|
return 0
|
|
2751
2769
|
}
|
|
2770
|
+
// The paths inside the container, and the agent its commands name, follow the Butler name the live container's image runs.
|
|
2771
|
+
let agentName
|
|
2772
|
+
if (options.command === "provision" || options.command === "run") try { agentName = (deps.butlerName ?? liveButlerName)() } catch (error) { io.err(`could not read the Butler's name from the ${CONTAINER} container's image: ${String(error.message).split("\n")[0]}`); return 1 }
|
|
2752
2773
|
if (options.command === "provision") {
|
|
2753
|
-
try { deps.provision({ ...(options.bundle ? { bundle: options.bundle } : {}), ...(options.trustDir ? { trustDir: options.trustDir } : {}), ...(options.cardUrl ? { cardUrl: options.cardUrl } : {}), ...(options.clientDir ? { clientDir: options.clientDir } : {}), ...(options.retire ? { retire: options.retire } : {}), ...(options.rotate ? { rotate: true } : {}), log: io.out }); return 0 } catch (error) { io.err(`provision failed: ${error.message}`); return 1 }
|
|
2774
|
+
try { deps.provision({ agentName, ...(options.bundle ? { bundle: options.bundle } : {}), ...(options.trustDir ? { trustDir: options.trustDir } : {}), ...(options.cardUrl ? { cardUrl: options.cardUrl } : {}), ...(options.clientDir ? { clientDir: options.clientDir } : {}), ...(options.retire ? { retire: options.retire } : {}), ...(options.rotate ? { rotate: true } : {}), log: io.out }); return 0 } catch (error) { io.err(`provision failed: ${error.message}`); return 1 }
|
|
2754
2775
|
}
|
|
2755
2776
|
if (options.command === "run") {
|
|
2756
2777
|
let host
|
|
2757
|
-
try { host = deps.makeHost({ ...(options.bundle ? { bundle: options.bundle } : {}), ...(options.backupDir ? { backupDir: options.backupDir } : {}), ...(options.trustDir ? { trustDir: options.trustDir } : {}), ...(options.clientDir ? { clientDir: options.clientDir } : {}), ...(options.cardUrl ? { cardUrl: options.cardUrl } : {}), log: io.err }) } catch (error) { io.err(error.message); return 1 }
|
|
2778
|
+
try { host = deps.makeHost({ agentName, ...(options.bundle ? { bundle: options.bundle } : {}), ...(options.backupDir ? { backupDir: options.backupDir } : {}), ...(options.trustDir ? { trustDir: options.trustDir } : {}), ...(options.clientDir ? { clientDir: options.clientDir } : {}), ...(options.cardUrl ? { cardUrl: options.cardUrl } : {}), log: io.err }) } catch (error) { io.err(error.message); return 1 }
|
|
2758
2779
|
// butler-ship runs this gate against the live version first and hands the upgrade that log through the environment.
|
|
2759
2780
|
const baselineFile = options.baseline ?? env.OURO_REPLAY_BASELINE
|
|
2760
2781
|
let baseline
|
|
@@ -31,6 +31,8 @@ BUNDLE_REPO_OWNER=arimendelow
|
|
|
31
31
|
BUNDLE_REPO_NAME=sanctuary.ouro
|
|
32
32
|
BUNDLE_REMOTE="git@github.com:${BUNDLE_REPO_OWNER}/${BUNDLE_REPO_NAME}.git"
|
|
33
33
|
BUNDLE_BRANCH=main
|
|
34
|
+
# The Butler's name inside the container, and the bundle's path there, follow the live container's image (use_image_agent_name).
|
|
35
|
+
# The host folder ($BUNDLE below) keeps its name whichever name the image runs.
|
|
34
36
|
AGENT_NAME=sanctuary
|
|
35
37
|
# backup.sh's commit identity and the fetch refspec the moved repository must have.
|
|
36
38
|
BACKUP_COMMIT_NAME="Sanctuary backup"
|
|
@@ -148,6 +150,19 @@ before_value() {
|
|
|
148
150
|
file_value "$BEFORE" "$1" || die "$(basename "$BEFORE") has no \"$1\" line"
|
|
149
151
|
}
|
|
150
152
|
|
|
153
|
+
# Sets AGENT_NAME and CONTAINER_BUNDLE from the Butler name image $1 runs: its ENTRYPOINT's `--package-managed-agent <name>`.
|
|
154
|
+
# Any other entrypoint means sanctuary, as src/heart/butler-agent.ts butlerNameFromEntrypoint reads it.
|
|
155
|
+
use_image_agent_name() {
|
|
156
|
+
local entrypoint name
|
|
157
|
+
entrypoint=$(docker image inspect --format '{{json .Config.Entrypoint}}' "$1") || die "docker could not read the entrypoint of $1"
|
|
158
|
+
name=$(printf '%s' "$entrypoint" | sed -n 's/.*"--package-managed-agent","\([^"]*\)".*/\1/p')
|
|
159
|
+
case "$name" in
|
|
160
|
+
butler | sanctuary) AGENT_NAME=$name ;;
|
|
161
|
+
*) AGENT_NAME=sanctuary ;;
|
|
162
|
+
esac
|
|
163
|
+
CONTAINER_BUNDLE=/home/ouro/AgentBundles/$AGENT_NAME.ouro
|
|
164
|
+
}
|
|
165
|
+
|
|
151
166
|
container_image() {
|
|
152
167
|
local image
|
|
153
168
|
image=$(docker inspect --format '{{.Image}}' "$CONTAINER")
|
|
@@ -309,6 +324,7 @@ preflight() {
|
|
|
309
324
|
local image branch upstream remote merge stash tracked timings status_ms add_ms excluded secrets out
|
|
310
325
|
local origin_url fetch bare worktree sshcmd ucache manyfiles agent_sync repo_stat repo_owner repo_mode key_state
|
|
311
326
|
image=$(container_image)
|
|
327
|
+
use_image_agent_name "$image"
|
|
312
328
|
print_exclude "$image" "$WORK/exclude"
|
|
313
329
|
chmod 0644 "$WORK/exclude"
|
|
314
330
|
timings=$(measure_git "$image" "$WORK/exclude")
|
|
@@ -910,9 +926,11 @@ butler_sync() { docker exec -u 10001 "$CONTAINER" timeout 60 node "$CLI_ENTRY" s
|
|
|
910
926
|
|
|
911
927
|
verify_live() {
|
|
912
928
|
[ -e "$MARKER" ] || die "the cutover is not done ($MARKER is missing)"
|
|
913
|
-
local heads uid start elapsed status out leftover
|
|
929
|
+
local heads uid start elapsed status out leftover image
|
|
914
930
|
trap 'trap "" INT TERM HUP; exit 130' INT TERM
|
|
915
931
|
trap 'trap "" INT TERM HUP; exit 129' HUP
|
|
932
|
+
image=$(container_image)
|
|
933
|
+
use_image_agent_name "$image"
|
|
916
934
|
|
|
917
935
|
say "the sync path reaches GitHub as ouro-sync"
|
|
918
936
|
heads=$(docker exec -u 10001 -e "GIT_SSH_COMMAND=sudo -n -u ouro-sync $SYNC_SSH_WRAPPER" -e GIT_SSH_VARIANT=ssh "$CONTAINER" \
|
|
@@ -10,10 +10,23 @@
|
|
|
10
10
|
// Protocol: JSON-RPC 2.0 over stdio, newline framed, MCP 2024-11-05.
|
|
11
11
|
|
|
12
12
|
import { appendFileSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs"
|
|
13
|
-
import { dirname } from "node:path"
|
|
14
|
-
import { pathToFileURL } from "node:url"
|
|
13
|
+
import { dirname, join } from "node:path"
|
|
14
|
+
import { fileURLToPath, pathToFileURL } from "node:url"
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
// Where this server's files live inside the bundle it ships in (this file is <bundle>/mcp/media-mcp.mjs).
|
|
17
|
+
// Derived from the script's own location, so a bundle mounted as sanctuary.ouro or butler.ouro finds its own files.
|
|
18
|
+
export function bundleMediaPaths(moduleUrl) {
|
|
19
|
+
const bundleRoot = dirname(dirname(fileURLToPath(moduleUrl)))
|
|
20
|
+
return {
|
|
21
|
+
bundleRoot,
|
|
22
|
+
credentials: join(bundleRoot, "mcp", "media-credentials.json"),
|
|
23
|
+
progress: join(bundleRoot, "state", "media", "download-progress.json"),
|
|
24
|
+
qualityAudit: join(bundleRoot, "state", "media", "quality-profile-audit.ndjson"),
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const BUNDLE_PATHS = bundleMediaPaths(import.meta.url)
|
|
28
|
+
|
|
29
|
+
const CRED_PATH = process.env.SANCTUARY_MEDIA_CREDENTIALS ?? BUNDLE_PATHS.credentials
|
|
17
30
|
|
|
18
31
|
// Credentials are host-specific and deliberately NOT packaged. A fresh install
|
|
19
32
|
// has none, and the server must still start and list its tools — otherwise the
|
|
@@ -1617,7 +1630,7 @@ const PROGRESS_FORGET_MS = 14 * 24 * 3_600_000
|
|
|
1617
1630
|
// Observations further apart than this are not continuous: the download may have been paused
|
|
1618
1631
|
// and resumed in between, so the older one stops counting.
|
|
1619
1632
|
const PROGRESS_CONTINUITY_MS = 6 * 3_600_000
|
|
1620
|
-
const progressPath = () => process.env.SANCTUARY_MEDIA_STATE ??
|
|
1633
|
+
const progressPath = () => process.env.SANCTUARY_MEDIA_STATE ?? BUNDLE_PATHS.progress
|
|
1621
1634
|
let progressSeen = null
|
|
1622
1635
|
function readProgressFile() {
|
|
1623
1636
|
const out = new Map()
|
|
@@ -2047,7 +2060,7 @@ async function getItem(kind, serviceId) {
|
|
|
2047
2060
|
}
|
|
2048
2061
|
|
|
2049
2062
|
// One line per applied change: what changed, the owner's words that asked for it, who called, and when.
|
|
2050
|
-
const qualityAuditPath = () => process.env.SANCTUARY_MEDIA_AUDIT ??
|
|
2063
|
+
const qualityAuditPath = () => process.env.SANCTUARY_MEDIA_AUDIT ?? BUNDLE_PATHS.qualityAudit
|
|
2051
2064
|
function auditQualityChange(entry) {
|
|
2052
2065
|
try {
|
|
2053
2066
|
mkdirSync(dirname(qualityAuditPath()), { recursive: true })
|
|
@@ -9,5 +9,5 @@
|
|
|
9
9
|
- When {{owner}} asks how the whole house is doing, I cover active work, what waits on {{owner}}, snoozed wake times, services quiet on purpose, healthy systems and other current issues, in household words. I leave out daemons, event queues, provider lanes and backend service names.
|
|
10
10
|
- When {{owner}} hands the chat to someone, that person is reading this chat now. I greet them here and start right away, with a question when {{owner}} asked me to find out what they want. I use the name {{owner}} gives me, and no other.
|
|
11
11
|
- When I change SOUL, IDENTITY, LORE or ASPIRATIONS, I tell {{owner}} in one line which file changed and why. What I learn goes into TACIT quietly.
|
|
12
|
-
- When anyone in the house tells me how the house works, I write it into
|
|
12
|
+
- When anyone in the house tells me how the house works, I write it into `psyche/TACIT.md` this turn and say it's noted. Teaching me the house takes no one's say-so.
|
|
13
13
|
- A change to who I am is made in a one-to-one chat with someone in my family. Asked anywhere else, I say that in one line and save nothing.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<?xml version="1.0"?>
|
|
2
2
|
<Container version="2">
|
|
3
3
|
<Name>ouro-butler</Name>
|
|
4
|
-
<Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.
|
|
4
|
+
<Repository>ghcr.io/ourostack/ouroboros-butler:0.1.0-alpha.1637</Repository>
|
|
5
5
|
<Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
|
|
6
6
|
<Network>host</Network>
|
|
7
7
|
<Shell>sh</Shell>
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BUTLER_AGENT_NAMES = void 0;
|
|
4
4
|
exports.isButlerAgent = isButlerAgent;
|
|
5
5
|
exports.butlerContainerPaths = butlerContainerPaths;
|
|
6
|
+
exports.butlerNameFromEntrypoint = butlerNameFromEntrypoint;
|
|
6
7
|
exports.managedButlerAgent = managedButlerAgent;
|
|
7
8
|
exports.butlerOnDisk = butlerOnDisk;
|
|
8
9
|
/**
|
|
@@ -20,6 +21,7 @@ function butlerContainerPaths(name) {
|
|
|
20
21
|
const healthJobId = `${name}:sanctuary-health`;
|
|
21
22
|
return {
|
|
22
23
|
agentRoot,
|
|
24
|
+
trustRoot: `/etc/ouro/trust/${name}`,
|
|
23
25
|
crontabPath: `/home/ouro/.ouro-cli/scheduler/${name}.crontab`,
|
|
24
26
|
habitNamespace,
|
|
25
27
|
healthJobId,
|
|
@@ -28,6 +30,18 @@ function butlerContainerPaths(name) {
|
|
|
28
30
|
healthCronMarker: `# ouro:${habitNamespace}:${healthJobId}`,
|
|
29
31
|
};
|
|
30
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* The Butler an image runs, from its ENTRYPOINT (`docker image inspect --format '{{json .Config.Entrypoint}}'`): the argument
|
|
35
|
+
* after `--package-managed-agent` when it is a Butler name. Anything else, including an image with no package activation,
|
|
36
|
+
* means `sanctuary`, the name every image had before the rename. The host mounts the bundle and trust where this name says.
|
|
37
|
+
*/
|
|
38
|
+
function butlerNameFromEntrypoint(entrypoint) {
|
|
39
|
+
if (!Array.isArray(entrypoint))
|
|
40
|
+
return "sanctuary";
|
|
41
|
+
const flag = entrypoint.indexOf("--package-managed-agent");
|
|
42
|
+
const name = flag >= 0 ? entrypoint[flag + 1] : undefined;
|
|
43
|
+
return isButlerAgent(name) ? name : "sanctuary";
|
|
44
|
+
}
|
|
31
45
|
/** The one Butler among the agents this daemon manages, or null when there is none or more than one. */
|
|
32
46
|
function managedButlerAgent(managedAgents) {
|
|
33
47
|
const butlers = managedAgents.filter(isButlerAgent);
|
|
@@ -4,50 +4,57 @@ exports.auditSanctuaryContainerSpec = auditSanctuaryContainerSpec;
|
|
|
4
4
|
exports.auditSanctuaryStagedFiles = auditSanctuaryStagedFiles;
|
|
5
5
|
exports.auditSanctuaryPersistentTemplate = auditSanctuaryPersistentTemplate;
|
|
6
6
|
const runtime_1 = require("../../nerves/runtime");
|
|
7
|
+
const butler_agent_1 = require("../butler-agent");
|
|
7
8
|
const { parseDockerManTemplateXml } = require("../../../deploy/unraid/docker-man-template-xml.cjs");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
[
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
]
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
9
|
+
// The host folders never change with the Butler's name: the bundle stays in sanctuary.ouro on the live host. Only where the
|
|
10
|
+
// bundle, its psyche and the operator trust are mounted inside the container follows the name the image runs.
|
|
11
|
+
function expectedBinds(name) {
|
|
12
|
+
return [
|
|
13
|
+
"/mnt/user/appdata/ouro-butler/runtime/.ouro-cli:/home/ouro/.ouro-cli:rw",
|
|
14
|
+
`/mnt/user/appdata/ouro-butler/agent/sanctuary.ouro:/home/ouro/AgentBundles/${name}.ouro:rw`,
|
|
15
|
+
"/boot/config/custom/ouro-events/spool:/run/ouro-events:ro",
|
|
16
|
+
"/run/ouro-authority:/run/ouro-authority:ro",
|
|
17
|
+
// The psyche folder read-only over the bundle. Releases up to alpha.978 create it, and a rollback to one recreates it,
|
|
18
|
+
// so canonical-gateway accepts these binds with or without this row (gatewayBinds).
|
|
19
|
+
`/mnt/user/appdata/ouro-butler/agent/sanctuary.ouro/psyche:/home/ouro/AgentBundles/${name}.ouro/psyche:ro`,
|
|
20
|
+
// Operator-set grants, root-owned on the host and read-only inside the Butler (the Butler honours a grant only from here).
|
|
21
|
+
`/mnt/user/appdata/ouro-butler/trust/sanctuary:/etc/ouro/trust/${name}:ro`,
|
|
22
|
+
// The bundle sync deploy key, root-owned on the host and read-only inside the Butler. The key can push to the owner's repo.
|
|
23
|
+
"/mnt/user/appdata/ouro-butler/sync:/run/ouro-sync:ro",
|
|
24
|
+
];
|
|
25
|
+
}
|
|
26
|
+
function expectedMounts(name) {
|
|
27
|
+
return [
|
|
28
|
+
["/mnt/user/appdata/ouro-butler/runtime/.ouro-cli", "/home/ouro/.ouro-cli", true, "rprivate"],
|
|
29
|
+
["/mnt/user/appdata/ouro-butler/agent/sanctuary.ouro", `/home/ouro/AgentBundles/${name}.ouro`, true, "rprivate"],
|
|
30
|
+
["/boot/config/custom/ouro-events/spool", "/run/ouro-events", false, "rprivate"],
|
|
31
|
+
["/run/ouro-authority", "/run/ouro-authority", false, "rprivate"],
|
|
32
|
+
["/mnt/user/appdata/ouro-butler/agent/sanctuary.ouro/psyche", `/home/ouro/AgentBundles/${name}.ouro/psyche`, false, "rprivate"],
|
|
33
|
+
["/mnt/user/appdata/ouro-butler/trust/sanctuary", `/etc/ouro/trust/${name}`, false, "rprivate"],
|
|
34
|
+
["/mnt/user/appdata/ouro-butler/sync", "/run/ouro-sync", false, "rprivate"],
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
const psycheTarget = (name) => `/home/ouro/AgentBundles/${name}.ouro/psyche`;
|
|
34
38
|
const SYNC_TARGET = "/run/ouro-sync";
|
|
35
39
|
/**
|
|
36
|
-
* The canonical-gateway shapes
|
|
37
|
-
*
|
|
40
|
+
* The canonical-gateway shapes for one Butler name: with and without the separate read-only psyche mount. With sync on,
|
|
41
|
+
* the key mount is required. With sync off (the live Butler until the cutover, and a rollback to a release without the
|
|
42
|
+
* mount) each shape is accepted with or without it.
|
|
38
43
|
*/
|
|
39
|
-
function gatewayBinds(syncEnabled) {
|
|
40
|
-
const
|
|
44
|
+
function gatewayBinds(syncEnabled, name) {
|
|
45
|
+
const all = expectedBinds(name);
|
|
46
|
+
const shapes = [all, all.filter((bind) => !bind.includes(`:${psycheTarget(name)}:`))];
|
|
41
47
|
return syncEnabled ? shapes : [...shapes, ...shapes.map((binds) => binds.filter((bind) => !bind.includes(`:${SYNC_TARGET}:`)))];
|
|
42
48
|
}
|
|
43
|
-
function gatewayMounts(syncEnabled) {
|
|
44
|
-
const
|
|
49
|
+
function gatewayMounts(syncEnabled, name) {
|
|
50
|
+
const all = expectedMounts(name);
|
|
51
|
+
const shapes = [all, all.filter((mount) => mount[1] !== psycheTarget(name))];
|
|
45
52
|
return syncEnabled ? shapes : [...shapes, ...shapes.map((mounts) => mounts.filter((mount) => mount[1] !== SYNC_TARGET))];
|
|
46
53
|
}
|
|
47
|
-
const
|
|
48
|
-
const
|
|
54
|
+
const preGatewayBinds = (name) => expectedBinds(name).slice(0, 3);
|
|
55
|
+
const preGatewayMounts = (name) => expectedMounts(name).slice(0, 3);
|
|
49
56
|
const LEGACY_ALPHA742_IMAGE = "sha256:681449ad47a2621705cd339b481e6339236b31dc65e195b1cf5025d0f2191d7d";
|
|
50
|
-
const LEGACY_ALPHA742_MOUNTS =
|
|
57
|
+
const LEGACY_ALPHA742_MOUNTS = expectedMounts("sanctuary").slice(0, 2);
|
|
51
58
|
const EXPECTED_EXTRA_PARAMS = "--restart=unless-stopped --user=10001:10001";
|
|
52
59
|
const EXPECTED_NAME = "ouro-butler";
|
|
53
60
|
// The release's own template, then main's copy, which templates carried before releases moved off pull requests.
|
|
@@ -59,7 +66,7 @@ const EXPECTED_ICON = "https://raw.githubusercontent.com/ourostack/ouroboros/mai
|
|
|
59
66
|
const EXACT_IMAGE = /^sha256:[a-f0-9]{64}$/u;
|
|
60
67
|
const VERSION_REFERENCE = /^ghcr\.io\/ourostack\/ouroboros-butler:[0-9]+\.[0-9]+\.[0-9]+(?:-[0-9A-Za-z.-]+)?$/u;
|
|
61
68
|
// The image names the Butler `butler` from M2 on; images from before the rename name it `sanctuary`. Either runs its one bundle.
|
|
62
|
-
const
|
|
69
|
+
const packageDaemonArgs = (name) => ["/opt/ouro/dist/heart/daemon/daemon-entry.js", "--package-managed-agent", name];
|
|
63
70
|
const LEGACY_DAEMON_ARGS = ["/opt/ouro/dist/heart/daemon/daemon-entry.js"];
|
|
64
71
|
const LEGACY_ENTRYPOINT = ["node", ...LEGACY_DAEMON_ARGS];
|
|
65
72
|
function record(value) {
|
|
@@ -91,8 +98,10 @@ function auditSanctuaryContainerSpec(value, options) {
|
|
|
91
98
|
violations.push("unsupported mount contract");
|
|
92
99
|
if (mountContract === "legacy-alpha742" && options.expectedImage !== LEGACY_ALPHA742_IMAGE)
|
|
93
100
|
violations.push("legacy mount exception requires the pinned alpha.742 image ID");
|
|
94
|
-
|
|
95
|
-
const
|
|
101
|
+
// The Butler name the container runs, from its own arguments: its bundle, psyche and trust must be mounted under that name.
|
|
102
|
+
const name = butler_agent_1.BUTLER_AGENT_NAMES.find((candidate) => JSON.stringify(root.Args) === JSON.stringify(packageDaemonArgs(candidate))) ?? "sanctuary";
|
|
103
|
+
const packageArgs = packageDaemonArgs(name);
|
|
104
|
+
const acceptedMounts = mountContract === "legacy-alpha742" ? [LEGACY_ALPHA742_MOUNTS] : mountContract === "canonical-pre-gateway" ? [preGatewayMounts(name)] : gatewayMounts(options.syncEnabled === true, name);
|
|
96
105
|
const expectedArgs = mountContract !== "legacy-alpha742" ? packageArgs : LEGACY_DAEMON_ARGS;
|
|
97
106
|
const expectedEntrypoint = mountContract !== "legacy-alpha742" ? ["node", ...packageArgs] : LEGACY_ENTRYPOINT;
|
|
98
107
|
if (root.Image !== options.expectedImage)
|
|
@@ -201,7 +210,8 @@ function auditTemplate(input, expectedRepository, repositoryIsValid, repositoryV
|
|
|
201
210
|
const violations = [];
|
|
202
211
|
if (input.mountContract !== "canonical-pre-gateway" && input.mountContract !== "canonical-gateway")
|
|
203
212
|
violations.push("unsupported template mount contract");
|
|
204
|
-
|
|
213
|
+
// A template names no image arguments, so its binds may use either Butler name, but all under the same one.
|
|
214
|
+
const acceptedBinds = butler_agent_1.BUTLER_AGENT_NAMES.flatMap((name) => input.mountContract === "canonical-pre-gateway" ? [preGatewayBinds(name)] : gatewayBinds(input.syncEnabled === true, name));
|
|
205
215
|
const template = parseDockerManTemplateXml(input.templateXml);
|
|
206
216
|
if (!template)
|
|
207
217
|
violations.push("canonical DockerMan XML structure is invalid");
|
|
@@ -95,6 +95,7 @@ const sync_1 = require("../sync");
|
|
|
95
95
|
const presence_daemon_1 = require("./presence-daemon");
|
|
96
96
|
const presence_1 = require("./presence");
|
|
97
97
|
const sync_lock_1 = require("../sync-lock");
|
|
98
|
+
const router_1 = require("../external-events/router");
|
|
98
99
|
function parseSocketPath(argv) {
|
|
99
100
|
const socketIndex = argv.indexOf("--socket");
|
|
100
101
|
if (socketIndex >= 0) {
|
|
@@ -125,6 +126,8 @@ const daemonMachineId = daemonMachine.machineId;
|
|
|
125
126
|
const managedAgents = (0, agent_discovery_1.listHomeBundleAgents)({ machineId: daemonMachineId });
|
|
126
127
|
// The Butler under whichever name its bundle has; its container paths follow that name.
|
|
127
128
|
const butlerName = (0, butler_agent_1.managedButlerAgent)(managedAgents) ?? "sanctuary";
|
|
129
|
+
// Its saved external events follow that name too: a folder left under the other name (by the rename or a rollback) moves over.
|
|
130
|
+
(0, router_1.prepareButlerExternalEvents)((0, router_1.getExternalEventRoot)(), managedAgents);
|
|
128
131
|
const readinessAgents = (0, daemon_bootstrap_startup_1.providerReadinessAgents)(managedAgents, process.env.OURO_DAEMON_REQUIRED_AGENT);
|
|
129
132
|
const sanctuaryPackageManagement = (0, sanctuary_package_management_1.resolveSanctuaryPackageManagementActivation)({ mode, argv: process.argv, managedAgents, repoRoot: (0, identity_1.getRepoRoot)(), bundlesRoot: (0, identity_1.getAgentBundlesRoot)(), runtimePackageVersion: (0, bundle_manifest_1.getPackageVersion)() });
|
|
130
133
|
try {
|