@ouro.bot/cli 0.1.0-alpha.1404 → 0.1.0-alpha.1406
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 +12 -0
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +1 -1
- package/deploy/unraid/sanctuary.xml +1 -1
- package/dist/eval/sandbox/declared-gaps.js +17 -0
- package/dist/eval/sandbox/docker.js +2 -1
- package/dist/eval/sandbox/projection.js +20 -0
- package/dist/eval/transport/synthetic-sanctuary.js +12 -2
- package/dist/eval/transport/telegram-turn.js +1 -9
- package/dist/heart/daemon/process-manager.js +44 -1
- package/dist/heart/daemon/process-tree.js +109 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/changelog.json
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
{
|
|
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
|
+
{
|
|
5
|
+
"version": "0.1.0-alpha.1406",
|
|
6
|
+
"changes": [
|
|
7
|
+
"Eval reports now list every way the sandbox differs from a real Butler turn: the synthetic Sanctuary reads, no MCP server (so no media tools), no route off the host, the generic house config, no root host binding and the Telegram path's shortcuts. The synthetic Unraid data now uses production's shapes: calibre-web is Books and the calibre desktop app is stopped on purpose, matching the fake household the books cases use. The bundle projection drops agent.json's MCP servers and says which."
|
|
8
|
+
]
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"version": "0.1.0-alpha.1405",
|
|
12
|
+
"changes": [
|
|
13
|
+
"When the daemon has to SIGKILL a stuck worker, what that worker started goes too: sync's detached git commands and their ssh get SIGTERM, then SIGKILL after a second, so none of it runs on beside the replacement."
|
|
14
|
+
]
|
|
15
|
+
},
|
|
4
16
|
{
|
|
5
17
|
"version": "0.1.0-alpha.1404",
|
|
6
18
|
"changes": [
|
|
@@ -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.1406</Repository>
|
|
5
5
|
<Registry>https://github.com/ourostack/ouroboros/pkgs/container/ouroboros-butler</Registry>
|
|
6
6
|
<Network>host</Network>
|
|
7
7
|
<Shell>sh</Shell>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DECLARED_GAPS = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* What the sandbox fakes or leaves out of a real Butler turn, beside what the bundle projection leaves out. Every
|
|
6
|
+
* sandboxed run returns these with its projection gaps, so each report lists them.
|
|
7
|
+
*/
|
|
8
|
+
exports.DECLARED_GAPS = [
|
|
9
|
+
"synthetic Sanctuary: the Unraid, service, install state, download-queue, media optimisation and media-catalog reads return fixed data; a container restart and a download-queue resume are not simulated",
|
|
10
|
+
"no MCP server starts, so the media MCP tools (media_*) are not in the turn's tool list",
|
|
11
|
+
"the agent container is on an internal network with no route off the host, so web_search and fetch_url fail",
|
|
12
|
+
"house/house.json is not projected: the turn runs with the generic house config (no owner name, no public endpoints, no books container)",
|
|
13
|
+
"no root host binding, so sanctuary_host_execute is not offered",
|
|
14
|
+
"the owner's message goes straight to the Telegram sense's message handler, skipping the long poll's update parsing, its user and chat filter and the inbox",
|
|
15
|
+
"the owner's prompt does not list skills/: a skill file reaches the model only when the agent reads it with a tool",
|
|
16
|
+
"replies are read back as text: Telegram's HTML is decoded, a message's buttons are not part of the answer, and a send_file shows only as the tool call",
|
|
17
|
+
];
|
|
@@ -38,6 +38,7 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
38
38
|
const runtime_1 = require("../../nerves/runtime");
|
|
39
39
|
const provider_proxy_1 = require("../transport/provider-proxy");
|
|
40
40
|
const telegram_turn_1 = require("../transport/telegram-turn");
|
|
41
|
+
const declared_gaps_1 = require("./declared-gaps");
|
|
41
42
|
const projection_1 = require("./projection");
|
|
42
43
|
const readback_1 = require("./readback");
|
|
43
44
|
exports.SANDBOX_IMAGE = "ouro-eval-sandbox:local";
|
|
@@ -280,7 +281,7 @@ async function runSandboxed(input) {
|
|
|
280
281
|
...(input.oracle ? { oracle: input.oracle } : {}),
|
|
281
282
|
});
|
|
282
283
|
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.sandbox_run_end", message: "finished a sandboxed eval run", meta: { caseId: input.case.id, runId, outcome: observation.outcome } });
|
|
283
|
-
return { ...observation, gaps };
|
|
284
|
+
return { ...observation, gaps: [...gaps, ...declared_gaps_1.DECLARED_GAPS] };
|
|
284
285
|
}
|
|
285
286
|
catch (error) {
|
|
286
287
|
(0, runtime_1.emitNervesEvent)({ component: "eval", level: "error", event: "eval.sandbox_run_error", message: "a sandboxed eval run failed", meta: { caseId: input.case.id, runId, error: error.message } });
|
|
@@ -70,6 +70,25 @@ function copyTree(from, to, relative, gaps) {
|
|
|
70
70
|
node_fs_1.default.copyFileSync(source, node_path_1.default.join(to, relative));
|
|
71
71
|
node_fs_1.default.chmodSync(node_path_1.default.join(to, relative), stat.mode & 0o755);
|
|
72
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* The sandbox starts no MCP server: their programs and credentials are host-specific and never projected. Taking them
|
|
75
|
+
* out of `agent.json` makes that so whatever a case includes, instead of a server that fails to start.
|
|
76
|
+
*/
|
|
77
|
+
function dropMcpServers(file, gaps) {
|
|
78
|
+
let config;
|
|
79
|
+
try {
|
|
80
|
+
config = JSON.parse(node_fs_1.default.readFileSync(file, "utf8"));
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const servers = config?.mcpServers;
|
|
86
|
+
if (!servers || typeof servers !== "object" || Object.keys(servers).length === 0)
|
|
87
|
+
return;
|
|
88
|
+
delete config.mcpServers;
|
|
89
|
+
node_fs_1.default.writeFileSync(file, `${JSON.stringify(config, null, 2)}\n`);
|
|
90
|
+
gaps.push(`agent.json: its MCP servers (${Object.keys(servers).sort().join(", ")}) are left out; the sandbox starts no MCP server`);
|
|
91
|
+
}
|
|
73
92
|
function projectBundle(input) {
|
|
74
93
|
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.projection_start", message: "projecting a bundle for a sandboxed run", meta: { include: input.include } });
|
|
75
94
|
for (const include of input.include)
|
|
@@ -96,6 +115,7 @@ function projectBundle(input) {
|
|
|
96
115
|
else
|
|
97
116
|
copyTree(input.seedBundleDir, input.out, seeded, gaps);
|
|
98
117
|
}
|
|
118
|
+
dropMcpServers(node_path_1.default.join(input.out, "agent.json"), gaps);
|
|
99
119
|
for (const dir of EMPTY)
|
|
100
120
|
node_fs_1.default.mkdirSync(node_path_1.default.join(input.out, dir), { recursive: true });
|
|
101
121
|
node_fs_1.default.writeFileSync(node_path_1.default.join(input.out, "books/ledger.ndjson"), "");
|
|
@@ -2,15 +2,22 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createSyntheticSanctuary = createSyntheticSanctuary;
|
|
4
4
|
const tools_unraid_1 = require("../../repertoire/tools-unraid");
|
|
5
|
+
const sanctuary_container_policy_1 = require("../../repertoire/sanctuary-container-policy");
|
|
5
6
|
const sanctuary_media_optimization_1 = require("../../senses/sanctuary-media-optimization");
|
|
6
7
|
const runtime_1 = require("../../nerves/runtime");
|
|
7
8
|
const OBSERVED_AT = "2026-01-15T12:00:00.000Z";
|
|
8
9
|
const SERVER_ID = "eval:server";
|
|
10
|
+
const BOOKS_CONTAINER = "calibre-web";
|
|
11
|
+
// Only what annotateContainers reads of the steward policy.
|
|
12
|
+
const POLICY = { desiredStates: { "container:calibre": { value: "off" } } };
|
|
9
13
|
const CONTAINERS = [
|
|
10
14
|
{ id: "eval:jellyfin", names: ["/jellyfin"], state: "RUNNING", status: "Up 3 days", autoStart: true },
|
|
11
15
|
{ id: "eval:sabnzbd", names: ["/sabnzbd"], state: "RUNNING", status: "Up 3 days", autoStart: true },
|
|
12
16
|
{ id: "eval:unmanic", names: ["/unmanic"], state: "RUNNING", status: "Up 3 days", autoStart: true },
|
|
17
|
+
// As on the household: the calibre desktop app is kept stopped on purpose (POLICY), and calibre-web, which the fake
|
|
18
|
+
// household serves to the books cases, is Books.
|
|
13
19
|
{ id: "eval:calibre", names: ["/calibre"], state: "EXITED", status: "Exited (0) 2 days ago", autoStart: false },
|
|
20
|
+
{ id: "eval:calibre-web", names: ["/calibre-web"], state: "RUNNING", status: "Up 3 days", autoStart: true },
|
|
14
21
|
];
|
|
15
22
|
const CATALOG = [
|
|
16
23
|
{ untrustedTitle: "The Long Voyage", type: "Movie", productionYear: 2019, premiereDate: "2019-06-07" },
|
|
@@ -53,7 +60,7 @@ function createSyntheticSanctuary() {
|
|
|
53
60
|
(0, runtime_1.emitNervesEvent)({ component: "eval", event: "eval.synthetic_sanctuary_create", message: "creating synthetic Sanctuary service context" });
|
|
54
61
|
const reads = (0, tools_unraid_1.createUnraidReadTools)({ read: syntheticRead });
|
|
55
62
|
return {
|
|
56
|
-
listContainers: () => reads.listContainers(),
|
|
63
|
+
listContainers: async () => (0, sanctuary_container_policy_1.annotateContainers)(await reads.listContainers(), POLICY, Date.parse(OBSERVED_AT), (0, sanctuary_container_policy_1.serviceContainers)({ booksContainer: BOOKS_CONTAINER })),
|
|
57
64
|
getContainerLogs: (args) => reads.getContainerLogs(args),
|
|
58
65
|
getStorage: () => reads.getStorage(),
|
|
59
66
|
getDisks: () => reads.getDisks(),
|
|
@@ -65,7 +72,10 @@ function createSyntheticSanctuary() {
|
|
|
65
72
|
}),
|
|
66
73
|
checkServices: async () => ({
|
|
67
74
|
ok: true,
|
|
68
|
-
data: { observedAt: OBSERVED_AT, services: [
|
|
75
|
+
data: { observedAt: OBSERVED_AT, services: [
|
|
76
|
+
{ name: "books", container: BOOKS_CONTAINER, url: "https://books.eval.invalid", ok: true, status: 200 },
|
|
77
|
+
{ name: "jellyfin", url: "https://jellyfin.eval.invalid", ok: true, status: 200 },
|
|
78
|
+
], degraded: false },
|
|
69
79
|
}),
|
|
70
80
|
getDownloadQueue: async () => ({ paused: false, status: "Idle", queuedJobs: 0, observedAt: OBSERVED_AT, stateDigest: "eval" }),
|
|
71
81
|
getMediaOptimization: async () => ({
|
|
@@ -36,15 +36,7 @@ exports.runTelegramTurn = runTelegramTurn;
|
|
|
36
36
|
* message ids are fixed, so a second run on the same bundle fails. Bundle sync is on in `agent.json` and does
|
|
37
37
|
* nothing only because the bundle is not a Git repository; a projection must not carry `.git`.
|
|
38
38
|
*
|
|
39
|
-
* Fidelity gaps:
|
|
40
|
-
* - The message goes straight to the sense's message handler, skipping the long poll's update parsing, its user and
|
|
41
|
-
* chat filter and the inbox. Friend resolution and relationship authorization still run.
|
|
42
|
-
* - The Sanctuary service answers (containers, storage, disks, media catalog) are synthetic and fixed; a restart and a
|
|
43
|
-
* download-queue resume are not simulated. The books tools are not covered by this context.
|
|
44
|
-
* - The owner's prompt does not list `skills/`: the relationship prompt has no skills section and `load_skill` is not
|
|
45
|
-
* in the `sanctuary-owner` profile, so a skill file reaches the model only when the agent reads it with a tool.
|
|
46
|
-
* - Replies are read back as text: Telegram's HTML is decoded, and a message with buttons is not part of the answer.
|
|
47
|
-
* Files sent with `send_file` appear only as the tool call.
|
|
39
|
+
* Fidelity gaps: `sandbox/declared-gaps.ts` lists them, so every report does.
|
|
48
40
|
*/
|
|
49
41
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
50
42
|
const node_path_1 = __importDefault(require("node:path"));
|
|
@@ -39,6 +39,7 @@ const crypto_1 = require("crypto");
|
|
|
39
39
|
const path = __importStar(require("path"));
|
|
40
40
|
const identity_1 = require("../identity");
|
|
41
41
|
const runtime_1 = require("../../nerves/runtime");
|
|
42
|
+
const process_tree_1 = require("./process-tree");
|
|
42
43
|
function startOfHour(ms) {
|
|
43
44
|
return ms - 60 * 60 * 1000;
|
|
44
45
|
}
|
|
@@ -66,6 +67,9 @@ class DaemonProcessManager {
|
|
|
66
67
|
initialBackoffMs;
|
|
67
68
|
maxBackoffMs;
|
|
68
69
|
spawnFn;
|
|
70
|
+
listProcessesFn;
|
|
71
|
+
killProcessFn;
|
|
72
|
+
reapGraceMs;
|
|
69
73
|
now;
|
|
70
74
|
setTimeoutFn;
|
|
71
75
|
clearTimeoutFn;
|
|
@@ -153,6 +157,9 @@ class DaemonProcessManager {
|
|
|
153
157
|
this.stopTimeoutMs = options.stopTimeoutMs ?? 4_000;
|
|
154
158
|
this.killTimeoutMs = options.killTimeoutMs ?? 2_000;
|
|
155
159
|
this.spawnFn = options.spawn ?? ((command, args, spawnOptions) => (0, child_process_1.spawn)(command, args, spawnOptions));
|
|
160
|
+
this.listProcessesFn = options.listProcesses ?? (options.spawn ? () => [] : process_tree_1.listProcesses);
|
|
161
|
+
this.killProcessFn = options.killProcess ?? (options.spawn ? () => { } : process_tree_1.sendSignal);
|
|
162
|
+
this.reapGraceMs = options.reapGraceMs ?? 1_000;
|
|
156
163
|
this.now = options.now ?? (() => Date.now());
|
|
157
164
|
this.setTimeoutFn = options.setTimeoutFn ?? ((cb, delay) => setTimeout(cb, delay));
|
|
158
165
|
this.clearTimeoutFn = options.clearTimeoutFn ?? ((timer) => clearTimeout(timer));
|
|
@@ -483,7 +490,19 @@ class DaemonProcessManager {
|
|
|
483
490
|
const child = state.process;
|
|
484
491
|
const childPid = child.pid ?? null;
|
|
485
492
|
const childPidLabel = childPid === null ? "unknown" : String(childPid);
|
|
486
|
-
|
|
493
|
+
// Set when what the worker started is being reaped: the stop is not over until its SIGKILL pass has run, so a
|
|
494
|
+
// daemon that exits right after stopping, or a replacement starting at once, never races what is left.
|
|
495
|
+
let reaping = null;
|
|
496
|
+
try {
|
|
497
|
+
await this.signalWorkerToStop(agent, state, child, childPid, childPidLabel, (pass) => { reaping = pass; });
|
|
498
|
+
}
|
|
499
|
+
finally {
|
|
500
|
+
if (reaping)
|
|
501
|
+
await reaping;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
signalWorkerToStop(agent, state, child, childPid, childPidLabel, onReaping) {
|
|
505
|
+
return new Promise((resolve, reject) => {
|
|
487
506
|
let settled = false;
|
|
488
507
|
let timeout = null;
|
|
489
508
|
const finish = (error) => {
|
|
@@ -558,6 +577,9 @@ class DaemonProcessManager {
|
|
|
558
577
|
return;
|
|
559
578
|
// A worker stuck past its own shutdown grace (a turn that never ends, a blocked event loop) would otherwise
|
|
560
579
|
// stay alive with no replacement. SIGKILL ends it; the replacement replays whatever it left pending.
|
|
580
|
+
// Read what the worker started before it dies: once it is gone its children belong to launchd, and sync's
|
|
581
|
+
// detached git groups (with their ssh) would outlive it.
|
|
582
|
+
const tree = childPid === null ? null : (0, process_tree_1.processTreeTargets)(childPid, this.listProcessesFn());
|
|
561
583
|
let killAccepted = false;
|
|
562
584
|
try {
|
|
563
585
|
killAccepted = child.kill("SIGKILL");
|
|
@@ -565,6 +587,27 @@ class DaemonProcessManager {
|
|
|
565
587
|
catch {
|
|
566
588
|
killAccepted = false;
|
|
567
589
|
}
|
|
590
|
+
if (killAccepted && tree) {
|
|
591
|
+
// SIGTERM first: a child that relays signals (sudo, to the ssh it runs) can only pass that one on. Whatever
|
|
592
|
+
// is still there after the grace gets SIGKILL.
|
|
593
|
+
const reaped = (0, process_tree_1.killProcessTree)(tree, childPid, this.killProcessFn, "SIGTERM");
|
|
594
|
+
if (reaped.groups + reaped.processes > 0) {
|
|
595
|
+
(0, runtime_1.emitNervesEvent)({
|
|
596
|
+
level: "warn",
|
|
597
|
+
component: "daemon",
|
|
598
|
+
event: "daemon.agent_stop_reaped_children",
|
|
599
|
+
message: "sent SIGTERM to what the stuck worker started, and SIGKILL after a grace, so none of it outlives the worker",
|
|
600
|
+
meta: { agent, pid: childPid, groups: reaped.groups, processes: reaped.processes, graceMs: this.reapGraceMs },
|
|
601
|
+
});
|
|
602
|
+
onReaping(new Promise((done) => {
|
|
603
|
+
this.setTimeoutFn(() => {
|
|
604
|
+
// Only what is still the worker's: a pid or group freed since the first read may belong to anyone.
|
|
605
|
+
(0, process_tree_1.killProcessTree)((0, process_tree_1.targetsStillInTree)(tree, this.listProcessesFn()), childPid, this.killProcessFn, "SIGKILL");
|
|
606
|
+
done();
|
|
607
|
+
}, this.reapGraceMs);
|
|
608
|
+
}));
|
|
609
|
+
}
|
|
610
|
+
}
|
|
568
611
|
(0, runtime_1.emitNervesEvent)({
|
|
569
612
|
level: "warn",
|
|
570
613
|
component: "daemon",
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.listProcesses = listProcesses;
|
|
4
|
+
exports.sendSignal = sendSignal;
|
|
5
|
+
exports.processTreeTargets = processTreeTargets;
|
|
6
|
+
exports.targetsStillInTree = targetsStillInTree;
|
|
7
|
+
exports.killProcessTree = killProcessTree;
|
|
8
|
+
const node_child_process_1 = require("node:child_process");
|
|
9
|
+
const runtime_1 = require("../../nerves/runtime");
|
|
10
|
+
/** The process table, from `ps`. Empty when it cannot be read. */
|
|
11
|
+
function listProcesses() {
|
|
12
|
+
let output;
|
|
13
|
+
try {
|
|
14
|
+
output = (0, node_child_process_1.execFileSync)("ps", ["-A", "-o", "pid=,ppid=,pgid="], { encoding: "utf-8", timeout: 2_000, killSignal: "SIGKILL" });
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
(0, runtime_1.emitNervesEvent)({
|
|
18
|
+
level: "warn",
|
|
19
|
+
component: "daemon",
|
|
20
|
+
event: "daemon.process_table_unreadable",
|
|
21
|
+
message: "could not read the process table, so what a stopped worker started is not reaped",
|
|
22
|
+
meta: { error: String(error) },
|
|
23
|
+
});
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
return output.split("\n").flatMap((line) => {
|
|
27
|
+
const [pid, ppid, pgid] = line.trim().split(/\s+/).map(Number);
|
|
28
|
+
return Number.isInteger(pid) && Number.isInteger(ppid) && Number.isInteger(pgid) ? [{ pid: pid, ppid: ppid, pgid: pgid }] : [];
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/** Sends a signal to a process, or to a process group when the pid is negative. Throws when it is gone. */
|
|
32
|
+
function sendSignal(pid, signal) {
|
|
33
|
+
process.kill(pid, signal);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The worker and everything below it. A group is killed whole only when its leader is in the tree, so the daemon's
|
|
37
|
+
* own group is never touched; the tree's members in other groups are killed one by one. Init (1) and pid 0 are
|
|
38
|
+
* never named: as a group, -1 means every process and 0 the caller's own group.
|
|
39
|
+
*/
|
|
40
|
+
function processTreeTargets(rootPid, rows) {
|
|
41
|
+
if (rootPid <= 1)
|
|
42
|
+
return { groups: [], pids: [], members: [] };
|
|
43
|
+
const tree = new Set([rootPid]);
|
|
44
|
+
let grew = true;
|
|
45
|
+
while (grew) {
|
|
46
|
+
grew = false;
|
|
47
|
+
for (const row of rows) {
|
|
48
|
+
if (!tree.has(row.pid) && tree.has(row.ppid)) {
|
|
49
|
+
tree.add(row.pid);
|
|
50
|
+
grew = true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
const groupOf = new Map(rows.map((row) => [row.pid, row.pgid]));
|
|
55
|
+
const groups = new Set();
|
|
56
|
+
const pids = [];
|
|
57
|
+
for (const pid of tree) {
|
|
58
|
+
if (pid <= 1)
|
|
59
|
+
continue;
|
|
60
|
+
const pgid = groupOf.get(pid) ?? -1;
|
|
61
|
+
if (pgid > 1 && tree.has(pgid))
|
|
62
|
+
groups.add(pgid);
|
|
63
|
+
else
|
|
64
|
+
pids.push(pid);
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
groups: [...groups].sort((a, b) => a - b),
|
|
68
|
+
pids: pids.sort((a, b) => a - b),
|
|
69
|
+
members: rows.filter((row) => tree.has(row.pid)),
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The targets that are still what they were, from a fresh read of the table, so a later pass never signals a pid or
|
|
74
|
+
* group the system has since handed to something else. A group counts while it holds a member's child (git forks ssh
|
|
75
|
+
* after the first read), or a member that launchd took over when its parent died. A process counts while it keeps its
|
|
76
|
+
* group and its parent is a member or launchd. A pid reused within the grace by a child of launchd would still pass;
|
|
77
|
+
* macOS hands out pids in order, so that needs the whole pid range to wrap in about a second.
|
|
78
|
+
*/
|
|
79
|
+
function targetsStillInTree(targets, rows) {
|
|
80
|
+
const memberPids = new Set(targets.members.map((member) => member.pid));
|
|
81
|
+
const groupOf = new Map(targets.members.map((member) => [member.pid, member.pgid]));
|
|
82
|
+
const stillOurs = (row) => memberPids.has(row.ppid) || (row.ppid === 1 && memberPids.has(row.pid));
|
|
83
|
+
const groups = targets.groups.filter((group) => rows.some((row) => row.pgid === group && stillOurs(row)));
|
|
84
|
+
const pids = targets.pids.filter((pid) => rows.some((row) => row.pid === pid && row.pgid === groupOf.get(pid) && (row.ppid === 1 || memberPids.has(row.ppid))));
|
|
85
|
+
return { groups, pids, members: targets.members };
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Signal every target except `skipPid` (already signalled). A process that is already gone is not an error. Returns
|
|
89
|
+
* how many groups and processes were signalled.
|
|
90
|
+
*/
|
|
91
|
+
function killProcessTree(targets, skipPid, kill, signal) {
|
|
92
|
+
const signalled = { groups: 0, processes: 0 };
|
|
93
|
+
const send = (pid) => {
|
|
94
|
+
try {
|
|
95
|
+
kill(pid, signal);
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
for (const group of targets.groups)
|
|
103
|
+
if (send(-group))
|
|
104
|
+
signalled.groups += 1;
|
|
105
|
+
for (const pid of targets.pids)
|
|
106
|
+
if (pid !== skipPid && send(pid))
|
|
107
|
+
signalled.processes += 1;
|
|
108
|
+
return signalled;
|
|
109
|
+
}
|
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.1406",
|
|
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.1406",
|
|
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.1406",
|
|
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": {
|