pi-braid 0.40.6 → 0.41.1
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/README.md +13 -1
- package/build-info.json +4 -4
- package/docs/CONTEXT-MAP.md +1 -1
- package/docs/FLEET.md +134 -0
- package/package.json +5 -1
- package/scripts/fleet/cli.mjs +540 -0
- package/scripts/fleet/driver-rpc.mjs +376 -0
- package/scripts/fleet/driver-scripted.mjs +239 -0
- package/scripts/fleet/journal.mjs +1124 -0
- package/scripts/fleet/procs.mjs +76 -0
- package/scripts/fleet/supervisor.mjs +1649 -0
- package/scripts/fleet/tool-guard.mjs +467 -0
- package/skills/release-pipeline/SKILL.md +20 -4
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Process facts the fleet reads from the operating system rather than from its
|
|
3
|
+
* own bookkeeping: is a pid alive, is a process group alive, how much resident
|
|
4
|
+
* memory a set of pids holds.
|
|
5
|
+
*
|
|
6
|
+
* The journal records what the supervisor believes; these answer what the box
|
|
7
|
+
* actually holds, which is the only instrument an orphan fence or a memory
|
|
8
|
+
* budget can be checked with.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { execFileSync } from "node:child_process";
|
|
12
|
+
|
|
13
|
+
/** A pid that exists counts as alive; EPERM means it exists under another user. */
|
|
14
|
+
export function pidIsAlive(pid) {
|
|
15
|
+
if (!pid) return false;
|
|
16
|
+
try {
|
|
17
|
+
process.kill(pid, 0);
|
|
18
|
+
return true;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
return error.code === "EPERM";
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** True when any member of the process group is still running. */
|
|
25
|
+
export function groupIsAlive(pgid) {
|
|
26
|
+
if (!pgid) return false;
|
|
27
|
+
try {
|
|
28
|
+
process.kill(-pgid, 0);
|
|
29
|
+
return true;
|
|
30
|
+
} catch (error) {
|
|
31
|
+
return error.code === "EPERM";
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* RSS in mebibytes for one pid, or null when `ps` reports nothing. `ps` is the
|
|
37
|
+
* instrument because it reads the kernel's number, not ours.
|
|
38
|
+
*/
|
|
39
|
+
export function rssMb(pid) {
|
|
40
|
+
if (!pid) return null;
|
|
41
|
+
try {
|
|
42
|
+
const out = execFileSync("ps", ["-o", "rss=", "-p", String(pid)], { encoding: "utf8" }).trim();
|
|
43
|
+
if (!out) return null;
|
|
44
|
+
return Math.round(Number(out) / 1024);
|
|
45
|
+
} catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The supervisor's own resident set plus every pid in it, as `{pids, totalMb}`.
|
|
52
|
+
* A pid that vanished between listing and reading contributes zero rather than
|
|
53
|
+
* aborting the sum, so a sample taken across a settle still prints.
|
|
54
|
+
*/
|
|
55
|
+
export function residentMb(pids) {
|
|
56
|
+
const rows = [];
|
|
57
|
+
let totalMb = 0;
|
|
58
|
+
for (const pid of pids) {
|
|
59
|
+
const mb = rssMb(pid);
|
|
60
|
+
if (mb == null) continue;
|
|
61
|
+
rows.push({ pid, mb });
|
|
62
|
+
totalMb += mb;
|
|
63
|
+
}
|
|
64
|
+
return { pids: rows, totalMb };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** True when `pid` is a live descendant of the current process. */
|
|
68
|
+
export function isOwnChild(pid) {
|
|
69
|
+
if (!pidIsAlive(pid)) return false;
|
|
70
|
+
try {
|
|
71
|
+
const out = execFileSync("ps", ["-o", "ppid=", "-p", String(pid)], { encoding: "utf8" }).trim();
|
|
72
|
+
return Number(out) === process.pid;
|
|
73
|
+
} catch {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|