@ouro.bot/cli 0.1.0-alpha.1 → 0.1.0-alpha.11
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/AdoptionSpecialist.ouro/agent.json +70 -9
- package/AdoptionSpecialist.ouro/psyche/SOUL.md +4 -1
- package/dist/heart/config.js +34 -0
- package/dist/heart/core.js +41 -2
- package/dist/heart/daemon/daemon-cli.js +293 -46
- package/dist/heart/daemon/daemon.js +3 -0
- package/dist/heart/daemon/hatch-animation.js +28 -0
- package/dist/heart/daemon/hatch-flow.js +3 -1
- package/dist/heart/daemon/hatch-specialist.js +6 -1
- package/dist/heart/daemon/log-tailer.js +146 -0
- package/dist/heart/daemon/os-cron.js +260 -0
- package/dist/heart/daemon/ouro-bot-entry.js +0 -0
- package/dist/heart/daemon/ouro-bot-wrapper.js +4 -3
- package/dist/heart/daemon/ouro-entry.js +0 -0
- package/dist/heart/daemon/ouro-path-installer.js +161 -0
- package/dist/heart/daemon/process-manager.js +18 -1
- package/dist/heart/daemon/runtime-logging.js +9 -5
- package/dist/heart/daemon/specialist-orchestrator.js +186 -0
- package/dist/heart/daemon/specialist-prompt.js +61 -0
- package/dist/heart/daemon/specialist-session.js +177 -0
- package/dist/heart/daemon/specialist-tools.js +132 -0
- package/dist/heart/daemon/task-scheduler.js +4 -1
- package/dist/heart/identity.js +28 -3
- package/dist/heart/providers/anthropic.js +3 -0
- package/dist/heart/streaming.js +3 -0
- package/dist/mind/associative-recall.js +23 -2
- package/dist/mind/context.js +85 -1
- package/dist/mind/friends/channel.js +8 -0
- package/dist/mind/friends/types.js +1 -1
- package/dist/mind/memory.js +62 -0
- package/dist/mind/pending.js +93 -0
- package/dist/mind/prompt-refresh.js +20 -0
- package/dist/mind/prompt.js +101 -0
- package/dist/nerves/coverage/file-completeness.js +14 -4
- package/dist/repertoire/tools-base.js +92 -0
- package/dist/repertoire/tools.js +3 -3
- package/dist/senses/bluebubbles-client.js +279 -0
- package/dist/senses/bluebubbles-entry.js +11 -0
- package/dist/senses/bluebubbles-model.js +253 -0
- package/dist/senses/bluebubbles-mutation-log.js +76 -0
- package/dist/senses/bluebubbles.js +332 -0
- package/dist/senses/cli.js +89 -8
- package/dist/senses/inner-dialog.js +15 -0
- package/dist/senses/session-lock.js +119 -0
- package/dist/senses/teams.js +1 -0
- package/package.json +4 -3
- package/subagents/README.md +3 -1
- package/subagents/work-merger.md +33 -2
|
@@ -233,6 +233,7 @@ class OuroDaemon {
|
|
|
233
233
|
ok: true,
|
|
234
234
|
summary: "logs: use `ouro logs` to tail daemon and agent output",
|
|
235
235
|
message: "log streaming available via ouro logs",
|
|
236
|
+
data: { logDir: "~/.agentstate/daemon/logs" },
|
|
236
237
|
};
|
|
237
238
|
case "agent.start":
|
|
238
239
|
await this.processManager.startAgent(command.agent);
|
|
@@ -263,6 +264,7 @@ class OuroDaemon {
|
|
|
263
264
|
sessionId: command.sessionId,
|
|
264
265
|
taskRef: command.taskRef,
|
|
265
266
|
});
|
|
267
|
+
this.processManager.sendToAgent?.(command.to, { type: "message" });
|
|
266
268
|
return { ok: true, message: `queued message ${receipt.id}`, data: receipt };
|
|
267
269
|
}
|
|
268
270
|
case "message.poll": {
|
|
@@ -288,6 +290,7 @@ class OuroDaemon {
|
|
|
288
290
|
taskRef: command.taskId,
|
|
289
291
|
});
|
|
290
292
|
await this.scheduler.recordTaskRun?.(command.agent, command.taskId);
|
|
293
|
+
this.processManager.sendToAgent?.(command.agent, { type: "poke", taskId: command.taskId });
|
|
291
294
|
return {
|
|
292
295
|
ok: true,
|
|
293
296
|
message: `queued poke ${receipt.id}`,
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
write(`\n ${EGG}`);
|
|
24
|
+
await wait(400);
|
|
25
|
+
write(DOTS);
|
|
26
|
+
await wait(400);
|
|
27
|
+
write(`${SNAKE} \x1b[1m${hatchlingName}\x1b[0m\n\n`);
|
|
28
|
+
}
|
|
@@ -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"));
|
|
@@ -182,6 +183,7 @@ function writeFriendImprint(bundleRoot, humanName, now) {
|
|
|
182
183
|
fs.mkdirSync(friendsDir, { recursive: true });
|
|
183
184
|
const nowIso = now.toISOString();
|
|
184
185
|
const id = `friend-${slugify(humanName)}`;
|
|
186
|
+
const localExternalId = `${os.userInfo().username}@${os.hostname()}`;
|
|
185
187
|
const record = {
|
|
186
188
|
id,
|
|
187
189
|
name: humanName,
|
|
@@ -191,7 +193,7 @@ function writeFriendImprint(bundleRoot, humanName, now) {
|
|
|
191
193
|
externalIds: [
|
|
192
194
|
{
|
|
193
195
|
provider: "local",
|
|
194
|
-
externalId:
|
|
196
|
+
externalId: localExternalId,
|
|
195
197
|
linkedAt: nowIso,
|
|
196
198
|
},
|
|
197
199
|
],
|
|
@@ -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
|
-
|
|
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,146 @@
|
|
|
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.discoverLogFiles = discoverLogFiles;
|
|
37
|
+
exports.readLastLines = readLastLines;
|
|
38
|
+
exports.formatLogLine = formatLogLine;
|
|
39
|
+
exports.tailLogs = tailLogs;
|
|
40
|
+
const os = __importStar(require("os"));
|
|
41
|
+
const path = __importStar(require("path"));
|
|
42
|
+
const nerves_1 = require("../../nerves");
|
|
43
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
44
|
+
const LEVEL_COLORS = {
|
|
45
|
+
debug: "\x1b[2m",
|
|
46
|
+
info: "\x1b[36m",
|
|
47
|
+
warn: "\x1b[33m",
|
|
48
|
+
error: "\x1b[31m",
|
|
49
|
+
};
|
|
50
|
+
function discoverLogFiles(options) {
|
|
51
|
+
/* v8 ignore start -- integration: default DI stubs for real OS @preserve */
|
|
52
|
+
const homeDir = options.homeDir ?? os.homedir();
|
|
53
|
+
const existsSync = options.existsSync ?? (() => false);
|
|
54
|
+
const readdirSync = options.readdirSync ?? (() => []);
|
|
55
|
+
/* v8 ignore stop */
|
|
56
|
+
const logDir = path.join(homeDir, ".agentstate", "daemon", "logs");
|
|
57
|
+
const files = [];
|
|
58
|
+
if (existsSync(logDir)) {
|
|
59
|
+
for (const name of readdirSync(logDir)) {
|
|
60
|
+
if (!name.endsWith(".ndjson"))
|
|
61
|
+
continue;
|
|
62
|
+
if (options.agentFilter && !name.includes(options.agentFilter))
|
|
63
|
+
continue;
|
|
64
|
+
files.push(path.join(logDir, name));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return files.sort();
|
|
68
|
+
}
|
|
69
|
+
function readLastLines(filePath, count, readFileSync) {
|
|
70
|
+
let content;
|
|
71
|
+
try {
|
|
72
|
+
content = readFileSync(filePath, "utf-8");
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return [];
|
|
76
|
+
}
|
|
77
|
+
const lines = content.split("\n").filter((l) => l.trim().length > 0);
|
|
78
|
+
return lines.slice(-count);
|
|
79
|
+
}
|
|
80
|
+
function formatLogLine(ndjsonLine) {
|
|
81
|
+
try {
|
|
82
|
+
const entry = JSON.parse(ndjsonLine);
|
|
83
|
+
const formatted = (0, nerves_1.formatTerminalEntry)(entry);
|
|
84
|
+
const color = LEVEL_COLORS[entry.level] ?? "";
|
|
85
|
+
return `${color}${formatted}\x1b[0m`;
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return ndjsonLine;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function tailLogs(options = {}) {
|
|
92
|
+
/* v8 ignore start -- integration: default DI stubs for real OS @preserve */
|
|
93
|
+
const writer = options.writer ?? ((text) => process.stdout.write(text));
|
|
94
|
+
const lineCount = options.lines ?? 20;
|
|
95
|
+
const readFileSync = options.readFileSync ?? (() => "");
|
|
96
|
+
/* v8 ignore stop */
|
|
97
|
+
const watchFile = options.watchFile;
|
|
98
|
+
const unwatchFile = options.unwatchFile;
|
|
99
|
+
const files = discoverLogFiles(options);
|
|
100
|
+
(0, runtime_1.emitNervesEvent)({ component: "daemon", event: "daemon.log_tailer_started", message: "log tailer started", meta: { fileCount: files.length, follow: !!options.follow } });
|
|
101
|
+
const fileSizes = new Map();
|
|
102
|
+
// Read initial lines
|
|
103
|
+
for (const file of files) {
|
|
104
|
+
const lines = readLastLines(file, lineCount, readFileSync);
|
|
105
|
+
for (const line of lines) {
|
|
106
|
+
writer(`${formatLogLine(line)}\n`);
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
const content = readFileSync(file, "utf-8");
|
|
110
|
+
fileSizes.set(file, content.length);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
fileSizes.set(file, 0);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// Follow mode
|
|
117
|
+
if (options.follow && watchFile && unwatchFile) {
|
|
118
|
+
for (const file of files) {
|
|
119
|
+
watchFile(file, () => {
|
|
120
|
+
let content;
|
|
121
|
+
try {
|
|
122
|
+
content = readFileSync(file, "utf-8");
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
/* v8 ignore next -- defensive: fileSizes always populated above @preserve */
|
|
128
|
+
const prevSize = fileSizes.get(file) ?? 0;
|
|
129
|
+
if (content.length <= prevSize)
|
|
130
|
+
return;
|
|
131
|
+
fileSizes.set(file, content.length);
|
|
132
|
+
const newContent = content.slice(prevSize);
|
|
133
|
+
const newLines = newContent.split("\n").filter((l) => l.trim().length > 0);
|
|
134
|
+
for (const line of newLines) {
|
|
135
|
+
writer(`${formatLogLine(line)}\n`);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
return () => {
|
|
140
|
+
for (const file of files) {
|
|
141
|
+
unwatchFile(file);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
return () => { };
|
|
146
|
+
}
|
|
@@ -0,0 +1,260 @@
|
|
|
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.CrontabCronManager = exports.LaunchdCronManager = void 0;
|
|
37
|
+
exports.createOsCronManager = createOsCronManager;
|
|
38
|
+
exports.cadenceToSeconds = cadenceToSeconds;
|
|
39
|
+
exports.scheduleToCalendarInterval = scheduleToCalendarInterval;
|
|
40
|
+
exports.generatePlistXml = generatePlistXml;
|
|
41
|
+
exports.plistLabel = plistLabel;
|
|
42
|
+
exports.crontabLine = crontabLine;
|
|
43
|
+
const os = __importStar(require("os"));
|
|
44
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
45
|
+
const PLIST_PREFIX = "bot.ouro.";
|
|
46
|
+
function plistLabel(job) {
|
|
47
|
+
return `${PLIST_PREFIX}${job.agent}.${job.taskId}`;
|
|
48
|
+
}
|
|
49
|
+
function cadenceToSeconds(schedule) {
|
|
50
|
+
const parts = schedule.trim().split(/\s+/);
|
|
51
|
+
if (parts.length !== 5)
|
|
52
|
+
return null;
|
|
53
|
+
const [minute, hour, day, month, weekday] = parts;
|
|
54
|
+
// Simple interval patterns only
|
|
55
|
+
if (month !== "*" || weekday !== "*" || day !== "*")
|
|
56
|
+
return null;
|
|
57
|
+
const everyNMinutes = /^\*\/(\d+)$/.exec(minute);
|
|
58
|
+
if (everyNMinutes && hour === "*") {
|
|
59
|
+
return parseInt(everyNMinutes[1], 10) * 60;
|
|
60
|
+
}
|
|
61
|
+
const everyNHours = /^\*\/(\d+)$/.exec(hour);
|
|
62
|
+
if (everyNHours && minute === "0") {
|
|
63
|
+
return parseInt(everyNHours[1], 10) * 3600;
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
function scheduleToCalendarInterval(schedule) {
|
|
68
|
+
const parts = schedule.trim().split(/\s+/);
|
|
69
|
+
if (parts.length !== 5)
|
|
70
|
+
return null;
|
|
71
|
+
const [minute, hour, day, month] = parts;
|
|
72
|
+
const result = {};
|
|
73
|
+
if (minute !== "*" && !/^\*\//.test(minute))
|
|
74
|
+
result.Minute = parseInt(minute, 10);
|
|
75
|
+
if (hour !== "*" && !/^\*\//.test(hour))
|
|
76
|
+
result.Hour = parseInt(hour, 10);
|
|
77
|
+
if (day !== "*")
|
|
78
|
+
result.Day = parseInt(day, 10);
|
|
79
|
+
if (month !== "*")
|
|
80
|
+
result.Month = parseInt(month, 10);
|
|
81
|
+
return Object.keys(result).length > 0 ? result : null;
|
|
82
|
+
}
|
|
83
|
+
function generatePlistXml(job) {
|
|
84
|
+
const label = plistLabel(job);
|
|
85
|
+
const seconds = cadenceToSeconds(job.schedule);
|
|
86
|
+
const calendar = seconds === null ? scheduleToCalendarInterval(job.schedule) : null;
|
|
87
|
+
let triggerXml;
|
|
88
|
+
if (seconds !== null) {
|
|
89
|
+
triggerXml = ` <key>StartInterval</key>\n <integer>${seconds}</integer>`;
|
|
90
|
+
}
|
|
91
|
+
else if (calendar !== null) {
|
|
92
|
+
const entries = Object.entries(calendar)
|
|
93
|
+
.map(([k, v]) => ` <key>${k}</key>\n <integer>${v}</integer>`)
|
|
94
|
+
.join("\n");
|
|
95
|
+
triggerXml = ` <key>StartCalendarInterval</key>\n <dict>\n${entries}\n </dict>`;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
triggerXml = ` <key>StartInterval</key>\n <integer>1800</integer>`;
|
|
99
|
+
}
|
|
100
|
+
return [
|
|
101
|
+
`<?xml version="1.0" encoding="UTF-8"?>`,
|
|
102
|
+
`<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">`,
|
|
103
|
+
`<plist version="1.0">`,
|
|
104
|
+
`<dict>`,
|
|
105
|
+
` <key>Label</key>`,
|
|
106
|
+
` <string>${label}</string>`,
|
|
107
|
+
` <key>ProgramArguments</key>`,
|
|
108
|
+
` <array>`,
|
|
109
|
+
` <string>${job.command.split(" ")[0]}</string>`,
|
|
110
|
+
...job.command.split(" ").slice(1).map((arg) => ` <string>${arg}</string>`),
|
|
111
|
+
` </array>`,
|
|
112
|
+
triggerXml,
|
|
113
|
+
` <key>StandardOutPath</key>`,
|
|
114
|
+
` <string>/tmp/${label}.stdout.log</string>`,
|
|
115
|
+
` <key>StandardErrorPath</key>`,
|
|
116
|
+
` <string>/tmp/${label}.stderr.log</string>`,
|
|
117
|
+
`</dict>`,
|
|
118
|
+
`</plist>`,
|
|
119
|
+
``,
|
|
120
|
+
].join("\n");
|
|
121
|
+
}
|
|
122
|
+
class LaunchdCronManager {
|
|
123
|
+
deps;
|
|
124
|
+
constructor(deps) {
|
|
125
|
+
this.deps = deps;
|
|
126
|
+
}
|
|
127
|
+
get launchAgentsDir() {
|
|
128
|
+
return `${this.deps.homeDir}/Library/LaunchAgents`;
|
|
129
|
+
}
|
|
130
|
+
sync(jobs) {
|
|
131
|
+
this.deps.mkdirp(this.launchAgentsDir);
|
|
132
|
+
const desiredLabels = new Set(jobs.map(plistLabel));
|
|
133
|
+
// Remove stale plists
|
|
134
|
+
const existing = this.listPlistFiles();
|
|
135
|
+
for (const filename of existing) {
|
|
136
|
+
const label = filename.replace(".plist", "");
|
|
137
|
+
if (!desiredLabels.has(label)) {
|
|
138
|
+
const fullPath = `${this.launchAgentsDir}/${filename}`;
|
|
139
|
+
try {
|
|
140
|
+
this.deps.exec(`launchctl unload "${fullPath}"`);
|
|
141
|
+
}
|
|
142
|
+
catch { /* best effort */ }
|
|
143
|
+
this.deps.removeFile(fullPath);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// Write current plists
|
|
147
|
+
for (const job of jobs) {
|
|
148
|
+
const label = plistLabel(job);
|
|
149
|
+
const filename = `${label}.plist`;
|
|
150
|
+
const fullPath = `${this.launchAgentsDir}/${filename}`;
|
|
151
|
+
const xml = generatePlistXml(job);
|
|
152
|
+
try {
|
|
153
|
+
this.deps.exec(`launchctl unload "${fullPath}"`);
|
|
154
|
+
}
|
|
155
|
+
catch { /* best effort */ }
|
|
156
|
+
this.deps.writeFile(fullPath, xml);
|
|
157
|
+
try {
|
|
158
|
+
this.deps.exec(`launchctl load "${fullPath}"`);
|
|
159
|
+
}
|
|
160
|
+
catch { /* best effort */ }
|
|
161
|
+
}
|
|
162
|
+
(0, runtime_1.emitNervesEvent)({ component: "daemon", event: "daemon.os_cron_synced", message: "synced OS cron entries", meta: { platform: "darwin", jobCount: jobs.length } });
|
|
163
|
+
}
|
|
164
|
+
removeAll() {
|
|
165
|
+
const existing = this.listPlistFiles();
|
|
166
|
+
for (const filename of existing) {
|
|
167
|
+
const fullPath = `${this.launchAgentsDir}/${filename}`;
|
|
168
|
+
try {
|
|
169
|
+
this.deps.exec(`launchctl unload "${fullPath}"`);
|
|
170
|
+
}
|
|
171
|
+
catch { /* best effort */ }
|
|
172
|
+
this.deps.removeFile(fullPath);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
list() {
|
|
176
|
+
return this.listPlistFiles().map((f) => f.replace(".plist", ""));
|
|
177
|
+
}
|
|
178
|
+
listPlistFiles() {
|
|
179
|
+
if (!this.deps.existsFile(this.launchAgentsDir))
|
|
180
|
+
return [];
|
|
181
|
+
return this.deps.listDir(this.launchAgentsDir).filter((f) => f.startsWith(PLIST_PREFIX) && f.endsWith(".plist"));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
exports.LaunchdCronManager = LaunchdCronManager;
|
|
185
|
+
const CRONTAB_MARKER_PREFIX = "# ouro:";
|
|
186
|
+
function crontabLine(job) {
|
|
187
|
+
return `${CRONTAB_MARKER_PREFIX}${job.id}\n${job.schedule} ${job.command}`;
|
|
188
|
+
}
|
|
189
|
+
class CrontabCronManager {
|
|
190
|
+
deps;
|
|
191
|
+
constructor(deps) {
|
|
192
|
+
this.deps = deps;
|
|
193
|
+
}
|
|
194
|
+
sync(jobs) {
|
|
195
|
+
const currentLines = this.readCrontab();
|
|
196
|
+
const cleaned = this.removeOuroLines(currentLines);
|
|
197
|
+
const newLines = jobs.map(crontabLine);
|
|
198
|
+
const combined = [...cleaned, ...newLines].join("\n").trim();
|
|
199
|
+
this.deps.execWrite("crontab -", combined ? `${combined}\n` : "");
|
|
200
|
+
}
|
|
201
|
+
removeAll() {
|
|
202
|
+
const currentLines = this.readCrontab();
|
|
203
|
+
const cleaned = this.removeOuroLines(currentLines);
|
|
204
|
+
const combined = cleaned.join("\n").trim();
|
|
205
|
+
this.deps.execWrite("crontab -", combined ? `${combined}\n` : "");
|
|
206
|
+
}
|
|
207
|
+
list() {
|
|
208
|
+
const lines = this.readCrontab();
|
|
209
|
+
return lines
|
|
210
|
+
.filter((l) => l.startsWith(CRONTAB_MARKER_PREFIX))
|
|
211
|
+
.map((l) => l.slice(CRONTAB_MARKER_PREFIX.length));
|
|
212
|
+
}
|
|
213
|
+
readCrontab() {
|
|
214
|
+
try {
|
|
215
|
+
return this.deps.execOutput("crontab -l").split("\n");
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
return [];
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
removeOuroLines(lines) {
|
|
222
|
+
const result = [];
|
|
223
|
+
let skipNext = false;
|
|
224
|
+
for (const line of lines) {
|
|
225
|
+
if (line.startsWith(CRONTAB_MARKER_PREFIX)) {
|
|
226
|
+
skipNext = true;
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
if (skipNext) {
|
|
230
|
+
skipNext = false;
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
result.push(line);
|
|
234
|
+
}
|
|
235
|
+
return result;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
exports.CrontabCronManager = CrontabCronManager;
|
|
239
|
+
function createOsCronManager(options = {}) {
|
|
240
|
+
const platform = options.platform ?? process.platform;
|
|
241
|
+
if (platform === "darwin") {
|
|
242
|
+
/* v8 ignore start -- integration: default stubs for real OS operations @preserve */
|
|
243
|
+
const deps = options.launchdDeps ?? {
|
|
244
|
+
exec: () => { },
|
|
245
|
+
writeFile: () => { },
|
|
246
|
+
removeFile: () => { },
|
|
247
|
+
existsFile: () => false,
|
|
248
|
+
listDir: () => [],
|
|
249
|
+
mkdirp: () => { },
|
|
250
|
+
homeDir: os.homedir(),
|
|
251
|
+
};
|
|
252
|
+
/* v8 ignore stop */
|
|
253
|
+
return new LaunchdCronManager(deps);
|
|
254
|
+
}
|
|
255
|
+
const deps = options.crontabDeps ?? {
|
|
256
|
+
execOutput: () => "",
|
|
257
|
+
execWrite: () => { },
|
|
258
|
+
};
|
|
259
|
+
return new CrontabCronManager(deps);
|
|
260
|
+
}
|
|
File without changes
|
|
@@ -37,8 +37,9 @@ exports.runOuroBotWrapper = runOuroBotWrapper;
|
|
|
37
37
|
const runtime_1 = require("../../nerves/runtime");
|
|
38
38
|
const daemon_cli_1 = require("./daemon-cli");
|
|
39
39
|
async function defaultLoadCanonicalRunner() {
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
// Use the subpath export so we get the daemon-cli module directly,
|
|
41
|
+
// NOT the root entry point which has side-effects (immediately runs the CLI).
|
|
42
|
+
const specifier = "@ouro.bot/cli/runOuroCli";
|
|
42
43
|
const loaded = await Promise.resolve(`${specifier}`).then(s => __importStar(require(s)));
|
|
43
44
|
const candidate = Object.prototype.hasOwnProperty.call(loaded, "runOuroCli")
|
|
44
45
|
? loaded["runOuroCli"]
|
|
@@ -46,7 +47,7 @@ async function defaultLoadCanonicalRunner() {
|
|
|
46
47
|
if (typeof candidate === "function") {
|
|
47
48
|
return candidate;
|
|
48
49
|
}
|
|
49
|
-
throw new Error("@ouro.bot/cli does not export runOuroCli");
|
|
50
|
+
throw new Error("@ouro.bot/cli/runOuroCli does not export runOuroCli");
|
|
50
51
|
}
|
|
51
52
|
function defaultWriteStdout(_text) {
|
|
52
53
|
// Wrapper is intentionally silent by default to avoid duplicate terminal output.
|
|
File without changes
|