Adds justfile with 8 grouped recipe sections covering build, jail management, skill catalog, agent ops, and system admin. Adds scripts for skill-list/add/sync, jail-status, system-health, agent-task/status/logs, harness-check, and hostd-cli. Fixes project root derivation to use import.meta.url instead of process.cwd() so scripts work regardless of invocation directory. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --- Build: pass | Tests: FAIL — Tests 40 failed | 766 passed (806)
62 lines
2 KiB
TypeScript
62 lines
2 KiB
TypeScript
#!/usr/bin/env npx tsx
|
|
/**
|
|
* scripts/hostd-cli.ts — Generic hostd operation CLI wrapper.
|
|
*
|
|
* Usage:
|
|
* just zfs-snapshots # bastille-list
|
|
* just zfs-snapshot tank/db pre-deploy # zfs-snapshot with args
|
|
* npx tsx scripts/hostd-cli.ts bastille-list
|
|
* npx tsx scripts/hostd-cli.ts zfs-snapshot '{"dataset":"tank/db","name":"pre-deploy"}'
|
|
* npx tsx scripts/hostd-cli.ts service-restart '{"jail":"cms","service":"nginx"}'
|
|
*/
|
|
import { hostd } from '../src/hostd/client.js';
|
|
|
|
const [op, rawParams] = process.argv.slice(2);
|
|
|
|
if (!op) {
|
|
console.error('Usage: hostd-cli.ts <op> [json-params]');
|
|
console.error('');
|
|
console.error('Ops: bastille-start bastille-stop bastille-restart bastille-list');
|
|
console.error(' zfs-snapshot zfs-list zfs-create zfs-rollback');
|
|
console.error(' pf-reload pf-enable');
|
|
console.error(' service-start service-stop service-restart service-status');
|
|
console.error(' bastille-pkg-install bastille-mount-pkg-cache');
|
|
process.exit(1);
|
|
}
|
|
|
|
async function main(): Promise<void> {
|
|
let params: Record<string, string | number | boolean> = {};
|
|
|
|
if (rawParams) {
|
|
try {
|
|
params = JSON.parse(rawParams) as Record<string, string | number | boolean>;
|
|
} catch {
|
|
console.error(`Invalid JSON params: ${rawParams}`);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
let resp;
|
|
try {
|
|
resp = await hostd(op, params);
|
|
} catch (err) {
|
|
const msg = err instanceof Error ? err.message : String(err);
|
|
if (msg.includes('ENOENT') || msg.includes('ECONNREFUSED')) {
|
|
console.error('hostd not reachable. Is clawdie-hostd running?');
|
|
} else {
|
|
console.error(`Error: ${msg}`);
|
|
}
|
|
process.exit(1);
|
|
}
|
|
|
|
if (resp.output) process.stdout.write(resp.output + (resp.output.endsWith('\n') ? '' : '\n'));
|
|
if (!resp.ok) {
|
|
if (resp.error) console.error(`Error: ${resp.error}`);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
main().catch((err: Error) => {
|
|
console.error(err.message);
|
|
process.exit(1);
|
|
});
|