spur-board 0.152.0 → 0.153.0
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/daemon.mjs
CHANGED
|
@@ -50,6 +50,22 @@ const PERSONA_ROLES = [
|
|
|
50
50
|
"worker",
|
|
51
51
|
"board"
|
|
52
52
|
];
|
|
53
|
+
// ../contracts/src/host-usage.ts
|
|
54
|
+
/**
|
|
55
|
+
* Levels of host usage shared by the web meters, the status bar dot and the board's disk item:
|
|
56
|
+
* a reading is at a level when its used fraction is at or above it, as the Meter colours it.
|
|
57
|
+
*/
|
|
58
|
+
const HOST_USAGE_LEVELS = {
|
|
59
|
+
warn: .8,
|
|
60
|
+
error: .9
|
|
61
|
+
};
|
|
62
|
+
/** The level of a reading given in percent used, 0-100. */
|
|
63
|
+
function hostUsageLevel(usedPercent) {
|
|
64
|
+
const used = usedPercent / 100;
|
|
65
|
+
if (used >= HOST_USAGE_LEVELS.error) return "error";
|
|
66
|
+
if (used >= HOST_USAGE_LEVELS.warn) return "warn";
|
|
67
|
+
return "ok";
|
|
68
|
+
}
|
|
53
69
|
// ../core/src/store/copy.ts
|
|
54
70
|
/**
|
|
55
71
|
* Opens a database read-write with no PRAGMA, migration or version check: the connection only
|
|
@@ -15164,6 +15180,79 @@ async function externalQuietItems(trx, config, now, tasks, sourceById) {
|
|
|
15164
15180
|
held
|
|
15165
15181
|
};
|
|
15166
15182
|
}
|
|
15183
|
+
// ../core/src/app/host-disk.ts
|
|
15184
|
+
const HOST_DISK_KEY = "host-disk:";
|
|
15185
|
+
const META_KEY = "host_disk";
|
|
15186
|
+
const GIB = 2 ** 30;
|
|
15187
|
+
/**
|
|
15188
|
+
* Per mount: the run of samples in a row at the error level, when the open episode began (null
|
|
15189
|
+
* when none is open) and the latest reading.
|
|
15190
|
+
*/
|
|
15191
|
+
const stateSchema = z.record(z.string(), z.strictObject({
|
|
15192
|
+
streak: z.number().int().nonnegative(),
|
|
15193
|
+
since: z.iso.datetime().nullable(),
|
|
15194
|
+
usedPercent: z.number(),
|
|
15195
|
+
availableBytes: z.number(),
|
|
15196
|
+
sampledAt: z.iso.datetime()
|
|
15197
|
+
}));
|
|
15198
|
+
/** The stored state; a missing or malformed value reads as empty. */
|
|
15199
|
+
async function readState(trx) {
|
|
15200
|
+
const row = await trx.selectFrom("meta").select("value").where("key", "=", META_KEY).executeTakeFirst();
|
|
15201
|
+
if (row === void 0) return {};
|
|
15202
|
+
try {
|
|
15203
|
+
const parsed = stateSchema.safeParse(JSON.parse(row.value));
|
|
15204
|
+
return parsed.success ? parsed.data : {};
|
|
15205
|
+
} catch {
|
|
15206
|
+
return {};
|
|
15207
|
+
}
|
|
15208
|
+
}
|
|
15209
|
+
/**
|
|
15210
|
+
* Records one host sample's volumes. Two samples in a row at the error level open an episode; a
|
|
15211
|
+
* sample below the warn level ends it. A mount missing from the sample keeps its entry.
|
|
15212
|
+
*/
|
|
15213
|
+
async function recordHostDisk(store, sample) {
|
|
15214
|
+
await store.transaction(async (trx) => {
|
|
15215
|
+
const state = await readState(trx);
|
|
15216
|
+
for (const volume of sample.volumes) {
|
|
15217
|
+
const level = hostUsageLevel(volume.usedPercent);
|
|
15218
|
+
const previous = state[volume.mount];
|
|
15219
|
+
const streak = level === "error" ? (previous?.streak ?? 0) + 1 : 0;
|
|
15220
|
+
let since = previous?.since ?? null;
|
|
15221
|
+
if (level === "ok") since = null;
|
|
15222
|
+
else if (streak >= 2 && since === null) since = sample.sampledAt;
|
|
15223
|
+
state[volume.mount] = {
|
|
15224
|
+
streak,
|
|
15225
|
+
since,
|
|
15226
|
+
usedPercent: volume.usedPercent,
|
|
15227
|
+
availableBytes: volume.availableBytes,
|
|
15228
|
+
sampledAt: sample.sampledAt
|
|
15229
|
+
};
|
|
15230
|
+
}
|
|
15231
|
+
const value = JSON.stringify(stateSchema.parse(state));
|
|
15232
|
+
await trx.insertInto("meta").values({
|
|
15233
|
+
key: META_KEY,
|
|
15234
|
+
value
|
|
15235
|
+
}).onConflict((oc) => oc.column("key").doUpdateSet({ value })).execute();
|
|
15236
|
+
});
|
|
15237
|
+
}
|
|
15238
|
+
/**
|
|
15239
|
+
* One item per volume with an open episode. The fingerprint hashes the mount and the episode
|
|
15240
|
+
* start, so the item and its feed line stay while the shown numbers follow the latest sample.
|
|
15241
|
+
*/
|
|
15242
|
+
async function hostDiskItems(trx) {
|
|
15243
|
+
const state = await readState(trx);
|
|
15244
|
+
return Object.entries(state).flatMap(([mount, entry]) => entry.since === null ? [] : [{
|
|
15245
|
+
key: `${HOST_DISK_KEY}${mount}`,
|
|
15246
|
+
kind: "board_observation",
|
|
15247
|
+
taskId: null,
|
|
15248
|
+
summary: `host disk ${mount}: ${String(Math.floor(entry.usedPercent))}% used, ${(entry.availableBytes / GIB).toFixed(1)} GiB free`,
|
|
15249
|
+
hashedSummary: `host disk ${mount}`,
|
|
15250
|
+
factAt: entry.sampledAt,
|
|
15251
|
+
source: null,
|
|
15252
|
+
priority: 4,
|
|
15253
|
+
revision: entry.since
|
|
15254
|
+
}]);
|
|
15255
|
+
}
|
|
15167
15256
|
// ../core/src/app/quiet-turns.ts
|
|
15168
15257
|
/**
|
|
15169
15258
|
* How long the holder of a taken turn may sit quiet before it is reminded, then flagged: the column
|
|
@@ -15931,6 +16020,7 @@ async function reconcileItems(trx, config, now, spurComplete, warnSkipped, spurC
|
|
|
15931
16020
|
candidates.push(...quiet.candidates);
|
|
15932
16021
|
heldKeys.push(...quiet.held);
|
|
15933
16022
|
candidates.push(...await turnWaitItems(trx, config, taskById));
|
|
16023
|
+
candidates.push(...await hostDiskItems(trx));
|
|
15934
16024
|
const ordered = orderItems(candidates);
|
|
15935
16025
|
const seen = /* @__PURE__ */ new Set([...ordered.map((item) => item.key), ...heldKeys]);
|
|
15936
16026
|
for (const flag of health.held) {
|
|
@@ -29162,10 +29252,12 @@ function untilAborted(promise, signal) {
|
|
|
29162
29252
|
* `read` never samples. A metric whose read fails is null, with one warning per metric; a disk
|
|
29163
29253
|
* path whose read fails is left out of `volumes`, with one warning per path. Volumes are deduped
|
|
29164
29254
|
* by device and listed least free bytes first; `disk` is the first. Stop aborts pending disk
|
|
29165
|
-
* reads instead of waiting for them, and that run writes nothing.
|
|
29255
|
+
* reads instead of waiting for them, and that run writes nothing. `onSample` gets each sample
|
|
29256
|
+
* once it is stored, so `read` already returns it; its failure is the run's error and leaves the
|
|
29257
|
+
* sample readable.
|
|
29166
29258
|
*/
|
|
29167
29259
|
function createHostSampler(options) {
|
|
29168
|
-
const { probe, clock, log, intervalMs = HOST_SAMPLE_MS } = options;
|
|
29260
|
+
const { probe, clock, log, intervalMs = HOST_SAMPLE_MS, onSample } = options;
|
|
29169
29261
|
let last = null;
|
|
29170
29262
|
let previousCpu;
|
|
29171
29263
|
const warned = /* @__PURE__ */ new Set();
|
|
@@ -29218,7 +29310,7 @@ function createHostSampler(options) {
|
|
|
29218
29310
|
});
|
|
29219
29311
|
});
|
|
29220
29312
|
volumes.sort((a, b) => a.availableBytes - b.availableBytes);
|
|
29221
|
-
|
|
29313
|
+
const taken = {
|
|
29222
29314
|
sampledAt,
|
|
29223
29315
|
cpuPercent,
|
|
29224
29316
|
memory: mem === null ? null : {
|
|
@@ -29229,6 +29321,8 @@ function createHostSampler(options) {
|
|
|
29229
29321
|
disk: volumes[0] ?? null,
|
|
29230
29322
|
volumes
|
|
29231
29323
|
};
|
|
29324
|
+
last = taken;
|
|
29325
|
+
await onSample?.(taken);
|
|
29232
29326
|
};
|
|
29233
29327
|
const own = new AbortController();
|
|
29234
29328
|
const job = createJob({
|
|
@@ -30393,7 +30487,8 @@ function createDaemonModules(ctxFor, ports = {}) {
|
|
|
30393
30487
|
const host = createHostSampler({
|
|
30394
30488
|
probe: ports.hostProbe ?? createHostProbe(ports.dataDir),
|
|
30395
30489
|
clock: hostCtx.clock,
|
|
30396
|
-
log: hostCtx.log
|
|
30490
|
+
log: hostCtx.log,
|
|
30491
|
+
onSample: (sample) => recordHostDisk(hostCtx.store, sample)
|
|
30397
30492
|
});
|
|
30398
30493
|
let webPort;
|
|
30399
30494
|
let lastDispatchAt = null;
|