benignswarm 0.12.97 → 0.12.99
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/dist/admin-index.js +0 -0
- package/dist/args.js +5 -2
- package/dist/client.js +76 -8
- package/dist/commands/admin.js +10 -1
- package/dist/commands/cloud-admin.js +113 -1
- package/dist/commands/codex-start.js +10 -5
- package/dist/commands/hook.js +24 -11
- package/dist/commands/machine-admin.js +35 -1
- package/dist/commands/machine.js +149 -29
- package/dist/commands/operator.js +1 -0
- package/dist/commands/project-secrets.js +177 -0
- package/dist/commands/routing-admin.js +396 -0
- package/dist/commands/turn.js +21 -0
- package/dist/commands/watch.js +270 -21
- package/dist/commands/worktrees.js +29 -2
- package/dist/commands/wu.js +148 -5
- package/dist/context-policy.js +49 -0
- package/dist/git.js +68 -17
- package/dist/help.js +54 -15
- package/dist/index.js +2 -0
- package/dist/install.js +21 -2
- package/dist/machine-processes.js +312 -0
- package/dist/machine-telemetry.js +125 -0
- package/dist/output.js +3 -0
- package/dist/turn-guard.js +5 -5
- package/dist/version.js +1 -1
- package/package.json +3 -1
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/** Parse one Linux PSI file without turning a missing some/full line into zero. */
|
|
2
|
+
export function parsePressureStall(content) {
|
|
3
|
+
const parseWindow = (kind) => {
|
|
4
|
+
const line = content.split(/\r?\n/).find((entry) => entry.startsWith(`${kind} `));
|
|
5
|
+
if (!line)
|
|
6
|
+
return null;
|
|
7
|
+
const metric = (name) => {
|
|
8
|
+
const match = new RegExp(`(?:^|\\s)${name}=([0-9]+(?:\\.[0-9]+)?)(?:\\s|$)`).exec(line);
|
|
9
|
+
return match ? Number(match[1]) : null;
|
|
10
|
+
};
|
|
11
|
+
const avg10 = metric("avg10"), avg60 = metric("avg60"), avg300 = metric("avg300"), total = metric("total");
|
|
12
|
+
if ([avg10, avg60, avg300, total].every((value) => value === null))
|
|
13
|
+
return null;
|
|
14
|
+
return { avg10, avg60, avg300, total_us: total !== null && Number.isSafeInteger(total) ? total : null };
|
|
15
|
+
};
|
|
16
|
+
const some = parseWindow("some");
|
|
17
|
+
const full = parseWindow("full");
|
|
18
|
+
return some || full ? { some, full } : null;
|
|
19
|
+
}
|
|
20
|
+
function kibibytes(content, key) {
|
|
21
|
+
const match = new RegExp(`^${key}:\\s+(\\d+)\\s+kB\\s*$`, "m").exec(content);
|
|
22
|
+
if (!match)
|
|
23
|
+
return null;
|
|
24
|
+
const bytes = Number(match[1]) * 1024;
|
|
25
|
+
return Number.isSafeInteger(bytes) ? bytes : null;
|
|
26
|
+
}
|
|
27
|
+
/** Linux /proc/meminfo values are kibibytes; zero swap is a valid measured state. */
|
|
28
|
+
export function parseLinuxMemory(content) {
|
|
29
|
+
const total = kibibytes(content, "MemTotal");
|
|
30
|
+
const available = kibibytes(content, "MemAvailable");
|
|
31
|
+
const swapTotal = kibibytes(content, "SwapTotal");
|
|
32
|
+
const swapFree = kibibytes(content, "SwapFree");
|
|
33
|
+
return {
|
|
34
|
+
total_bytes: total,
|
|
35
|
+
available_bytes: available,
|
|
36
|
+
swap_total_bytes: swapTotal,
|
|
37
|
+
swap_used_bytes: swapTotal !== null && swapFree !== null && swapFree <= swapTotal ? swapTotal - swapFree : null,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/** Linux /proc/vmstat swap counters are pages; page size must come from the running host. */
|
|
41
|
+
export function parseLinuxSwapCounters(content, pageSizeBytes) {
|
|
42
|
+
if (!pageSizeBytes || !Number.isSafeInteger(pageSizeBytes) || pageSizeBytes < 1)
|
|
43
|
+
return { in_bytes_total: null, out_bytes_total: null };
|
|
44
|
+
const pages = (key) => {
|
|
45
|
+
const match = new RegExp(`^${key}\\s+(\\d+)\\s*$`, "m").exec(content);
|
|
46
|
+
if (!match)
|
|
47
|
+
return null;
|
|
48
|
+
const count = Number(match[1]);
|
|
49
|
+
const bytes = count * pageSizeBytes;
|
|
50
|
+
return Number.isSafeInteger(bytes) ? bytes : null;
|
|
51
|
+
};
|
|
52
|
+
return { in_bytes_total: pages("pswpin"), out_bytes_total: pages("pswpout") };
|
|
53
|
+
}
|
|
54
|
+
function parseSizeBytes(value, unit) {
|
|
55
|
+
const multiplier = { K: 1024, M: 1024 ** 2, G: 1024 ** 3, T: 1024 ** 4 };
|
|
56
|
+
const bytes = Math.round(Number(value) * (multiplier[unit.toUpperCase()] ?? NaN));
|
|
57
|
+
return Number.isSafeInteger(bytes) ? bytes : null;
|
|
58
|
+
}
|
|
59
|
+
/** Parse `sysctl -n vm.swapusage`; no page-counter rates are inferred on macOS. */
|
|
60
|
+
export function parseMacSwapUsage(content) {
|
|
61
|
+
const field = (name) => {
|
|
62
|
+
const match = new RegExp(`(?:^|\\s)${name}\\s*=\\s*([0-9]+(?:\\.[0-9]+)?)\\s*([KMGT])`, "i").exec(content);
|
|
63
|
+
return match ? parseSizeBytes(match[1], match[2]) : null;
|
|
64
|
+
};
|
|
65
|
+
const totalBytes = field("total"), usedBytes = field("used");
|
|
66
|
+
return totalBytes !== null && usedBytes !== null && usedBytes <= totalBytes ? { total_bytes: totalBytes, used_bytes: usedBytes } : null;
|
|
67
|
+
}
|
|
68
|
+
function flattenPressure(report) {
|
|
69
|
+
return {
|
|
70
|
+
some_avg10: report?.some?.avg10 ?? null,
|
|
71
|
+
some_avg60: report?.some?.avg60 ?? null,
|
|
72
|
+
some_avg300: report?.some?.avg300 ?? null,
|
|
73
|
+
some_total_us: report?.some?.total_us ?? null,
|
|
74
|
+
full_avg10: report?.full?.avg10 ?? null,
|
|
75
|
+
full_avg60: report?.full?.avg60 ?? null,
|
|
76
|
+
full_avg300: report?.full?.avg300 ?? null,
|
|
77
|
+
full_total_us: report?.full?.total_us ?? null,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/** Normalize supported host readings into the daemon report contract. */
|
|
81
|
+
export function machineResourceTelemetry(hostPlatform, readText, pageSizeBytes, macSwapUsage = null) {
|
|
82
|
+
const linux = hostPlatform === "linux";
|
|
83
|
+
const darwin = hostPlatform === "darwin";
|
|
84
|
+
const memoryText = linux ? readText("/proc/meminfo") : null;
|
|
85
|
+
const linuxMemory = memoryText ? parseLinuxMemory(memoryText) : null;
|
|
86
|
+
const macSwap = darwin && macSwapUsage !== null ? parseMacSwapUsage(macSwapUsage) : null;
|
|
87
|
+
const vmstat = linux ? parseLinuxSwapCounters(readText("/proc/vmstat") ?? "", pageSizeBytes) : { in_bytes_total: null, out_bytes_total: null };
|
|
88
|
+
const pressure = (kind) => linux ? parsePressureStall(readText(`/proc/pressure/${kind}`) ?? "") : null;
|
|
89
|
+
const memoryPressure = pressure("memory");
|
|
90
|
+
const cpuPressure = pressure("cpu");
|
|
91
|
+
const ioPressure = pressure("io");
|
|
92
|
+
const swapTotal = linuxMemory?.swap_total_bytes ?? macSwap?.total_bytes ?? null;
|
|
93
|
+
const swapUsed = linuxMemory?.swap_used_bytes ?? macSwap?.used_bytes ?? null;
|
|
94
|
+
const swapAvailable = swapTotal !== null && swapUsed !== null;
|
|
95
|
+
const swapIoAvailable = linux && vmstat.in_bytes_total !== null && vmstat.out_bytes_total !== null;
|
|
96
|
+
return {
|
|
97
|
+
...(linux ? {
|
|
98
|
+
mem_total_bytes: linuxMemory?.total_bytes ?? null,
|
|
99
|
+
mem_available_bytes: linuxMemory?.available_bytes ?? null,
|
|
100
|
+
swap_in_bytes_total: vmstat.in_bytes_total,
|
|
101
|
+
swap_out_bytes_total: vmstat.out_bytes_total,
|
|
102
|
+
} : {
|
|
103
|
+
swap_in_bytes_total: null,
|
|
104
|
+
swap_out_bytes_total: null,
|
|
105
|
+
}),
|
|
106
|
+
swap_total_bytes: swapTotal,
|
|
107
|
+
swap_used_bytes: swapUsed,
|
|
108
|
+
memory_pressure: flattenPressure(memoryPressure),
|
|
109
|
+
cpu_pressure: flattenPressure(cpuPressure),
|
|
110
|
+
io_pressure: flattenPressure(ioPressure),
|
|
111
|
+
metric_availability: {
|
|
112
|
+
memory: linux ? (typeof linuxMemory?.total_bytes === "number" && typeof linuxMemory?.available_bytes === "number" ? "available" : "unavailable") : "available",
|
|
113
|
+
load: linux || darwin ? "available" : "unsupported",
|
|
114
|
+
swap: swapAvailable ? "available" : "unavailable",
|
|
115
|
+
swap_io: swapIoAvailable ? "available" : linux ? "unavailable" : "unsupported",
|
|
116
|
+
memory_pressure: memoryPressure ? "available" : linux ? "unsupported" : "unsupported",
|
|
117
|
+
cpu_pressure: cpuPressure ? "available" : linux ? "unsupported" : "unsupported",
|
|
118
|
+
io_pressure: ioPressure ? "available" : linux ? "unsupported" : "unsupported",
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
export function parsePageSize(content) {
|
|
123
|
+
const value = Number(content.trim());
|
|
124
|
+
return Number.isSafeInteger(value) && value > 0 ? value : null;
|
|
125
|
+
}
|
package/dist/output.js
CHANGED
|
@@ -4,6 +4,8 @@ function receiptLine(data) {
|
|
|
4
4
|
return null;
|
|
5
5
|
return receipts.map((r) => {
|
|
6
6
|
const label = receipts.length > 1 && typeof r.field === "string" ? ` ${r.field}` : "";
|
|
7
|
+
if (r.redacted === true)
|
|
8
|
+
return `${typeof r.field === "string" ? r.field : "text"} redacted by policy: stored ${r.bytes_stored} of ${r.bytes_received} bytes, sha256 ${(String(r.sha256 ?? "")).slice(0, 12)}`;
|
|
7
9
|
return `stored${label} ${r.bytes_stored} bytes, sha256 ${(String(r.sha256 ?? "")).slice(0, 12)}`;
|
|
8
10
|
}).join("; ");
|
|
9
11
|
}
|
|
@@ -35,6 +37,7 @@ export function fmtStatus(s) {
|
|
|
35
37
|
s.blocked_on ? `blocked_on="${s.blocked_on}"` : null,
|
|
36
38
|
`model=${s.model ?? "-"}`,
|
|
37
39
|
s.machine ? `machine=${s.machine}` : null,
|
|
40
|
+
s.machine_pressure ? `machine_health=${s.machine_pressure.state ?? "unknown"} (sample_age=${typeof s.machine_pressure.age_seconds === "number" ? `${Math.floor(s.machine_pressure.age_seconds)}s` : "unknown"}${s.machine_pressure.reasons?.length ? `; reasons=${s.machine_pressure.reasons.join(",")}` : ""})` : null,
|
|
38
41
|
s.capabilities?.length ? `capabilities=${s.capabilities.map((c) => `${c.name}:${c.ready ? c.version ?? "ok" : c.error ?? "stale/unknown"}`).join(",")}` : null,
|
|
39
42
|
s.branch ? `branch=${s.branch}${s.dirty ? "*" : ""}@${s.head ?? "?"}` : null,
|
|
40
43
|
s.worktree ? `worktree=${s.worktree}` : null,
|
package/dist/turn-guard.js
CHANGED
|
@@ -39,7 +39,7 @@ function faultFor(state, reason, now, turns, output, tokenTurns = turns) {
|
|
|
39
39
|
output_tail: output.slice(-OUTPUT_TAIL_LIMIT),
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
export function beginGuardedTurn(state, maxTurnsPerHour, now, activitySeqBefore, unproductivePerHour) {
|
|
42
|
+
export function beginGuardedTurn(state, maxTurnsPerHour, now, activitySeqBefore, unproductivePerHour, turnId, telemetryEnabled = false) {
|
|
43
43
|
const current = state ?? emptyTurnGuard();
|
|
44
44
|
const turns = recentTurns(current, now);
|
|
45
45
|
const next = { ...current, turns, unproductive_per_hour: unproductivePerHour ?? current.unproductive_per_hour ?? DEFAULT_UNPRODUCTIVE_PER_HOUR };
|
|
@@ -48,10 +48,10 @@ export function beginGuardedTurn(state, maxTurnsPerHour, now, activitySeqBefore,
|
|
|
48
48
|
if (turns.length >= maxTurnsPerHour) {
|
|
49
49
|
return { state: next, start: false, pause_until: turns[0].at + HOUR_MS };
|
|
50
50
|
}
|
|
51
|
-
next.turns = [...turns, { at: now, productive: null, estimated_tokens: 0, ...(activitySeqBefore === undefined ? {} : { activity_seq_before: activitySeqBefore }) }];
|
|
51
|
+
next.turns = [...turns, { at: now, productive: null, estimated_tokens: 0, ...(turnId ? { turn_id: turnId, telemetry_enabled: telemetryEnabled } : {}), ...(activitySeqBefore === undefined ? {} : { activity_seq_before: activitySeqBefore }) }];
|
|
52
52
|
return { state: next, start: true };
|
|
53
53
|
}
|
|
54
|
-
export function completeGuardedTurn(state, now, productive, output, tokens) {
|
|
54
|
+
export function completeGuardedTurn(state, now, productive, output, tokens, softTriggers = false) {
|
|
55
55
|
if (state.fault)
|
|
56
56
|
return state;
|
|
57
57
|
const turns = state.turns;
|
|
@@ -70,11 +70,11 @@ export function completeGuardedTurn(state, now, productive, output, tokens) {
|
|
|
70
70
|
const currentHour = recentTurns({ ...state, turns: completed }, now);
|
|
71
71
|
const consecutive = productive ? 0 : state.consecutive_unproductive + 1;
|
|
72
72
|
const next = { turns: currentHour, consecutive_unproductive: consecutive, unproductive_per_hour: state.unproductive_per_hour, fault: null };
|
|
73
|
-
if (!productive && consecutive >= MAX_UNPRODUCTIVE_TURNS) {
|
|
73
|
+
if (!softTriggers && !productive && consecutive >= MAX_UNPRODUCTIVE_TURNS) {
|
|
74
74
|
const fault = faultFor(next, "unproductive", now, currentHour, output, completed.slice(-MAX_UNPRODUCTIVE_TURNS));
|
|
75
75
|
next.fault = fault;
|
|
76
76
|
}
|
|
77
|
-
else if (!productive) {
|
|
77
|
+
else if (!softTriggers && !productive) {
|
|
78
78
|
const unproductive = currentHour.filter((turn) => turn.productive === false);
|
|
79
79
|
const limit = state.unproductive_per_hour ?? DEFAULT_UNPRODUCTIVE_PER_HOUR;
|
|
80
80
|
if (unproductive.length >= limit) {
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CLI_VERSION = "0.12.
|
|
1
|
+
export const CLI_VERSION = "0.12.99";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "benignswarm",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.99",
|
|
4
4
|
"description": "b9s: chat, status board and evidence store for coding agents (benignswarm.org)",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -31,6 +31,8 @@
|
|
|
31
31
|
"scripts": {
|
|
32
32
|
"build": "tsc -p tsconfig.build.json",
|
|
33
33
|
"typecheck": "tsc --noEmit",
|
|
34
|
+
"generate:docs": "node scripts/generate-operator-reference.mjs",
|
|
35
|
+
"check:docs": "node scripts/generate-operator-reference.mjs --check",
|
|
34
36
|
"test": "npm run typecheck && npm run build && vitest run",
|
|
35
37
|
"prepack": "npm run build"
|
|
36
38
|
},
|