- apps/cli/ is now the canonical CLI (was apps/cli-v2/). - apps/cli/ legacy v0 archived as branch 'legacy-cli-archive' and tag 'cli-v0-legacy-final' before deletion; git history preserves it too. - .github/workflows/release-cli.yml paths updated. - pnpm-lock.yaml regenerated. Broker-side peer-grant enforcement (spec: 2026-04-15-per-peer-capabilities): - 0020_peer-grants.sql adds peer_grants jsonb + GIN index on mesh.member. - handleSend in broker fetches recipient grant maps once per send, drops messages silently when sender lacks the required capability. - POST /cli/mesh/:slug/grants to update from CLI; broker_messages_dropped_by_grant_total metric. - CLI grant/revoke/block now mirror to broker via syncToBroker. Auto-migrate on broker startup: - apps/broker/src/migrate.ts runs drizzle migrate with pg_advisory_lock before the HTTP server binds. Exits non-zero on failure so Coolify healthcheck fails closed. - Dockerfile copies packages/db/migrations into /app/migrations. - postgres 3.4.5 added as direct broker dep. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
102 lines
2.9 KiB
TypeScript
102 lines
2.9 KiB
TypeScript
/**
|
|
* `claudemesh status` — one-shot health report.
|
|
*
|
|
* Reports CLI version, config path + permissions, each joined mesh
|
|
* with broker reachability (WS handshake probe). Exit 0 if every
|
|
* mesh's broker is reachable, 1 otherwise.
|
|
*/
|
|
|
|
import { statSync, existsSync } from "node:fs";
|
|
import WebSocket from "ws";
|
|
import { readConfig, getConfigPath } from "~/services/config/facade.js";
|
|
import { VERSION } from "~/constants/urls.js";
|
|
import { render } from "~/ui/render.js";
|
|
|
|
interface MeshStatus {
|
|
slug: string;
|
|
brokerUrl: string;
|
|
pubkey: string;
|
|
reachable: boolean;
|
|
error?: string;
|
|
latencyMs?: number;
|
|
}
|
|
|
|
async function probeBroker(url: string, timeoutMs = 4000): Promise<{ ok: boolean; error?: string; latencyMs?: number }> {
|
|
return new Promise((resolve) => {
|
|
const started = Date.now();
|
|
const ws = new WebSocket(url);
|
|
const timer = setTimeout(() => {
|
|
try { ws.terminate(); } catch { /* noop */ }
|
|
resolve({ ok: false, error: "timeout" });
|
|
}, timeoutMs);
|
|
ws.on("open", () => {
|
|
clearTimeout(timer);
|
|
const latency = Date.now() - started;
|
|
try { ws.close(); } catch { /* noop */ }
|
|
resolve({ ok: true, latencyMs: latency });
|
|
});
|
|
ws.on("error", (err) => {
|
|
clearTimeout(timer);
|
|
resolve({ ok: false, error: err.message });
|
|
});
|
|
});
|
|
}
|
|
|
|
export async function runStatus(): Promise<void> {
|
|
render.section(`status (v${VERSION})`);
|
|
|
|
const configPath = getConfigPath();
|
|
let configPermsNote = "missing";
|
|
if (existsSync(configPath)) {
|
|
const mode = (statSync(configPath).mode & 0o777).toString(8).padStart(4, "0");
|
|
configPermsNote = mode === "0600" ? `${mode}` : `${mode} — expected 0600`;
|
|
}
|
|
render.kv([["config", configPath], ["perms", configPermsNote]]);
|
|
|
|
const config = readConfig();
|
|
if (config.meshes.length === 0) {
|
|
render.blank();
|
|
render.info("No meshes joined.");
|
|
render.hint("claudemesh <invite-url> # join + launch");
|
|
process.exit(0);
|
|
}
|
|
|
|
render.blank();
|
|
render.heading(`meshes (${config.meshes.length})`);
|
|
|
|
const results: MeshStatus[] = [];
|
|
for (const m of config.meshes) {
|
|
const probe = await probeBroker(m.brokerUrl);
|
|
const entry: MeshStatus = {
|
|
slug: m.slug,
|
|
brokerUrl: m.brokerUrl,
|
|
pubkey: m.pubkey,
|
|
reachable: probe.ok,
|
|
error: probe.error,
|
|
latencyMs: probe.latencyMs,
|
|
};
|
|
results.push(entry);
|
|
if (probe.ok) {
|
|
render.ok(`${m.slug}`, `${probe.latencyMs}ms → ${m.brokerUrl}`);
|
|
} else {
|
|
render.err(`${m.slug}`, `unreachable (${probe.error})`);
|
|
}
|
|
}
|
|
|
|
render.blank();
|
|
for (const r of results) {
|
|
render.kv([[r.slug, `${r.pubkey.slice(0, 16)}…`]]);
|
|
}
|
|
|
|
const allOk = results.every((r) => r.reachable);
|
|
render.blank();
|
|
if (allOk) {
|
|
render.ok("all meshes reachable");
|
|
process.exit(0);
|
|
} else {
|
|
const broken = results.filter((r) => !r.reachable).length;
|
|
render.err(`${broken} of ${results.length} mesh(es) unreachable`);
|
|
process.exit(1);
|
|
}
|
|
}
|