@ouro.bot/cli 0.1.0-alpha.1636 → 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 +11 -3
- package/deploy/unraid/migrate-sanctuary-bundle.mjs +8 -3
- 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/daemon/daemon-entry.js +3 -0
- 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
package/changelog.json
CHANGED
|
@@ -2,12 +2,20 @@
|
|
|
2
2
|
"_note": "Each pull request writes its own change note under changes/; the release job on main gives each landed change its version and adds the notes here (scripts/release-version.cjs). On main this file stops at the last version set by hand; the published package has every release. Agents read this file directly via read_file to understand what changed between versions.",
|
|
3
3
|
"versions": [
|
|
4
4
|
{
|
|
5
|
-
"version": "0.1.0-alpha.
|
|
5
|
+
"version": "0.1.0-alpha.1637",
|
|
6
|
+
"changes": [
|
|
7
|
+
"The Butler's host tools now read the Butler's name from the image they start (the name after `--package-managed-agent` in its entrypoint, else `sanctuary`). They use that name for every path inside the container: the bundle mount, the psyche mount, the trust mount `/etc/ouro/trust/<name>`, the vault and token containers, the bw profile, the replay gate, the sync cutover and the DockerMan template's bundle and trust Targets. The folders on the host never move: the bundle stays at `/mnt/user/appdata/ouro-butler/agent/sanctuary.ouro` and trust stays at `trust/sanctuary`. Resident mounts now use `--mount`, so a missing host folder stops the start instead of mounting an empty one. Preflight also refuses a leftover credential handoff that names another Butler, and a DockerMan template that can't be moved to the image's name. Every image still says `sanctuary`, so nothing changes until a release renames it.",
|
|
8
|
+
"The Butler's media tools and its house rules no longer assume the bundle is mounted at `sanctuary.ouro`: the media server finds its credentials and state next to itself, and the instruction for house notes names `psyche/TACIT.md` in the bundle. Nothing changes for an install that is still called sanctuary.",
|
|
9
|
+
"When the daemon runs the Butler under one name and finds its saved external events under the other name, it moves that folder over at start and treats those events as the running Butler's. If both folders exist it leaves both and logs a warning. A rollback moves them back the same way.",
|
|
10
|
+
"The bundle migration takes `--butler-name <butler|sanctuary>`. When the bundle's own files (agent.json, the replay client's provision.json, recent attachments, skills and HOUSE.md) name the other Butler's container path, it points them at this one. The rollback record holds those files, so a rollback restores them exactly. Psyche, friends, sessions and logs are never touched."
|
|
11
|
+
]
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"version": "0.1.0-alpha.1635",
|
|
6
15
|
"changes": [
|
|
7
16
|
"The Butler's Telegram front door runs under either of the Butler's names. This covers the root gateway's transport, the owner's and household's privileges, the Butler tools, the privileged failsafe, and the SABnzbd key it reads to verify a protective pause.",
|
|
8
17
|
"The privileged event spool keeps its events and replay manifest under the name of the Butler the daemon runs. An envelope from the host's emitter that still names the Butler by its other name is filed there too, so usenet alerts survive the rename.",
|
|
9
|
-
"The vault handoff, root-host approvals and the health sweep's acceptance marker each follow the Butler's bundle name. The vault's machine id stays `sanctuary`."
|
|
10
|
-
"The Butler's host tools now read the Butler's name from the image they start (the name after `--package-managed-agent` in its entrypoint, else `sanctuary`). They use that name for every path inside the container: the bundle mount, the psyche mount, the trust mount `/etc/ouro/trust/<name>`, the vault and token containers, the bw profile, the replay gate, the sync cutover and the DockerMan template's bundle and trust Targets. The folders on the host never move: the bundle stays at `/mnt/user/appdata/ouro-butler/agent/sanctuary.ouro` and trust stays at `trust/sanctuary`. Resident mounts now use `--mount`, so a missing host folder stops the start instead of mounting an empty one. Preflight also refuses a leftover credential handoff that names another Butler, and a DockerMan template that can't be moved to the image's name. Every image still says `sanctuary`, so nothing changes until a release renames it."
|
|
18
|
+
"The vault handoff, root-host approvals and the health sweep's acceptance marker each follow the Butler's bundle name. The vault's machine id stays `sanctuary`."
|
|
11
19
|
]
|
|
12
20
|
},
|
|
13
21
|
{
|
|
@@ -2,9 +2,13 @@
|
|
|
2
2
|
import * as path from "node:path"
|
|
3
3
|
import { pathToFileURL } from "node:url"
|
|
4
4
|
|
|
5
|
-
const USAGE = "Usage: migrate-sanctuary-bundle.mjs --package-root <path> --agent-root <path> --operation <migrate|seed|rollback|finalize-rollback|commit|status|inspect> [--rollback-image-id <sha256:id> --target-image-id <sha256:id>]"
|
|
5
|
+
const USAGE = "Usage: migrate-sanctuary-bundle.mjs --package-root <path> --agent-root <path> --operation <migrate|seed|rollback|finalize-rollback|commit|status|inspect> [--rollback-image-id <sha256:id> --target-image-id <sha256:id> [--butler-name <butler|sanctuary>]]"
|
|
6
6
|
const BASE_KEYS = ["--package-root", "--agent-root", "--operation"]
|
|
7
7
|
const MIGRATE_KEYS = [...BASE_KEYS, "--rollback-image-id", "--target-image-id"]
|
|
8
|
+
// The Butler the image being installed runs. The host's bundle folder keeps its name, so the migrate is told which
|
|
9
|
+
// container path the bundle's own files should name; without it, the agent root's folder name says.
|
|
10
|
+
const BUTLER_NAME_KEY = "--butler-name"
|
|
11
|
+
const BUTLER_NAMES = ["butler", "sanctuary"]
|
|
8
12
|
|
|
9
13
|
function parseArguments(args) {
|
|
10
14
|
if (args.length % 2 !== 0) throw new Error(USAGE)
|
|
@@ -17,7 +21,8 @@ function parseArguments(args) {
|
|
|
17
21
|
}
|
|
18
22
|
const operation = values.get("--operation")
|
|
19
23
|
if (!["migrate", "seed", "rollback", "finalize-rollback", "commit", "status", "inspect"].includes(operation)) throw new Error(USAGE)
|
|
20
|
-
const expectedKeys = operation === "migrate" ? MIGRATE_KEYS : BASE_KEYS
|
|
24
|
+
const expectedKeys = operation === "migrate" ? (values.has(BUTLER_NAME_KEY) ? [...MIGRATE_KEYS, BUTLER_NAME_KEY] : MIGRATE_KEYS) : BASE_KEYS
|
|
25
|
+
if (values.has(BUTLER_NAME_KEY) && !BUTLER_NAMES.includes(values.get(BUTLER_NAME_KEY))) throw new Error(USAGE)
|
|
21
26
|
if (values.size !== expectedKeys.length || expectedKeys.some((key) => !values.has(key)) || [...values.keys()].some((key) => !expectedKeys.includes(key))) throw new Error(USAGE)
|
|
22
27
|
return values
|
|
23
28
|
}
|
|
@@ -28,7 +33,7 @@ export function runSanctuaryBundleOperation(args, dependencies) {
|
|
|
28
33
|
const agentRoot = values.get("--agent-root")
|
|
29
34
|
const operation = values.get("--operation")
|
|
30
35
|
const result = operation === "migrate"
|
|
31
|
-
? dependencies.migrate({ packageRoot, agentRoot, retainRollback: true, rollbackImageId: values.get("--rollback-image-id"), targetImageId: values.get("--target-image-id") })
|
|
36
|
+
? dependencies.migrate({ packageRoot, agentRoot, retainRollback: true, rollbackImageId: values.get("--rollback-image-id"), targetImageId: values.get("--target-image-id"), butlerName: values.has(BUTLER_NAME_KEY) ? values.get(BUTLER_NAME_KEY) : null })
|
|
32
37
|
// A fresh install has no earlier image to roll back to, so it writes the packaged files without a rollback record.
|
|
33
38
|
: operation === "seed"
|
|
34
39
|
? dependencies.migrate({ packageRoot, agentRoot, retainRollback: false })
|
|
@@ -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>
|
|
@@ -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 {
|
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.SANCTUARY_GIT_EXCLUDES = exports.SANCTUARY_BUNDLE_ROLLBACK_FILE = exports.SANCTUARY_STARTER_PSYCHE_FILES = exports.SANCTUARY_PACKAGE_MANAGED_FILES = void 0;
|
|
36
|
+
exports.SANCTUARY_BUNDLE_PATH_FILES = exports.SANCTUARY_GIT_EXCLUDES = exports.SANCTUARY_BUNDLE_ROLLBACK_FILE = exports.SANCTUARY_STARTER_PSYCHE_FILES = exports.SANCTUARY_PACKAGE_MANAGED_FILES = void 0;
|
|
37
37
|
exports.sanctuaryGitExcludeText = sanctuaryGitExcludeText;
|
|
38
38
|
exports.bundleSyncEnabled = bundleSyncEnabled;
|
|
39
39
|
exports.writeSanctuaryGitExclude = writeSanctuaryGitExclude;
|
|
@@ -52,6 +52,7 @@ const node_child_process_1 = require("node:child_process");
|
|
|
52
52
|
const node_crypto_1 = require("node:crypto");
|
|
53
53
|
const runtime_1 = require("../../nerves/runtime");
|
|
54
54
|
const house_names_1 = require("../../mind/house-names");
|
|
55
|
+
const butler_agent_1 = require("../butler-agent");
|
|
55
56
|
exports.SANCTUARY_PACKAGE_MANAGED_FILES = [
|
|
56
57
|
"provider-readiness.json",
|
|
57
58
|
"tool-profiles.json",
|
|
@@ -315,6 +316,60 @@ function writeAtomic(filePath, content, mode = 0o600) {
|
|
|
315
316
|
syncDirectory(path.dirname(filePath));
|
|
316
317
|
}
|
|
317
318
|
const SNAPSHOT_RELATIVES = [...exports.SANCTUARY_PACKAGE_MANAGED_FILES, "bundle-meta.json"];
|
|
319
|
+
/**
|
|
320
|
+
* The install's own files that name the bundle's container path, and so follow the Butler's name on a migrate. Nothing
|
|
321
|
+
* else is rewritten: never psyche/, friends/, sessions or logs. `skills/*.md` stands for every skill file at the top of skills/.
|
|
322
|
+
*/
|
|
323
|
+
exports.SANCTUARY_BUNDLE_PATH_FILES = ["agent.json", "state/replay-client/provision.json", "state/attachments/recent.json", "skills/*.md", "house/HOUSE.md"];
|
|
324
|
+
const SKILL_FILE = /^skills\/[^/]+\.md$/u;
|
|
325
|
+
function isBundlePathFile(relative) {
|
|
326
|
+
return SKILL_FILE.test(relative) || exports.SANCTUARY_BUNDLE_PATH_FILES.includes(relative);
|
|
327
|
+
}
|
|
328
|
+
const containerBundlePath = (name) => `/home/ouro/AgentBundles/${name}.ouro`;
|
|
329
|
+
/**
|
|
330
|
+
* The Butler a migrate runs for: the one it is told, or the one its agent root is named after; null for any other bundle,
|
|
331
|
+
* and for `null`, which the host passes when it names no Butler: its folder keeps the name `sanctuary` whatever the image runs.
|
|
332
|
+
*/
|
|
333
|
+
function migrationButlerName(agentRoot, given) {
|
|
334
|
+
if (given !== undefined)
|
|
335
|
+
return given;
|
|
336
|
+
const name = path.basename(agentRoot).replace(/\.ouro$/u, "");
|
|
337
|
+
return (0, butler_agent_1.isButlerAgent)(name) ? name : null;
|
|
338
|
+
}
|
|
339
|
+
/** The allowlisted files that name the other Butler's container path, with that path changed to `name`'s. */
|
|
340
|
+
function planBundlePathRewrites(agentRoot, name) {
|
|
341
|
+
if (!name)
|
|
342
|
+
return [];
|
|
343
|
+
const other = butler_agent_1.BUTLER_AGENT_NAMES.find((candidate) => candidate !== name);
|
|
344
|
+
// The other bundle's path, and not a longer folder name that starts with it.
|
|
345
|
+
const escaped = containerBundlePath(other).replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
346
|
+
const pattern = new RegExp(`${escaped}(?![A-Za-z0-9._-])`, "gu");
|
|
347
|
+
const skills = path.join(agentRoot, "skills");
|
|
348
|
+
let skillFiles = [];
|
|
349
|
+
try {
|
|
350
|
+
if (fs.statSync(skills).isDirectory())
|
|
351
|
+
skillFiles = fs.readdirSync(skills).filter((entry) => entry.endsWith(".md")).sort().map((entry) => `skills/${entry}`);
|
|
352
|
+
}
|
|
353
|
+
catch (error) {
|
|
354
|
+
if (!isMissing(error))
|
|
355
|
+
throw error;
|
|
356
|
+
}
|
|
357
|
+
const relatives = [...exports.SANCTUARY_BUNDLE_PATH_FILES.filter((relative) => !relative.includes("*")), ...skillFiles];
|
|
358
|
+
const rewrites = [];
|
|
359
|
+
for (const relative of relatives) {
|
|
360
|
+
const filePath = path.join(agentRoot, relative);
|
|
361
|
+
if (!fs.existsSync(filePath) || !fs.statSync(filePath).isFile())
|
|
362
|
+
continue;
|
|
363
|
+
const text = fs.readFileSync(filePath, "utf8");
|
|
364
|
+
const next = text.replace(pattern, containerBundlePath(name));
|
|
365
|
+
if (next === text)
|
|
366
|
+
continue;
|
|
367
|
+
// Only a file that needs the rewrite must be a real one inside the bundle; anything else is left as it is.
|
|
368
|
+
validateDestination(agentRoot, relative);
|
|
369
|
+
rewrites.push({ relative, content: Buffer.from(next, "utf8"), mode: fs.lstatSync(filePath).mode & 0o777 });
|
|
370
|
+
}
|
|
371
|
+
return rewrites;
|
|
372
|
+
}
|
|
318
373
|
function packageManagedArtifactPaths(agentRoot) {
|
|
319
374
|
return SNAPSHOT_RELATIVES.map((relative) => path.join(agentRoot, relative));
|
|
320
375
|
}
|
|
@@ -377,8 +432,8 @@ function snapshotDirectoryRelatives() {
|
|
|
377
432
|
}
|
|
378
433
|
return [...directories].sort((left, right) => left.length - right.length);
|
|
379
434
|
}
|
|
380
|
-
function captureMigrationSnapshot(agentRoot) {
|
|
381
|
-
const files = SNAPSHOT_RELATIVES.map((relative) => {
|
|
435
|
+
function captureMigrationSnapshot(agentRoot, extraRelatives = []) {
|
|
436
|
+
const files = [...SNAPSHOT_RELATIVES, ...extraRelatives].map((relative) => {
|
|
382
437
|
const filePath = path.join(agentRoot, relative);
|
|
383
438
|
if (!fs.existsSync(filePath))
|
|
384
439
|
return { path: filePath, content: null, mode: null };
|
|
@@ -447,9 +502,12 @@ function readDurableRecord(agentRoot) {
|
|
|
447
502
|
const fileRelatives = record.files.map((file) => file?.relative);
|
|
448
503
|
const directoryRelatives = record.directories.map((directory) => directory?.relative);
|
|
449
504
|
const expectedDirectories = snapshotDirectoryRelatives();
|
|
450
|
-
|
|
505
|
+
// After the managed files come any bundle-path files the migrate rewrote, each once and each on the allowlist.
|
|
506
|
+
const extraRelatives = fileRelatives.slice(SNAPSHOT_RELATIVES.length);
|
|
507
|
+
const validExtras = extraRelatives.every((relative) => typeof relative === "string" && isBundlePathFile(relative)) && new Set(extraRelatives).size === extraRelatives.length;
|
|
508
|
+
if (JSON.stringify(fileRelatives.slice(0, SNAPSHOT_RELATIVES.length)) !== JSON.stringify(SNAPSHOT_RELATIVES) || !validExtras || JSON.stringify(directoryRelatives) !== JSON.stringify(expectedDirectories))
|
|
451
509
|
throw new Error("Sanctuary bundle rollback record paths are invalid");
|
|
452
|
-
for (const relative of SNAPSHOT_RELATIVES)
|
|
510
|
+
for (const relative of [...SNAPSHOT_RELATIVES, ...extraRelatives])
|
|
453
511
|
validateDestination(agentRoot, relative);
|
|
454
512
|
const validMode = (mode) => mode === null || (Number.isInteger(mode) && mode >= 0 && mode <= 0o777);
|
|
455
513
|
const files = record.files.map((file) => {
|
|
@@ -916,8 +974,10 @@ function migrateSanctuaryPackageManagedBundle(input) {
|
|
|
916
974
|
if (!(field in packagedMeta))
|
|
917
975
|
throw new Error(`packaged bundle-meta.json is missing ${field}`);
|
|
918
976
|
validatePackagedPolicy(input.packageRoot);
|
|
919
|
-
|
|
920
|
-
|
|
977
|
+
const rewrites = planBundlePathRewrites(input.agentRoot, migrationButlerName(input.agentRoot, input.butlerName));
|
|
978
|
+
const rewriteModes = new Map(rewrites.map((rewrite) => [path.join(input.agentRoot, rewrite.relative), rewrite.mode]));
|
|
979
|
+
cleanupInterruptedWrites([...packageManagedArtifactPaths(input.agentRoot), ...rewriteModes.keys()], rewriteModes);
|
|
980
|
+
snapshot = captureMigrationSnapshot(input.agentRoot, rewrites.map((rewrite) => rewrite.relative));
|
|
921
981
|
if (input.retainRollback) {
|
|
922
982
|
writeAtomic(existingRollback, `${JSON.stringify(durableSnapshot(input.agentRoot, snapshot, input.rollbackImageId, input.targetImageId))}\n`);
|
|
923
983
|
}
|
|
@@ -950,9 +1010,14 @@ function migrateSanctuaryPackageManagedBundle(input) {
|
|
|
950
1010
|
fs.closeSync(meta);
|
|
951
1011
|
}
|
|
952
1012
|
}
|
|
1013
|
+
// The install's own files that name the bundle's container path now name the Butler this release runs.
|
|
1014
|
+
for (const rewrite of rewrites)
|
|
1015
|
+
writeAtomic(path.join(input.agentRoot, rewrite.relative), rewrite.content, rewrite.mode);
|
|
1016
|
+
if (rewrites.length > 0)
|
|
1017
|
+
(0, runtime_1.emitNervesEvent)({ component: "daemon", event: "daemon.sanctuary_bundle_paths_rewritten", message: "pointed the bundle's own container paths at the Butler's name", meta: { agentRoot: input.agentRoot, files: rewrites.map((rewrite) => rewrite.relative) } });
|
|
953
1018
|
if (!seedSanctuaryPsycheIfAbsent({ packageRoot: input.packageRoot, agentRoot: input.agentRoot }).ok)
|
|
954
1019
|
throw new Error("psyche must be a real directory, not a symlink or file");
|
|
955
|
-
const result = { managedFilesUpdated };
|
|
1020
|
+
const result = { managedFilesUpdated, ...(rewrites.length > 0 ? { bundlePathsRewritten: rewrites.length } : {}) };
|
|
956
1021
|
(0, runtime_1.emitNervesEvent)({ component: "daemon", event: "daemon.sanctuary_bundle_migration_end", message: "completed Sanctuary package-managed bundle migration", meta: result });
|
|
957
1022
|
return result;
|
|
958
1023
|
}
|
|
@@ -37,6 +37,7 @@ exports.ExternalEventScanCache = void 0;
|
|
|
37
37
|
exports.getExternalEventRoot = getExternalEventRoot;
|
|
38
38
|
exports.externalEventRecordPath = externalEventRecordPath;
|
|
39
39
|
exports.readExternalEventRecord = readExternalEventRecord;
|
|
40
|
+
exports.prepareButlerExternalEvents = prepareButlerExternalEvents;
|
|
40
41
|
exports.repairExternalEventsFromManifest = repairExternalEventsFromManifest;
|
|
41
42
|
exports.listExternalEventStatus = listExternalEventStatus;
|
|
42
43
|
exports.buildExternalEventMessage = buildExternalEventMessage;
|
|
@@ -318,17 +319,87 @@ function isRecord(value) {
|
|
|
318
319
|
&& validFailure
|
|
319
320
|
&& validGrant;
|
|
320
321
|
}
|
|
321
|
-
|
|
322
|
+
// The Butler this daemon runs, set once at daemon start. Records saved under the Butler's other name are its records.
|
|
323
|
+
let runningButler = null;
|
|
324
|
+
/** The agent a record or new event belongs to: a Butler name means the running Butler, or the Butler folder it sits in. */
|
|
325
|
+
function eventAgent(agent, folder) {
|
|
326
|
+
if (!(0, butler_agent_1.isButlerAgent)(agent))
|
|
327
|
+
return agent;
|
|
328
|
+
if (runningButler)
|
|
329
|
+
return runningButler;
|
|
330
|
+
return folder !== undefined && (0, butler_agent_1.isButlerAgent)(folder) ? folder : agent;
|
|
331
|
+
}
|
|
332
|
+
/** The record as the daemon sees it: owned by the running Butler, at the path it was read from. */
|
|
333
|
+
function normaliseButlerRecord(record, recordPath) {
|
|
334
|
+
const agent = eventAgent(record.agent, path.basename(path.dirname(path.dirname(recordPath))));
|
|
335
|
+
return agent === record.agent && record.recordPath === recordPath ? record : { ...record, agent, recordPath };
|
|
336
|
+
}
|
|
337
|
+
/** The record exactly as saved, after checking it sits where its identity says (or in the other Butler name's folder). */
|
|
338
|
+
function readStoredExternalEventRecord(recordPath) {
|
|
322
339
|
const parsed = JSON.parse(fs.readFileSync(recordPath, "utf8"));
|
|
323
340
|
if (!isRecord(parsed))
|
|
324
341
|
throw new Error(`External event record is invalid: ${recordPath}`);
|
|
325
342
|
const root = path.dirname(path.dirname(path.dirname(recordPath)));
|
|
326
|
-
const
|
|
327
|
-
|
|
343
|
+
const here = path.resolve(recordPath);
|
|
344
|
+
const expectedPath = path.resolve(externalEventRecordPath(root, parsed));
|
|
345
|
+
if (path.resolve(parsed.recordPath) === here && expectedPath === here)
|
|
346
|
+
return parsed;
|
|
347
|
+
// A Butler record whose folder was adopted under the Butler's other name: it names the folder it was written in, or this one.
|
|
348
|
+
const folder = path.basename(path.dirname(path.dirname(recordPath)));
|
|
349
|
+
const adopted = (0, butler_agent_1.isButlerAgent)(parsed.agent) && (0, butler_agent_1.isButlerAgent)(folder)
|
|
350
|
+
&& path.resolve(externalEventRecordPath(root, { ...parsed, agent: folder })) === here
|
|
351
|
+
&& [here, expectedPath].includes(path.resolve(parsed.recordPath));
|
|
352
|
+
if (!adopted)
|
|
328
353
|
throw new Error(`External event record identity is invalid: ${recordPath}`);
|
|
329
|
-
}
|
|
330
354
|
return parsed;
|
|
331
355
|
}
|
|
356
|
+
function readExternalEventRecord(recordPath) {
|
|
357
|
+
return normaliseButlerRecord(readStoredExternalEventRecord(recordPath), recordPath);
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* At daemon start, the running Butler takes over the event folder saved under its other name (from before the rename,
|
|
361
|
+
* or from the release a rollback left). A same-filesystem rename; with both folders present, both stay and it warns.
|
|
362
|
+
*/
|
|
363
|
+
function prepareButlerExternalEvents(root, managedAgents) {
|
|
364
|
+
const butler = (0, butler_agent_1.managedButlerAgent)(managedAgents);
|
|
365
|
+
runningButler = butler;
|
|
366
|
+
if (!butler)
|
|
367
|
+
return "none";
|
|
368
|
+
const own = path.join(root, butler);
|
|
369
|
+
const others = butler_agent_1.BUTLER_AGENT_NAMES.filter((name) => name !== butler).map((name) => path.join(root, name)).filter((dir) => fs.existsSync(dir));
|
|
370
|
+
if (others.length === 0)
|
|
371
|
+
return "none";
|
|
372
|
+
if (fs.existsSync(own)) {
|
|
373
|
+
(0, runtime_1.emitNervesEvent)({
|
|
374
|
+
level: "warn",
|
|
375
|
+
component: "daemon",
|
|
376
|
+
event: "daemon.external_events_adoption_conflict",
|
|
377
|
+
message: "both Butler names have external-event folders; leaving both in place",
|
|
378
|
+
meta: { butler, own, others },
|
|
379
|
+
});
|
|
380
|
+
return "both-present";
|
|
381
|
+
}
|
|
382
|
+
try {
|
|
383
|
+
fs.renameSync(others[0], own);
|
|
384
|
+
}
|
|
385
|
+
catch (error) {
|
|
386
|
+
(0, runtime_1.emitNervesEvent)({
|
|
387
|
+
level: "warn",
|
|
388
|
+
component: "daemon",
|
|
389
|
+
event: "daemon.external_events_adoption_failed",
|
|
390
|
+
message: "could not move the Butler's other-name external-event folder",
|
|
391
|
+
meta: { butler, from: others[0], to: own, error: error instanceof Error ? error.message : /* v8 ignore next -- fs throws Error objects @preserve */ String(error) },
|
|
392
|
+
});
|
|
393
|
+
return "failed";
|
|
394
|
+
}
|
|
395
|
+
(0, runtime_1.emitNervesEvent)({
|
|
396
|
+
component: "daemon",
|
|
397
|
+
event: "daemon.external_events_adopted",
|
|
398
|
+
message: "moved the Butler's other-name external-event folder to the running Butler",
|
|
399
|
+
meta: { butler, from: others[0], to: own },
|
|
400
|
+
});
|
|
401
|
+
return "adopted";
|
|
402
|
+
}
|
|
332
403
|
const MAX_REPAIR_MANIFEST_BYTES = 1024 * 1024;
|
|
333
404
|
const MAX_REPAIR_ENTRIES = 512;
|
|
334
405
|
const SHA256_HEX = /^[a-f0-9]{64}$/u;
|
|
@@ -409,9 +480,17 @@ function parseRepairManifest(manifestPath) {
|
|
|
409
480
|
}
|
|
410
481
|
return value;
|
|
411
482
|
}
|
|
483
|
+
/** The folder a reviewed repair's record is in: its own agent's, or the other Butler name's once the daemon adopted it. */
|
|
484
|
+
function repairFolderAgent(root, entry) {
|
|
485
|
+
if (!(0, butler_agent_1.isButlerAgent)(entry.agent))
|
|
486
|
+
return entry.agent;
|
|
487
|
+
const names = [entry.agent, ...butler_agent_1.BUTLER_AGENT_NAMES.filter((name) => name !== entry.agent)];
|
|
488
|
+
return names.find((agent) => fs.existsSync(externalEventRecordPath(root, { ...entry, agent }))) ?? entry.agent;
|
|
489
|
+
}
|
|
412
490
|
function assertRepairRecordPath(root, entry) {
|
|
413
491
|
const resolvedRoot = path.resolve(root);
|
|
414
|
-
const
|
|
492
|
+
const folderAgent = repairFolderAgent(resolvedRoot, entry);
|
|
493
|
+
const recordPath = externalEventRecordPath(resolvedRoot, { ...entry, agent: folderAgent });
|
|
415
494
|
const relative = path.relative(resolvedRoot, path.resolve(recordPath));
|
|
416
495
|
/* v8 ignore next -- defense in depth: safePathSegment cannot emit traversal @preserve */
|
|
417
496
|
if (relative.startsWith("..") || path.isAbsolute(relative))
|
|
@@ -425,8 +504,8 @@ function assertRepairRecordPath(root, entry) {
|
|
|
425
504
|
}
|
|
426
505
|
const expected = [
|
|
427
506
|
[resolvedRoot, "directory"],
|
|
428
|
-
[path.join(resolvedRoot, safePathSegment(
|
|
429
|
-
[path.join(resolvedRoot, safePathSegment(
|
|
507
|
+
[path.join(resolvedRoot, safePathSegment(folderAgent)), "directory"],
|
|
508
|
+
[path.join(resolvedRoot, safePathSegment(folderAgent), safePathSegment(entry.source)), "directory"],
|
|
430
509
|
[recordPath, "file"],
|
|
431
510
|
];
|
|
432
511
|
for (const [candidate, kind] of expected) {
|
|
@@ -467,7 +546,7 @@ function repairExternalEventsFromManifest(manifestPath, options) {
|
|
|
467
546
|
const recordPath = assertRepairRecordPath(root, entry);
|
|
468
547
|
const raw = fs.readFileSync(recordPath);
|
|
469
548
|
const digest = digestBytes(raw);
|
|
470
|
-
const record =
|
|
549
|
+
const record = readStoredExternalEventRecord(recordPath);
|
|
471
550
|
if (digest === entry.postimageSha256) {
|
|
472
551
|
assertRepairPostimage(record, entry, manifest.repairedAt);
|
|
473
552
|
prepared.push({ entry, recordPath, state: "post" });
|
|
@@ -504,13 +583,13 @@ function repairExternalEventsFromManifest(manifestPath, options) {
|
|
|
504
583
|
const raw = fs.readFileSync(item.recordPath);
|
|
505
584
|
const digest = digestBytes(raw);
|
|
506
585
|
if (digest === item.entry.postimageSha256) {
|
|
507
|
-
assertRepairPostimage(
|
|
586
|
+
assertRepairPostimage(readStoredExternalEventRecord(item.recordPath), item.entry, manifest.repairedAt);
|
|
508
587
|
result.alreadyApplied.push(identity);
|
|
509
588
|
return;
|
|
510
589
|
}
|
|
511
590
|
if (digest !== item.entry.preimageSha256)
|
|
512
591
|
throw new Error("record advanced after prevalidation");
|
|
513
|
-
const record =
|
|
592
|
+
const record = readStoredExternalEventRecord(item.recordPath);
|
|
514
593
|
atomicWrite(item.recordPath, repairedRecord(record, manifest.repairedAt));
|
|
515
594
|
result.applied.push(identity);
|
|
516
595
|
});
|
|
@@ -686,7 +765,7 @@ function readExisting(recordPath) {
|
|
|
686
765
|
try {
|
|
687
766
|
const parsed = JSON.parse(fs.readFileSync(recordPath, "utf8"));
|
|
688
767
|
if (isRecord(parsed))
|
|
689
|
-
return { record: parsed, corruptDuplicateCount: 0 };
|
|
768
|
+
return { record: normaliseButlerRecord(parsed, recordPath), corruptDuplicateCount: 0 };
|
|
690
769
|
const duplicateCount = parsed && typeof parsed === "object" && !Array.isArray(parsed) && typeof parsed.duplicateCount === "number"
|
|
691
770
|
? Number(parsed.duplicateCount) + 1
|
|
692
771
|
: 1;
|
|
@@ -741,8 +820,10 @@ const EXHAUSTED_RECOVERY_SLOTS = 6;
|
|
|
741
820
|
function exhaustedRecoverySlot(record) {
|
|
742
821
|
return (0, node_crypto_1.createHash)("sha256").update(`${record.agent}\0${record.source}\0${record.eventId}`).digest().readUInt32BE(0) % EXHAUSTED_RECOVERY_SLOTS;
|
|
743
822
|
}
|
|
744
|
-
function recordExternalEventInternal(
|
|
745
|
-
validateExternalEventInput(
|
|
823
|
+
function recordExternalEventInternal(given, options = {}) {
|
|
824
|
+
validateExternalEventInput(given);
|
|
825
|
+
// An event naming the Butler's other name is the running Butler's, filed in its folder.
|
|
826
|
+
const input = { ...given, agent: eventAgent(given.agent) };
|
|
746
827
|
const now = options.now?.() ?? new Date().toISOString();
|
|
747
828
|
const root = options.root ?? getExternalEventRoot();
|
|
748
829
|
const recordPath = externalEventRecordPath(root, input);
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ouro.bot/cli",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.1637",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@ouro.bot/cli",
|
|
9
|
-
"version": "0.1.0-alpha.
|
|
9
|
+
"version": "0.1.0-alpha.1637",
|
|
10
10
|
"bundleDependencies": [
|
|
11
11
|
"@ouro.bot/friends"
|
|
12
12
|
],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ouro.bot/cli",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.1637",
|
|
4
4
|
"description": "Ouroboros, the agent harness: agents with durable memory that live where you talk (terminal, Teams, iMessage, mail, voice) and use real tools. Start with npx ouro.bot@latest.",
|
|
5
5
|
"homepage": "https://ouroboros.bot/",
|
|
6
6
|
"engines": {
|