@ouro.bot/cli 0.1.0-alpha.3 → 0.1.0-alpha.30

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.
Files changed (71) hide show
  1. package/AdoptionSpecialist.ouro/agent.json +70 -9
  2. package/AdoptionSpecialist.ouro/psyche/SOUL.md +5 -2
  3. package/AdoptionSpecialist.ouro/psyche/identities/monty.md +2 -2
  4. package/AdoptionSpecialist.ouro/psyche/identities/python.md +30 -0
  5. package/assets/ouroboros.png +0 -0
  6. package/changelog.json +80 -0
  7. package/dist/heart/config.js +66 -4
  8. package/dist/heart/core.js +75 -2
  9. package/dist/heart/daemon/agent-discovery.js +81 -0
  10. package/dist/heart/daemon/daemon-cli.js +562 -64
  11. package/dist/heart/daemon/daemon-entry.js +14 -5
  12. package/dist/heart/daemon/daemon-runtime-sync.js +90 -0
  13. package/dist/heart/daemon/daemon.js +87 -9
  14. package/dist/heart/daemon/hatch-animation.js +35 -0
  15. package/dist/heart/daemon/hatch-flow.js +2 -11
  16. package/dist/heart/daemon/hatch-specialist.js +6 -1
  17. package/dist/heart/daemon/hooks/bundle-meta.js +92 -0
  18. package/dist/heart/daemon/launchd.js +134 -0
  19. package/dist/heart/daemon/ouro-bot-global-installer.js +128 -0
  20. package/dist/heart/daemon/ouro-bot-wrapper.js +4 -3
  21. package/dist/heart/daemon/ouro-path-installer.js +178 -0
  22. package/dist/heart/daemon/ouro-uti.js +11 -2
  23. package/dist/heart/daemon/process-manager.js +1 -1
  24. package/dist/heart/daemon/run-hooks.js +37 -0
  25. package/dist/heart/daemon/runtime-logging.js +9 -5
  26. package/dist/heart/daemon/runtime-metadata.js +118 -0
  27. package/dist/heart/daemon/sense-manager.js +266 -0
  28. package/dist/heart/daemon/specialist-orchestrator.js +129 -0
  29. package/dist/heart/daemon/specialist-prompt.js +98 -0
  30. package/dist/heart/daemon/specialist-tools.js +237 -0
  31. package/dist/heart/daemon/staged-restart.js +114 -0
  32. package/dist/heart/daemon/subagent-installer.js +10 -1
  33. package/dist/heart/daemon/update-checker.js +103 -0
  34. package/dist/heart/daemon/update-hooks.js +138 -0
  35. package/dist/heart/daemon/wrapper-publish-guard.js +86 -0
  36. package/dist/heart/identity.js +85 -1
  37. package/dist/heart/providers/anthropic.js +19 -2
  38. package/dist/heart/sense-truth.js +61 -0
  39. package/dist/heart/streaming.js +99 -21
  40. package/dist/mind/bundle-manifest.js +69 -0
  41. package/dist/mind/first-impressions.js +2 -1
  42. package/dist/mind/friends/channel.js +8 -0
  43. package/dist/mind/friends/types.js +1 -1
  44. package/dist/mind/phrases.js +1 -0
  45. package/dist/mind/prompt.js +94 -3
  46. package/dist/nerves/cli-logging.js +15 -2
  47. package/dist/repertoire/ado-client.js +4 -2
  48. package/dist/repertoire/coding/feedback.js +134 -0
  49. package/dist/repertoire/coding/index.js +4 -1
  50. package/dist/repertoire/coding/manager.js +61 -2
  51. package/dist/repertoire/coding/spawner.js +3 -3
  52. package/dist/repertoire/coding/tools.js +41 -2
  53. package/dist/repertoire/data/ado-endpoints.json +188 -0
  54. package/dist/repertoire/tools-base.js +69 -5
  55. package/dist/repertoire/tools-teams.js +57 -4
  56. package/dist/repertoire/tools.js +44 -11
  57. package/dist/senses/bluebubbles-client.js +434 -0
  58. package/dist/senses/bluebubbles-entry.js +11 -0
  59. package/dist/senses/bluebubbles-media.js +338 -0
  60. package/dist/senses/bluebubbles-model.js +251 -0
  61. package/dist/senses/bluebubbles-mutation-log.js +76 -0
  62. package/dist/senses/bluebubbles-session-cleanup.js +73 -0
  63. package/dist/senses/bluebubbles.js +449 -0
  64. package/dist/senses/cli.js +299 -133
  65. package/dist/senses/debug-activity.js +108 -0
  66. package/dist/senses/teams.js +173 -54
  67. package/package.json +15 -6
  68. package/subagents/work-doer.md +26 -24
  69. package/subagents/work-merger.md +24 -30
  70. package/subagents/work-planner.md +34 -25
  71. package/dist/inner-worker-entry.js +0 -4
@@ -8,6 +8,8 @@ const message_router_1 = require("./message-router");
8
8
  const health_monitor_1 = require("./health-monitor");
9
9
  const task_scheduler_1 = require("./task-scheduler");
10
10
  const runtime_logging_1 = require("./runtime-logging");
11
+ const sense_manager_1 = require("./sense-manager");
12
+ const agent_discovery_1 = require("./agent-discovery");
11
13
  function parseSocketPath(argv) {
12
14
  const socketIndex = argv.indexOf("--socket");
13
15
  if (socketIndex >= 0) {
@@ -25,16 +27,22 @@ const socketPath = parseSocketPath(process.argv);
25
27
  message: "starting daemon entrypoint",
26
28
  meta: { socketPath },
27
29
  });
30
+ const managedAgents = (0, agent_discovery_1.listEnabledBundleAgents)();
28
31
  const processManager = new process_manager_1.DaemonProcessManager({
29
- agents: [
30
- { name: "ouroboros", entry: "heart/agent-entry.js", channel: "cli", autoStart: true },
31
- { name: "slugger", entry: "heart/agent-entry.js", channel: "cli", autoStart: true },
32
- ],
32
+ agents: managedAgents.map((agent) => ({
33
+ name: agent,
34
+ entry: "heart/agent-entry.js",
35
+ channel: "inner-dialog",
36
+ autoStart: true,
37
+ })),
33
38
  });
34
39
  const scheduler = new task_scheduler_1.TaskDrivenScheduler({
35
- agents: ["ouroboros", "slugger"],
40
+ agents: [...managedAgents],
36
41
  });
37
42
  const router = new message_router_1.FileMessageRouter();
43
+ const senseManager = new sense_manager_1.DaemonSenseManager({
44
+ agents: [...managedAgents],
45
+ });
38
46
  const healthMonitor = new health_monitor_1.HealthMonitor({
39
47
  processManager,
40
48
  scheduler,
@@ -51,6 +59,7 @@ const healthMonitor = new health_monitor_1.HealthMonitor({
51
59
  const daemon = new daemon_1.OuroDaemon({
52
60
  socketPath,
53
61
  processManager,
62
+ senseManager,
54
63
  scheduler,
55
64
  healthMonitor,
56
65
  router,
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureCurrentDaemonRuntime = ensureCurrentDaemonRuntime;
4
+ const runtime_1 = require("../../nerves/runtime");
5
+ function isKnownVersion(version) {
6
+ return version !== "unknown" && version.trim().length > 0;
7
+ }
8
+ function formatErrorReason(error) {
9
+ return error instanceof Error ? error.message : String(error);
10
+ }
11
+ async function ensureCurrentDaemonRuntime(deps) {
12
+ try {
13
+ const runningVersion = await deps.fetchRunningVersion();
14
+ let result;
15
+ if (isKnownVersion(deps.localVersion) &&
16
+ isKnownVersion(runningVersion) &&
17
+ runningVersion !== deps.localVersion) {
18
+ try {
19
+ await deps.stopDaemon();
20
+ }
21
+ catch (error) {
22
+ const reason = formatErrorReason(error);
23
+ result = {
24
+ alreadyRunning: true,
25
+ message: `daemon already running (${deps.socketPath}; could not replace stale daemon ${runningVersion} -> ${deps.localVersion}: ${reason})`,
26
+ };
27
+ (0, runtime_1.emitNervesEvent)({
28
+ level: "warn",
29
+ component: "daemon",
30
+ event: "daemon.runtime_sync_decision",
31
+ message: "evaluated daemon runtime sync outcome",
32
+ meta: { socketPath: deps.socketPath, localVersion: deps.localVersion, runningVersion, action: "stale_replace_failed", reason },
33
+ });
34
+ return result;
35
+ }
36
+ deps.cleanupStaleSocket(deps.socketPath);
37
+ const started = await deps.startDaemonProcess(deps.socketPath);
38
+ result = {
39
+ alreadyRunning: false,
40
+ message: `restarted stale daemon from ${runningVersion} to ${deps.localVersion} (pid ${started.pid ?? "unknown"})`,
41
+ };
42
+ (0, runtime_1.emitNervesEvent)({
43
+ component: "daemon",
44
+ event: "daemon.runtime_sync_decision",
45
+ message: "evaluated daemon runtime sync outcome",
46
+ meta: { socketPath: deps.socketPath, localVersion: deps.localVersion, runningVersion, action: "stale_restarted", pid: started.pid ?? null },
47
+ });
48
+ return result;
49
+ }
50
+ if (!isKnownVersion(deps.localVersion) || !isKnownVersion(runningVersion)) {
51
+ result = {
52
+ alreadyRunning: true,
53
+ message: `daemon already running (${deps.socketPath}; unable to verify version)`,
54
+ };
55
+ (0, runtime_1.emitNervesEvent)({
56
+ component: "daemon",
57
+ event: "daemon.runtime_sync_decision",
58
+ message: "evaluated daemon runtime sync outcome",
59
+ meta: { socketPath: deps.socketPath, localVersion: deps.localVersion, runningVersion, action: "unknown_version" },
60
+ });
61
+ return result;
62
+ }
63
+ }
64
+ catch (error) {
65
+ const reason = formatErrorReason(error);
66
+ const result = {
67
+ alreadyRunning: true,
68
+ message: `daemon already running (${deps.socketPath}; unable to verify version: ${reason})`,
69
+ };
70
+ (0, runtime_1.emitNervesEvent)({
71
+ level: "warn",
72
+ component: "daemon",
73
+ event: "daemon.runtime_sync_decision",
74
+ message: "evaluated daemon runtime sync outcome",
75
+ meta: { socketPath: deps.socketPath, localVersion: deps.localVersion, action: "status_lookup_failed", reason },
76
+ });
77
+ return result;
78
+ }
79
+ const result = {
80
+ alreadyRunning: true,
81
+ message: `daemon already running (${deps.socketPath})`,
82
+ };
83
+ (0, runtime_1.emitNervesEvent)({
84
+ component: "daemon",
85
+ event: "daemon.runtime_sync_decision",
86
+ message: "evaluated daemon runtime sync outcome",
87
+ meta: { socketPath: deps.socketPath, localVersion: deps.localVersion, action: "already_current" },
88
+ });
89
+ return result;
90
+ }
@@ -39,14 +39,35 @@ const net = __importStar(require("net"));
39
39
  const path = __importStar(require("path"));
40
40
  const identity_1 = require("../identity");
41
41
  const runtime_1 = require("../../nerves/runtime");
42
- function formatStatusSummary(snapshots) {
43
- if (snapshots.length === 0)
42
+ const runtime_metadata_1 = require("./runtime-metadata");
43
+ const update_hooks_1 = require("./update-hooks");
44
+ const bundle_meta_1 = require("./hooks/bundle-meta");
45
+ const bundle_manifest_1 = require("../../mind/bundle-manifest");
46
+ const update_checker_1 = require("./update-checker");
47
+ const staged_restart_1 = require("./staged-restart");
48
+ const child_process_1 = require("child_process");
49
+ function buildWorkerRows(snapshots) {
50
+ return snapshots.map((snapshot) => ({
51
+ agent: snapshot.name,
52
+ worker: snapshot.channel,
53
+ status: snapshot.status,
54
+ pid: snapshot.pid,
55
+ restartCount: snapshot.restartCount,
56
+ startedAt: snapshot.startedAt,
57
+ }));
58
+ }
59
+ function formatStatusSummary(payload) {
60
+ if (payload.overview.workerCount === 0 && payload.overview.senseCount === 0) {
44
61
  return "no managed agents";
45
- return snapshots
46
- .map((snapshot) => {
47
- return `${snapshot.name}\t${snapshot.channel}\t${snapshot.status}\tpid=${snapshot.pid ?? "none"}\trestarts=${snapshot.restartCount}`;
48
- })
49
- .join("\n");
62
+ }
63
+ const rows = [
64
+ ...payload.workers.map((row) => `${row.agent}/${row.worker}:${row.status}`),
65
+ ...payload.senses
66
+ .filter((row) => row.enabled)
67
+ .map((row) => `${row.agent}/${row.sense}:${row.status}`),
68
+ ];
69
+ const detail = rows.length > 0 ? `\titems=${rows.join(",")}` : "";
70
+ return `daemon=${payload.overview.daemon}\tworkers=${payload.overview.workerCount}\tsenses=${payload.overview.senseCount}\thealth=${payload.overview.health}${detail}`;
50
71
  }
51
72
  function parseIncomingCommand(raw) {
52
73
  let parsed;
@@ -71,6 +92,7 @@ class OuroDaemon {
71
92
  scheduler;
72
93
  healthMonitor;
73
94
  router;
95
+ senseManager;
74
96
  bundlesRoot;
75
97
  server = null;
76
98
  constructor(options) {
@@ -79,6 +101,7 @@ class OuroDaemon {
79
101
  this.scheduler = options.scheduler;
80
102
  this.healthMonitor = options.healthMonitor;
81
103
  this.router = options.router;
104
+ this.senseManager = options.senseManager ?? null;
82
105
  this.bundlesRoot = options.bundlesRoot ?? (0, identity_1.getAgentBundlesRoot)();
83
106
  }
84
107
  async start() {
@@ -90,7 +113,46 @@ class OuroDaemon {
90
113
  message: "starting daemon server",
91
114
  meta: { socketPath: this.socketPath },
92
115
  });
116
+ // Register update hooks and apply pending updates before starting agents
117
+ (0, update_hooks_1.registerUpdateHook)(bundle_meta_1.bundleMetaHook);
118
+ const currentVersion = (0, bundle_manifest_1.getPackageVersion)();
119
+ await (0, update_hooks_1.applyPendingUpdates)(this.bundlesRoot, currentVersion);
120
+ // Start periodic update checker (polls npm registry every 30 minutes)
121
+ const bundlesRoot = this.bundlesRoot;
122
+ const daemon = this;
123
+ (0, update_checker_1.startUpdateChecker)({
124
+ currentVersion,
125
+ deps: {
126
+ distTag: "alpha",
127
+ fetchRegistryJson: /* v8 ignore next -- integration: real HTTP fetch @preserve */ async () => {
128
+ const res = await fetch("https://registry.npmjs.org/@ouro.bot/cli");
129
+ return res.json();
130
+ },
131
+ },
132
+ onUpdate: /* v8 ignore start -- integration: real npm install + process spawn @preserve */ async (result) => {
133
+ if (!result.latestVersion)
134
+ return;
135
+ await (0, staged_restart_1.performStagedRestart)(result.latestVersion, {
136
+ execSync: (cmd) => (0, child_process_1.execSync)(cmd, { stdio: "inherit" }),
137
+ spawnSync: child_process_1.spawnSync,
138
+ resolveNewCodePath: (_version) => {
139
+ try {
140
+ const resolved = (0, child_process_1.execSync)(`node -e "console.log(require.resolve('@ouro.bot/cli/package.json'))"`, { encoding: "utf-8" }).trim();
141
+ return resolved ? path.dirname(resolved) : null;
142
+ }
143
+ catch {
144
+ return null;
145
+ }
146
+ },
147
+ gracefulShutdown: () => daemon.stop(),
148
+ nodePath: process.execPath,
149
+ bundlesRoot,
150
+ });
151
+ },
152
+ /* v8 ignore stop */
153
+ });
93
154
  await this.processManager.startAutoStartAgents();
155
+ await this.senseManager?.startAutoStartSenses();
94
156
  this.scheduler.start?.();
95
157
  await this.scheduler.reconcile?.();
96
158
  await this.drainPendingBundleMessages();
@@ -176,8 +238,10 @@ class OuroDaemon {
176
238
  message: "stopping daemon server",
177
239
  meta: { socketPath: this.socketPath },
178
240
  });
241
+ (0, update_checker_1.stopUpdateChecker)();
179
242
  this.scheduler.stop?.();
180
243
  await this.processManager.stopAll();
244
+ await this.senseManager?.stopAll();
181
245
  if (this.server) {
182
246
  await new Promise((resolve) => {
183
247
  this.server?.close(() => resolve());
@@ -217,10 +281,24 @@ class OuroDaemon {
217
281
  return { ok: true, message: "daemon stopped" };
218
282
  case "daemon.status": {
219
283
  const snapshots = this.processManager.listAgentSnapshots();
284
+ const workers = buildWorkerRows(snapshots);
285
+ const senses = this.senseManager?.listSenseRows() ?? [];
286
+ const data = {
287
+ overview: {
288
+ daemon: "running",
289
+ health: workers.every((worker) => worker.status === "running") ? "ok" : "warn",
290
+ socketPath: this.socketPath,
291
+ ...(0, runtime_metadata_1.getRuntimeMetadata)(),
292
+ workerCount: workers.length,
293
+ senseCount: senses.length,
294
+ },
295
+ workers,
296
+ senses,
297
+ };
220
298
  return {
221
299
  ok: true,
222
- summary: formatStatusSummary(snapshots),
223
- data: snapshots,
300
+ summary: formatStatusSummary(data),
301
+ data,
224
302
  };
225
303
  }
226
304
  case "daemon.health": {
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.playHatchAnimation = playHatchAnimation;
4
+ const runtime_1 = require("../../nerves/runtime");
5
+ const EGG = "\uD83E\uDD5A";
6
+ const SNAKE = "\uD83D\uDC0D";
7
+ const DOTS = " . . . ";
8
+ function wait(ms) {
9
+ return new Promise((resolve) => setTimeout(resolve, ms));
10
+ }
11
+ /**
12
+ * Play the hatch animation: egg -> dots -> snake + name.
13
+ * The writer function receives each chunk. Default writer is process.stderr.write.
14
+ */
15
+ async function playHatchAnimation(hatchlingName, writer) {
16
+ (0, runtime_1.emitNervesEvent)({
17
+ component: "daemon",
18
+ event: "daemon.hatch_animation_start",
19
+ message: "playing hatch animation",
20
+ meta: { hatchlingName },
21
+ });
22
+ const write = writer ?? ((text) => process.stderr.write(text));
23
+ // Total animation time randomized between 3–5 seconds
24
+ const totalMs = 3000 + Math.floor(Math.random() * 2000);
25
+ const eggPhase = Math.floor(totalMs * 0.4);
26
+ const dotsPhase = Math.floor(totalMs * 0.4);
27
+ const revealPause = totalMs - eggPhase - dotsPhase;
28
+ write(`\n ${EGG}`);
29
+ await wait(eggPhase);
30
+ write(DOTS);
31
+ await wait(dotsPhase);
32
+ write(`${SNAKE} \x1b[1m${hatchlingName}\x1b[0m`);
33
+ await wait(revealPause);
34
+ write("\n\n");
35
+ }
@@ -33,6 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.writeSecretsFile = writeSecretsFile;
36
37
  exports.runHatchFlow = runHatchFlow;
37
38
  const fs = __importStar(require("fs"));
38
39
  const os = __importStar(require("os"));
@@ -84,7 +85,7 @@ function buildSecretsTemplate() {
84
85
  setupToken: "",
85
86
  },
86
87
  "openai-codex": {
87
- model: "gpt-5.2",
88
+ model: "gpt-5.4",
88
89
  oauthAccessToken: "",
89
90
  },
90
91
  },
@@ -206,15 +207,6 @@ function writeFriendImprint(bundleRoot, humanName, now) {
206
207
  };
207
208
  fs.writeFileSync(path.join(friendsDir, `${id}.json`), `${JSON.stringify(record, null, 2)}\n`, "utf-8");
208
209
  }
209
- function writeHatchlingPsyche(bundleRoot, input, identityFileName) {
210
- const psycheDir = path.join(bundleRoot, "psyche");
211
- fs.mkdirSync(psycheDir, { recursive: true });
212
- fs.writeFileSync(path.join(psycheDir, "SOUL.md"), "# SOUL\n\nI am a practical, collaborative agent. I keep commitments and communicate clearly.\n", "utf-8");
213
- fs.writeFileSync(path.join(psycheDir, "IDENTITY.md"), `# IDENTITY\n\nI'm ${input.agentName}, newly hatched and ready to help ${input.humanName}.`, "utf-8");
214
- fs.writeFileSync(path.join(psycheDir, "LORE.md"), `# LORE\n\nHatched with specialist identity seed: ${identityFileName}.`, "utf-8");
215
- fs.writeFileSync(path.join(psycheDir, "TACIT.md"), "# TACIT\n\n- Save what I learn.\n- Keep tasks current.\n", "utf-8");
216
- fs.writeFileSync(path.join(psycheDir, "ASPIRATIONS.md"), "# ASPIRATIONS\n\n- Become a reliable partner for my primary friend.\n", "utf-8");
217
- }
218
210
  function writeMemoryScaffold(bundleRoot) {
219
211
  const memoryRoot = path.join(bundleRoot, "psyche", "memory");
220
212
  fs.mkdirSync(path.join(memoryRoot, "daily"), { recursive: true });
@@ -266,7 +258,6 @@ async function runHatchFlow(input, deps = {}) {
266
258
  writeReadme(path.join(bundleRoot, "senses"), "Sense-specific config.");
267
259
  writeReadme(path.join(bundleRoot, "senses", "teams"), "Teams sense config.");
268
260
  writeHatchlingAgentConfig(bundleRoot, input);
269
- writeHatchlingPsyche(bundleRoot, input, selected.fileName);
270
261
  writeMemoryScaffold(bundleRoot);
271
262
  writeFriendImprint(bundleRoot, input.humanName, now);
272
263
  writeHeartbeatTask(bundleRoot, now);
@@ -42,7 +42,12 @@ const os = __importStar(require("os"));
42
42
  const path = __importStar(require("path"));
43
43
  const runtime_1 = require("../../nerves/runtime");
44
44
  function getSpecialistIdentitySourceDir() {
45
- return path.join(os.homedir(), "AgentBundles", "AdoptionSpecialist.ouro", "psyche", "identities");
45
+ // Prefer ~/AgentBundles/ if it exists (user may have customized identities)
46
+ const userSource = path.join(os.homedir(), "AgentBundles", "AdoptionSpecialist.ouro", "psyche", "identities");
47
+ if (fs.existsSync(userSource))
48
+ return userSource;
49
+ // Fall back to the bundled copy shipped with the npm package
50
+ return path.join(__dirname, "..", "..", "..", "AdoptionSpecialist.ouro", "psyche", "identities");
46
51
  }
47
52
  function getRepoSpecialistIdentitiesDir() {
48
53
  return path.join(process.cwd(), "AdoptionSpecialist.ouro", "psyche", "identities");
@@ -0,0 +1,92 @@
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
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.bundleMetaHook = bundleMetaHook;
37
+ const fs = __importStar(require("fs"));
38
+ const path = __importStar(require("path"));
39
+ const runtime_1 = require("../../../nerves/runtime");
40
+ async function bundleMetaHook(ctx) {
41
+ (0, runtime_1.emitNervesEvent)({
42
+ component: "daemon",
43
+ event: "daemon.bundle_meta_hook_start",
44
+ message: "running bundle-meta update hook",
45
+ meta: { agentRoot: ctx.agentRoot, currentVersion: ctx.currentVersion },
46
+ });
47
+ const metaPath = path.join(ctx.agentRoot, "bundle-meta.json");
48
+ let existing;
49
+ try {
50
+ if (fs.existsSync(metaPath)) {
51
+ const raw = fs.readFileSync(metaPath, "utf-8");
52
+ existing = JSON.parse(raw);
53
+ }
54
+ }
55
+ catch {
56
+ // Malformed JSON -- treat as missing, will overwrite with fresh
57
+ existing = undefined;
58
+ }
59
+ const updated = {
60
+ runtimeVersion: ctx.currentVersion,
61
+ bundleSchemaVersion: existing?.bundleSchemaVersion ?? 1,
62
+ lastUpdated: new Date().toISOString(),
63
+ };
64
+ // Save old runtimeVersion as previousRuntimeVersion (if there was one)
65
+ if (existing?.runtimeVersion) {
66
+ updated.previousRuntimeVersion = existing.runtimeVersion;
67
+ }
68
+ try {
69
+ fs.writeFileSync(metaPath, JSON.stringify(updated, null, 2) + "\n", "utf-8");
70
+ }
71
+ catch (err) {
72
+ const errorMessage = err instanceof Error ? err.message : /* v8 ignore next -- defensive: non-Error catch branch @preserve */ String(err);
73
+ (0, runtime_1.emitNervesEvent)({
74
+ component: "daemon",
75
+ event: "daemon.bundle_meta_hook_error",
76
+ message: "bundle-meta hook write failed",
77
+ meta: { agentRoot: ctx.agentRoot, error: errorMessage },
78
+ });
79
+ return { ok: false, error: errorMessage };
80
+ }
81
+ (0, runtime_1.emitNervesEvent)({
82
+ component: "daemon",
83
+ event: "daemon.bundle_meta_hook_end",
84
+ message: "bundle-meta updated",
85
+ meta: {
86
+ agentRoot: ctx.agentRoot,
87
+ runtimeVersion: updated.runtimeVersion,
88
+ previousRuntimeVersion: updated.previousRuntimeVersion,
89
+ },
90
+ });
91
+ return { ok: true };
92
+ }
@@ -0,0 +1,134 @@
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
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.DAEMON_PLIST_LABEL = void 0;
37
+ exports.generateDaemonPlist = generateDaemonPlist;
38
+ exports.installLaunchAgent = installLaunchAgent;
39
+ exports.uninstallLaunchAgent = uninstallLaunchAgent;
40
+ exports.isDaemonInstalled = isDaemonInstalled;
41
+ const path = __importStar(require("path"));
42
+ const runtime_1 = require("../../nerves/runtime");
43
+ exports.DAEMON_PLIST_LABEL = "bot.ouro.daemon";
44
+ function plistFilePath(homeDir) {
45
+ return path.join(homeDir, "Library", "LaunchAgents", `${exports.DAEMON_PLIST_LABEL}.plist`);
46
+ }
47
+ function generateDaemonPlist(options) {
48
+ (0, runtime_1.emitNervesEvent)({
49
+ component: "daemon",
50
+ event: "daemon.launchd_generate_plist",
51
+ message: "generating daemon plist",
52
+ meta: { entryPath: options.entryPath, socketPath: options.socketPath },
53
+ });
54
+ const lines = [
55
+ `<?xml version="1.0" encoding="UTF-8"?>`,
56
+ `<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">`,
57
+ `<plist version="1.0">`,
58
+ `<dict>`,
59
+ ` <key>Label</key>`,
60
+ ` <string>${exports.DAEMON_PLIST_LABEL}</string>`,
61
+ ` <key>ProgramArguments</key>`,
62
+ ` <array>`,
63
+ ` <string>${options.nodePath}</string>`,
64
+ ` <string>${options.entryPath}</string>`,
65
+ ` <string>--socket</string>`,
66
+ ` <string>${options.socketPath}</string>`,
67
+ ` </array>`,
68
+ ` <key>KeepAlive</key>`,
69
+ ` <true/>`,
70
+ ];
71
+ if (options.logDir) {
72
+ lines.push(` <key>StandardOutPath</key>`, ` <string>${path.join(options.logDir, "ouro-daemon-stdout.log")}</string>`, ` <key>StandardErrorPath</key>`, ` <string>${path.join(options.logDir, "ouro-daemon-stderr.log")}</string>`);
73
+ }
74
+ lines.push(`</dict>`, `</plist>`, ``);
75
+ return lines.join("\n");
76
+ }
77
+ function installLaunchAgent(deps, options) {
78
+ (0, runtime_1.emitNervesEvent)({
79
+ component: "daemon",
80
+ event: "daemon.launchd_install",
81
+ message: "installing launch agent",
82
+ meta: { entryPath: options.entryPath, socketPath: options.socketPath },
83
+ });
84
+ const launchAgentsDir = path.join(deps.homeDir, "Library", "LaunchAgents");
85
+ deps.mkdirp(launchAgentsDir);
86
+ const fullPath = plistFilePath(deps.homeDir);
87
+ // Unload existing (best effort) for idempotent re-install
88
+ if (deps.existsFile(fullPath)) {
89
+ try {
90
+ deps.exec(`launchctl unload "${fullPath}"`);
91
+ }
92
+ catch { /* best effort */ }
93
+ }
94
+ const xml = generateDaemonPlist(options);
95
+ deps.writeFile(fullPath, xml);
96
+ deps.exec(`launchctl load "${fullPath}"`);
97
+ (0, runtime_1.emitNervesEvent)({
98
+ component: "daemon",
99
+ event: "daemon.launchd_installed",
100
+ message: "launch agent installed",
101
+ meta: { plistPath: fullPath },
102
+ });
103
+ }
104
+ function uninstallLaunchAgent(deps) {
105
+ (0, runtime_1.emitNervesEvent)({
106
+ component: "daemon",
107
+ event: "daemon.launchd_uninstall",
108
+ message: "uninstalling launch agent",
109
+ meta: {},
110
+ });
111
+ const fullPath = plistFilePath(deps.homeDir);
112
+ if (deps.existsFile(fullPath)) {
113
+ try {
114
+ deps.exec(`launchctl unload "${fullPath}"`);
115
+ }
116
+ catch { /* best effort */ }
117
+ deps.removeFile(fullPath);
118
+ }
119
+ (0, runtime_1.emitNervesEvent)({
120
+ component: "daemon",
121
+ event: "daemon.launchd_uninstalled",
122
+ message: "launch agent uninstalled",
123
+ meta: { plistPath: fullPath },
124
+ });
125
+ }
126
+ function isDaemonInstalled(deps) {
127
+ (0, runtime_1.emitNervesEvent)({
128
+ component: "daemon",
129
+ event: "daemon.launchd_check_installed",
130
+ message: "checking if daemon is installed",
131
+ meta: {},
132
+ });
133
+ return deps.existsFile(plistFilePath(deps.homeDir));
134
+ }