clawdie-ai/scripts/system-health.ts
Clawdie AI 2160e7859e feat(phase4): just front door + safety rules + bugfix (Sam & Claude)
Rewrites justfile with 8 groups, 35+ recipes with docstrings.

Creates 8 CLI helper scripts (jail-status, hostd-cli, system-health,

agent-status, agent-task, agent-task-status, agent-logs, jail-provision).

Adds 4 hostd safety rules to safety.yaml (destroy, rollback, zfs-destroy, pf).

Fixes task_create empty assigned_to bug in controlplane-tools.ts.

Build: pass | Tests: not run (Linux)
2026-04-14 01:28:31 +02:00

76 lines
2.1 KiB
TypeScript

import { hostd } from '../src/hostd/client.js';
async function main(): Promise<void> {
const [jailRes, zfsRes, pfRes] = await Promise.all([
hostd('bastille-list').catch(() => ({
ok: false as const,
output: '',
error: 'unreachable',
})),
hostd('zfs-list').catch(() => ({
ok: false as const,
output: '',
error: 'unreachable',
})),
hostd('service-status', { service: 'pf' }).catch(() => ({
ok: false as const,
output: '',
error: 'unreachable',
})),
]);
console.log('=== SYSTEM HEALTH ===\n');
console.log('-- Jails --');
if (jailRes.ok) {
const lines = jailRes.output
.split('\n')
.filter((l) => l.trim() && !/^\s*(JID|Name|---)/i.test(l));
const jails = lines.map((l) => {
const p = l.trim().split(/\s+/);
return {
jid: p[0],
ip: p[1],
name: p[2],
state: p[0] === '-' ? 'stopped' : 'running',
};
});
const running = jails.filter((j) => j.state === 'running').length;
console.log(
` ${jails.length} jail(s), ${running} running, ${jails.length - running} stopped`,
);
for (const j of jails) {
console.log(` ${j.state === 'running' ? '●' : '○'} ${j.name} (${j.ip})`);
}
} else {
console.log(' Unable to reach hostd');
}
console.log('\n-- ZFS --');
if (zfsRes.ok) {
const lines = zfsRes.output
.split('\n')
.filter((l) => l.trim() && !/^NAME/i.test(l));
for (const line of lines.slice(0, 8)) {
const parts = line.trim().split(/\s+/);
console.log(` ${parts[0]}: used=${parts[1]} avail=${parts[2]}`);
}
if (lines.length > 8) console.log(` ... and ${lines.length - 8} more`);
} else {
console.log(' Unable to reach hostd');
}
console.log('\n-- PF Firewall --');
if (pfRes.ok) {
console.log(` ${pfRes.output.trim()}`);
} else {
console.log(' Unable to reach hostd');
}
console.log(`\nGenerated: ${new Date().toISOString()}`);
}
main().catch((err) => {
console.error('Error:', err instanceof Error ? err.message : String(err));
process.exit(1);
});