@ouro.bot/cli 0.1.0-alpha.1634 → 0.1.0-alpha.1636

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.
@@ -1,8 +1,44 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
2
35
  Object.defineProperty(exports, "__esModule", { value: true });
3
36
  exports.migrateSanctuaryAuthorityVault = migrateSanctuaryAuthorityVault;
4
37
  const runtime_credentials_1 = require("../runtime-credentials");
38
+ const fs = __importStar(require("node:fs"));
5
39
  const runtime_1 = require("../../nerves/runtime");
40
+ const identity_1 = require("../identity");
41
+ const butler_agent_1 = require("../butler-agent");
6
42
  function identity(value) {
7
43
  const candidate = value;
8
44
  if (!candidate || typeof candidate.token !== "string" || !/^[1-9][0-9]*:[A-Za-z0-9_-]{20,}$/u.test(candidate.token)
@@ -11,10 +47,11 @@ function identity(value) {
11
47
  throw new Error("Sanctuary vault token identity is invalid");
12
48
  return candidate;
13
49
  }
14
- async function readOwners() {
50
+ async function readOwners(agent) {
51
+ // The second argument is the machine id, which stays "sanctuary" through the rename.
15
52
  const results = [
16
- await (0, runtime_credentials_1.refreshRuntimeCredentialConfig)("sanctuary"),
17
- await (0, runtime_credentials_1.refreshMachineRuntimeCredentialConfig)("sanctuary", "sanctuary"),
53
+ await (0, runtime_credentials_1.refreshRuntimeCredentialConfig)(agent),
54
+ await (0, runtime_credentials_1.refreshMachineRuntimeCredentialConfig)(agent, "sanctuary"),
18
55
  ];
19
56
  return results.map((result) => {
20
57
  if (result.ok)
@@ -31,14 +68,15 @@ function absent(owners) {
31
68
  }
32
69
  // Invoked only by the fixed root migration process, never by the resident daemon.
33
70
  // Snapshot output travels through a private pipe to the root transaction, not logs.
34
- async function migrateSanctuaryAuthorityVault(operation, input) {
71
+ /** `agent` defaults to the Butler whose bundle the vault container mounts, and to its name from before the rename. */
72
+ async function migrateSanctuaryAuthorityVault(operation, input, agent = (0, butler_agent_1.butlerOnDisk)((0, identity_1.getAgentBundlesRoot)(), fs.existsSync) ?? "sanctuary") {
35
73
  if (process.getuid() !== 0 || process.getgid() !== 0)
36
74
  throw new Error("Sanctuary vault migration requires root");
37
75
  if (!["snapshot", "presence", "absent", "remove", "restore"].includes(operation))
38
76
  throw new Error("Sanctuary vault migration operation is invalid");
39
77
  (0, runtime_1.emitNervesEvent)({ component: "daemon", event: "daemon.sanctuary_vault_handoff_requested", message: "Sanctuary vault handoff requested", meta: { operation } });
40
78
  const supplied = operation === "restore" ? identity(input) : null;
41
- const owners = await readOwners();
79
+ const owners = await readOwners(agent);
42
80
  if (operation === "presence")
43
81
  return { tokenPresent: owners.some((owner) => Object.hasOwn(owner, "telegramBotToken")) };
44
82
  if (operation === "absent")
@@ -66,9 +104,9 @@ async function migrateSanctuaryAuthorityVault(operation, input) {
66
104
  }
67
105
  // Full replacement is intentional here: merge cannot remove a credential.
68
106
  // Each replacement starts from a fresh read of its own canonical owner.
69
- await (0, runtime_credentials_1.upsertRuntimeCredentialConfig)("sanctuary", next[0]);
70
- await (0, runtime_credentials_1.upsertMachineRuntimeCredentialConfig)("sanctuary", "sanctuary", next[1]);
71
- const readback = await readOwners();
107
+ await (0, runtime_credentials_1.upsertRuntimeCredentialConfig)(agent, next[0]);
108
+ await (0, runtime_credentials_1.upsertMachineRuntimeCredentialConfig)(agent, "sanctuary", next[1]);
109
+ const readback = await readOwners(agent);
72
110
  if (!supplied)
73
111
  return absent(readback);
74
112
  absent([readback[1]]);
@@ -1019,11 +1019,11 @@ function acquirePrivilegedReplayLock(sourceDir) {
1019
1019
  }
1020
1020
  return null;
1021
1021
  }
1022
- function replayStatePath(eventRoot) {
1023
- return path.join(eventRoot, "sanctuary", PRIVILEGED_EVENT_SOURCE, PRIVILEGED_REPLAY_STATE_FILE);
1022
+ function replayStatePath(eventRoot, agent) {
1023
+ return path.join(eventRoot, agent, PRIVILEGED_EVENT_SOURCE, PRIVILEGED_REPLAY_STATE_FILE);
1024
1024
  }
1025
- function replayStateFromManifest(manifest, updatedAt) {
1026
- return { schemaVersion: 1, agent: "sanctuary", source: PRIVILEGED_EVENT_SOURCE, ...manifest, updatedAt };
1025
+ function replayStateFromManifest(manifest, updatedAt, agent) {
1026
+ return { schemaVersion: 1, agent, source: PRIVILEGED_EVENT_SOURCE, ...manifest, updatedAt };
1027
1027
  }
1028
1028
  function isReplayState(value) {
1029
1029
  if (!value || typeof value !== "object" || Array.isArray(value))
@@ -1039,8 +1039,8 @@ function isReplayState(value) {
1039
1039
  return false;
1040
1040
  }
1041
1041
  }
1042
- function loadReplayState(eventRoot, sourceExisted, now) {
1043
- const statePath = replayStatePath(eventRoot);
1042
+ function loadReplayState(eventRoot, agent, sourceExisted, now) {
1043
+ const statePath = replayStatePath(eventRoot, agent);
1044
1044
  const sourceDir = path.dirname(statePath);
1045
1045
  const stateExists = fs.existsSync(statePath);
1046
1046
  let state = null;
@@ -1082,7 +1082,7 @@ function loadReplayState(eventRoot, sourceExisted, now) {
1082
1082
  }
1083
1083
  if (!state && sourceExisted && !legacyFound)
1084
1084
  throw new Error("Privileged replay manifest is missing");
1085
- const next = replayStateFromManifest(authority, now);
1085
+ const next = replayStateFromManifest(authority, now, agent);
1086
1086
  atomicWriteJson(statePath, next, "Privileged replay manifest");
1087
1087
  for (const migration of migrations) {
1088
1088
  const retentionSummary = migration.record.retentionSummary ? retentionWithoutReplayManifest(migration.record.retentionSummary) : undefined;
@@ -1095,13 +1095,15 @@ function loadReplayState(eventRoot, sourceExisted, now) {
1095
1095
  }
1096
1096
  return next;
1097
1097
  }
1098
+ /** `agent` is the Butler the daemon runs: its events, and the replay manifest that guards them, live under its name. */
1098
1099
  function scanPrivilegedEventSpool(options) {
1099
1100
  const entries = safeSpoolEntries(options.spoolRoot);
1100
1101
  let accepted = 0;
1101
1102
  let rejected = 0;
1102
1103
  let replayed = 0;
1103
1104
  const eventRoot = options.eventRoot ?? getExternalEventRoot();
1104
- const sourceDir = path.dirname(replayStatePath(eventRoot));
1105
+ const agent = options.agent ?? "sanctuary";
1106
+ const sourceDir = path.dirname(replayStatePath(eventRoot, agent));
1105
1107
  const sourceExisted = fs.existsSync(sourceDir);
1106
1108
  let rootSafe = false;
1107
1109
  try {
@@ -1120,11 +1122,11 @@ function scanPrivilegedEventSpool(options) {
1120
1122
  const initialNow = options.now?.() ?? new Date().toISOString();
1121
1123
  let replayState;
1122
1124
  try {
1123
- replayState = loadReplayState(eventRoot, sourceExisted, initialNow);
1125
+ replayState = loadReplayState(eventRoot, agent, sourceExisted, initialNow);
1124
1126
  }
1125
1127
  catch {
1126
1128
  rejected = Math.max(1, entries.length);
1127
- replayState = replayStateFromManifest(emptyReplayManifest(), initialNow);
1129
+ replayState = replayStateFromManifest(emptyReplayManifest(), initialNow, agent);
1128
1130
  }
1129
1131
  if (rejected === 0)
1130
1132
  for (const entry of entries) {
@@ -1160,9 +1162,10 @@ function scanPrivilegedEventSpool(options) {
1160
1162
  verification: { verified: envelope.protectiveStateVerified, digest: envelope.protectiveStateDigest, observedAt: envelope.protectiveStateObservedAt },
1161
1163
  };
1162
1164
  const transition = envelope.eventType === "usenet.health_observation" && envelope.transitionId.startsWith("recovered:") ? "recovered" : "opened";
1163
- const quietInitialReceipt = transition === "recovered" && !fs.existsSync(externalEventRecordPath(eventRoot, { agent: envelope.agent, source: envelope.source, eventId: envelope.incidentKey }));
1165
+ const quietInitialReceipt = transition === "recovered" && !fs.existsSync(externalEventRecordPath(eventRoot, { agent, source: envelope.source, eventId: envelope.incidentKey }));
1166
+ // The host's emitter may still name the Butler by its other name; the event is filed under the Butler this daemon runs.
1164
1167
  recordExternalEventInternal({
1165
- agent: envelope.agent,
1168
+ agent,
1166
1169
  source: envelope.source,
1167
1170
  eventType: envelope.eventType,
1168
1171
  eventId: envelope.incidentKey,
@@ -1173,8 +1176,8 @@ function scanPrivilegedEventSpool(options) {
1173
1176
  observationRevision: envelope.observationRevision,
1174
1177
  transition,
1175
1178
  }, { root: eventRoot, now: () => now, quietInitialReceipt, [privilegedIngress]: { nonce: envelope.nonce, protectiveAction } });
1176
- replayState = replayStateFromManifest(replayAdd(replayState, envelope.nonce), now);
1177
- atomicWriteJson(replayStatePath(eventRoot), replayState, "Privileged replay manifest");
1179
+ replayState = replayStateFromManifest(replayAdd(replayState, envelope.nonce), now, agent);
1180
+ atomicWriteJson(replayStatePath(eventRoot, agent), replayState, "Privileged replay manifest");
1178
1181
  accepted += 1;
1179
1182
  }
1180
1183
  catch (error) {
@@ -208,7 +208,8 @@ function createRootHostApprovalRuntime(options) {
208
208
  const context = await options.resolveContext(record.binding);
209
209
  requireValid(context.rootHost?.port === port);
210
210
  await (0, tools_sanctuary_host_1.authorizeRootHostContext)(context, record.binding);
211
- const owner = { agentName: "sanctuary", agentRoot: options.agentRoot };
211
+ // The Butler is named after its bundle folder, the rule its host tool enforces.
212
+ const owner = { agentName: path.basename(options.agentRoot, ".ouro"), agentRoot: options.agentRoot };
212
213
  const runtime = await (options.dependencies?.getProviderRuntime ?? core_1.getProviderRuntime)("human", owner);
213
214
  const mcp = await (options.dependencies?.getMcp ?? mcp_manager_1.getSharedMcpManager)(owner) ?? undefined;
214
215
  if (!port.isHealthy() && !await port.refresh())
@@ -74,6 +74,7 @@ async function runSanctuaryHealthHabit(agentName, options = {}) {
74
74
  await (0, runtime_credentials_1.refreshMachineRuntimeCredentialConfig)(agentName, machine.machineId, { preserveCachedOnFailure: true });
75
75
  }
76
76
  const sweep = options.createSweep?.(agentName) ?? (0, sanctuary_health_1.createSanctuaryHealthSweep)({
77
+ agentName,
77
78
  toolContext: (0, sanctuary_runtime_1.createSanctuaryToolContext)(agentName),
78
79
  house: (0, sanctuary_house_1.readSanctuaryHouse)((0, identity_1.getAgentRoot)(agentName)),
79
80
  statePath: path.join((0, identity_1.getAgentRoot)(agentName), "state", "health", "sanctuary-health.json"),
@@ -308,7 +308,7 @@ function createSanctuaryHealthSweep(options) {
308
308
  const publicEndpoints = (options.house?.publicEndpoints ?? []).map((endpoint) => endpoint.url);
309
309
  const requiredContainers = new Set(options.house?.requiredContainers ?? []);
310
310
  const now = options.now ?? (() => new Date());
311
- const acceptanceEventMeta = options.acceptanceEventMeta ?? (() => (0, sanctuary_acceptance_marker_1.sanctuaryAcceptanceEventMeta)("sanctuary"));
311
+ const acceptanceEventMeta = options.acceptanceEventMeta ?? (() => (0, sanctuary_acceptance_marker_1.sanctuaryAcceptanceEventMeta)(options.agentName ?? "sanctuary"));
312
312
  const runSweep = async () => {
313
313
  const sweepId = (0, node_crypto_1.randomUUID)();
314
314
  const startedAt = now().toISOString();
@@ -112,6 +112,7 @@ const telegram_effect_adapter_1 = require("./telegram-effect-adapter");
112
112
  const telegram_chat_actions_1 = require("./telegram-chat-actions");
113
113
  const atomic_file_1 = require("../heart/atomic-file");
114
114
  const repeat_while_1 = require("./repeat-while");
115
+ const butler_agent_1 = require("../heart/butler-agent");
115
116
  const EMPTY_SHARED_TURN_DIAGNOSTIC = "(agent responded but response was empty)";
116
117
  function hasUserVisibleTurnResponse(response) {
117
118
  const text = response.trim();
@@ -129,7 +130,7 @@ function createFullVisibilityProgress() {
129
130
  function createSabQueueProtectiveStateVerifier(options = {}) {
130
131
  let client = null;
131
132
  return async (action) => {
132
- client ??= (0, sanctuary_sab_1.createSanctuarySabClient)({ loadApiKey: options.loadApiKey ?? (() => (0, sanctuary_runtime_1.loadSanctuarySabApiKey)("sanctuary")), fetch: options.fetch, now: options.now });
133
+ client ??= (0, sanctuary_sab_1.createSanctuarySabClient)({ loadApiKey: options.loadApiKey ?? (() => (0, sanctuary_runtime_1.loadSanctuarySabApiKey)(options.agentName ?? "sanctuary")), fetch: options.fetch, now: options.now });
133
134
  const snapshot = await client.readQueue();
134
135
  const paused = snapshot.paused;
135
136
  const digest = (0, node_crypto_1.createHash)("sha256").update(`sabnzbd.queue.paused=${String(paused)}`).digest("hex");
@@ -616,7 +617,7 @@ function parseTelegramSenseCredentials(value) {
616
617
  }
617
618
  function createTelegramSenseApp(options) {
618
619
  const authorityTransport = options.authorityTransport;
619
- if (authorityTransport && options.agentName !== "sanctuary") {
620
+ if (authorityTransport && !(0, butler_agent_1.isButlerAgent)(options.agentName)) {
620
621
  throw new Error("Sanctuary Telegram authority transport cannot serve another agent");
621
622
  }
622
623
  if (authorityTransport && options.credentials.botToken !== undefined) {
@@ -653,7 +654,7 @@ function createTelegramSenseApp(options) {
653
654
  : undefined;
654
655
  const runTurn = options.runTurn ?? options._runTurn ?? shared_turn_1.runSenseTurn;
655
656
  const collectToolReceipts = options._runWithToolReceiptCollection ?? sanctuary_runtime_2.runWithSanctuaryToolReceiptCollection;
656
- const useSanctuaryRuntime = options.agentName === "sanctuary" && !options.runTurn;
657
+ const useSanctuaryRuntime = (0, butler_agent_1.isButlerAgent)(options.agentName) && !options.runTurn;
657
658
  const readScenarioHandleDigest = () => (options.acceptanceMarker
658
659
  ? options.acceptanceMarker()
659
660
  : (0, sanctuary_acceptance_marker_1.readSanctuaryAcceptanceMarker)(options.agentName))?.scenarioHandleDigest;
@@ -1429,8 +1430,8 @@ function createTelegramSenseApp(options) {
1429
1430
  const relationshipCoordinates = { ...input, botId: botId };
1430
1431
  return async ({ runAgentOptions, activeCares = [], careEvidenceNow = Date.now() }) => {
1431
1432
  const relationshipAuthorization = await resolveLiveRelationshipAuthorization(relationshipCoordinates);
1432
- const isSanctuaryOwner = options.agentName === "sanctuary" && relationshipAuthorization.profileId === "sanctuary-owner";
1433
- const isSanctuaryHouseholdConversation = options.agentName === "sanctuary"
1433
+ const isSanctuaryOwner = (0, butler_agent_1.isButlerAgent)(options.agentName) && relationshipAuthorization.profileId === "sanctuary-owner";
1434
+ const isSanctuaryHouseholdConversation = (0, butler_agent_1.isButlerAgent)(options.agentName)
1434
1435
  && (relationshipAuthorization.profileId === "sanctuary-owner" || relationshipAuthorization.profileId === "sanctuary-household");
1435
1436
  const storageOptimization = isSanctuaryOwner
1436
1437
  ? (0, sanctuary_storage_optimization_contract_1.sanctuaryStorageOptimizationRequiredToolCalls)(input.userMessage, relationshipAuthorization.advertisedToolNames)
@@ -2648,7 +2649,7 @@ async function createProductionTelegramRelationshipComposition(agentName, creden
2648
2649
  async function startTelegramSenseApp(agentName, waitForAuthority = false) {
2649
2650
  let authorityTransport;
2650
2651
  let credentials;
2651
- if (agentName === "sanctuary") {
2652
+ if ((0, butler_agent_1.isButlerAgent)(agentName)) {
2652
2653
  const runtime = (0, runtime_credentials_1.readRuntimeCredentialConfig)(agentName);
2653
2654
  const machine = (0, runtime_credentials_1.readMachineRuntimeCredentialConfig)(agentName);
2654
2655
  if (!runtime.ok || !machine.ok)
@@ -2685,9 +2686,9 @@ async function startTelegramSenseApp(agentName, waitForAuthority = false) {
2685
2686
  proactivePacing: { timeZone: process.env.TZ || "America/Los_Angeles" },
2686
2687
  ...(() => { const ownerRoute = (0, telegram_owner_route_1.ownerRouteForAgent)(agentName, (0, identity_1.getAgentRoot)(agentName)); return ownerRoute ? { ownerRoute } : {}; })(),
2687
2688
  ...(await createProductionTelegramRelationshipComposition(agentName, credentials, undefined, authorityTransport)),
2688
- ...(agentName === "sanctuary" ? { privilegedFailsafe: {
2689
+ ...((0, butler_agent_1.isButlerAgent)(agentName) ? { privilegedFailsafe: {
2689
2690
  eventRoot: (0, router_1.getExternalEventRoot)(),
2690
- verifyProtectiveState: createSabQueueProtectiveStateVerifier(),
2691
+ verifyProtectiveState: createSabQueueProtectiveStateVerifier({ agentName }),
2691
2692
  } } : {}),
2692
2693
  });
2693
2694
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@ouro.bot/cli",
3
- "version": "0.1.0-alpha.1634",
3
+ "version": "0.1.0-alpha.1636",
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.1634",
9
+ "version": "0.1.0-alpha.1636",
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.1634",
3
+ "version": "0.1.0-alpha.1636",
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": {