feat: add nodes list table with last connect
This commit is contained in:
@@ -23,10 +23,11 @@ clawdbot nodes approve <requestId>
|
|||||||
clawdbot nodes status
|
clawdbot nodes status
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`nodes list` prints pending/paired tables. Paired rows include the most recent connect age (Last Connect).
|
||||||
|
|
||||||
## Invoke / run
|
## Invoke / run
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
clawdbot nodes invoke --node <id|name|ip> --command <command> --params <json>
|
clawdbot nodes invoke --node <id|name|ip> --command <command> --params <json>
|
||||||
clawdbot nodes run --node <id|name|ip> <command...>
|
clawdbot nodes run --node <id|name|ip> <command...>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import { formatAge, formatPermissions, parseNodeList, parsePairingList } from ".
|
|||||||
import { runNodesCommand } from "./cli-utils.js";
|
import { runNodesCommand } from "./cli-utils.js";
|
||||||
import { callGatewayCli, nodesCallOpts, resolveNodeId } from "./rpc.js";
|
import { callGatewayCli, nodesCallOpts, resolveNodeId } from "./rpc.js";
|
||||||
import type { NodesRpcOpts } from "./types.js";
|
import type { NodesRpcOpts } from "./types.js";
|
||||||
|
import { renderTable } from "../../terminal/table.js";
|
||||||
|
import { isRich, theme } from "../../terminal/theme.js";
|
||||||
|
|
||||||
function formatVersionLabel(raw: string) {
|
function formatVersionLabel(raw: string) {
|
||||||
const trimmed = raw.trim();
|
const trimmed = raw.trim();
|
||||||
@@ -155,23 +157,65 @@ export function registerNodesStatusCommands(nodes: Command) {
|
|||||||
}
|
}
|
||||||
const { pending, paired } = parsePairingList(result);
|
const { pending, paired } = parsePairingList(result);
|
||||||
defaultRuntime.log(`Pending: ${pending.length} · Paired: ${paired.length}`);
|
defaultRuntime.log(`Pending: ${pending.length} · Paired: ${paired.length}`);
|
||||||
|
const rich = isRich();
|
||||||
|
const heading = (text: string) => (rich ? theme.heading(text) : text);
|
||||||
|
const muted = (text: string) => (rich ? theme.muted(text) : text);
|
||||||
|
const warn = (text: string) => (rich ? theme.warn(text) : text);
|
||||||
|
const tableWidth = Math.max(60, (process.stdout.columns ?? 120) - 1);
|
||||||
|
const now = Date.now();
|
||||||
|
|
||||||
if (pending.length > 0) {
|
if (pending.length > 0) {
|
||||||
defaultRuntime.log("\nPending:");
|
const pendingRows = pending.map((r) => ({
|
||||||
for (const r of pending) {
|
Request: r.requestId,
|
||||||
const name = r.displayName || r.nodeId;
|
Node: r.displayName?.trim() ? r.displayName.trim() : r.nodeId,
|
||||||
const repair = r.isRepair ? " (repair)" : "";
|
IP: r.remoteIp ?? "",
|
||||||
const ip = r.remoteIp ? ` · ${r.remoteIp}` : "";
|
Requested:
|
||||||
const age = typeof r.ts === "number" ? ` · ${formatAge(Date.now() - r.ts)} ago` : "";
|
typeof r.ts === "number"
|
||||||
defaultRuntime.log(`- ${r.requestId}: ${name}${repair}${ip}${age}`);
|
? `${formatAge(Math.max(0, now - r.ts))} ago`
|
||||||
}
|
: muted("unknown"),
|
||||||
|
Repair: r.isRepair ? warn("yes") : "",
|
||||||
|
}));
|
||||||
|
defaultRuntime.log("");
|
||||||
|
defaultRuntime.log(heading("Pending"));
|
||||||
|
defaultRuntime.log(
|
||||||
|
renderTable({
|
||||||
|
width: tableWidth,
|
||||||
|
columns: [
|
||||||
|
{ key: "Request", header: "Request", minWidth: 8 },
|
||||||
|
{ key: "Node", header: "Node", minWidth: 14, flex: true },
|
||||||
|
{ key: "IP", header: "IP", minWidth: 10 },
|
||||||
|
{ key: "Requested", header: "Requested", minWidth: 12 },
|
||||||
|
{ key: "Repair", header: "Repair", minWidth: 6 },
|
||||||
|
],
|
||||||
|
rows: pendingRows,
|
||||||
|
}).trimEnd(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (paired.length > 0) {
|
if (paired.length > 0) {
|
||||||
defaultRuntime.log("\nPaired:");
|
const pairedRows = paired.map((n) => ({
|
||||||
for (const n of paired) {
|
Node: n.displayName?.trim() ? n.displayName.trim() : n.nodeId,
|
||||||
const name = n.displayName || n.nodeId;
|
Id: n.nodeId,
|
||||||
const ip = n.remoteIp ? ` · ${n.remoteIp}` : "";
|
IP: n.remoteIp ?? "",
|
||||||
defaultRuntime.log(`- ${n.nodeId}: ${name}${ip}`);
|
LastConnect:
|
||||||
}
|
typeof n.lastConnectedAtMs === "number"
|
||||||
|
? `${formatAge(Math.max(0, now - n.lastConnectedAtMs))} ago`
|
||||||
|
: muted("unknown"),
|
||||||
|
}));
|
||||||
|
defaultRuntime.log("");
|
||||||
|
defaultRuntime.log(heading("Paired"));
|
||||||
|
defaultRuntime.log(
|
||||||
|
renderTable({
|
||||||
|
width: tableWidth,
|
||||||
|
columns: [
|
||||||
|
{ key: "Node", header: "Node", minWidth: 14, flex: true },
|
||||||
|
{ key: "Id", header: "ID", minWidth: 10 },
|
||||||
|
{ key: "IP", header: "IP", minWidth: 10 },
|
||||||
|
{ key: "LastConnect", header: "Last Connect", minWidth: 14 },
|
||||||
|
],
|
||||||
|
rows: pairedRows,
|
||||||
|
}).trimEnd(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ export type PairedNode = {
|
|||||||
permissions?: Record<string, boolean>;
|
permissions?: Record<string, boolean>;
|
||||||
createdAtMs?: number;
|
createdAtMs?: number;
|
||||||
approvedAtMs?: number;
|
approvedAtMs?: number;
|
||||||
|
lastConnectedAtMs?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type PairingList = {
|
export type PairingList = {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
updatePairedDeviceMetadata,
|
updatePairedDeviceMetadata,
|
||||||
verifyDeviceToken,
|
verifyDeviceToken,
|
||||||
} from "../../../infra/device-pairing.js";
|
} from "../../../infra/device-pairing.js";
|
||||||
|
import { updatePairedNodeMetadata } from "../../../infra/node-pairing.js";
|
||||||
import { recordRemoteNodeInfo, refreshRemoteNodeBins } from "../../../infra/skills-remote.js";
|
import { recordRemoteNodeInfo, refreshRemoteNodeBins } from "../../../infra/skills-remote.js";
|
||||||
import { loadVoiceWakeConfig } from "../../../infra/voicewake.js";
|
import { loadVoiceWakeConfig } from "../../../infra/voicewake.js";
|
||||||
import { upsertPresence } from "../../../infra/system-presence.js";
|
import { upsertPresence } from "../../../infra/system-presence.js";
|
||||||
@@ -718,6 +719,13 @@ export function attachGatewayWsMessageHandler(params: {
|
|||||||
if (role === "node") {
|
if (role === "node") {
|
||||||
const context = buildRequestContext();
|
const context = buildRequestContext();
|
||||||
const nodeSession = context.nodeRegistry.register(nextClient, { remoteIp: remoteAddr });
|
const nodeSession = context.nodeRegistry.register(nextClient, { remoteIp: remoteAddr });
|
||||||
|
void updatePairedNodeMetadata(nodeSession.nodeId, {
|
||||||
|
lastConnectedAtMs: nodeSession.connectedAtMs,
|
||||||
|
}).catch((err) =>
|
||||||
|
logGateway.warn(
|
||||||
|
`failed to record last connect for ${nodeSession.nodeId}: ${formatForLog(err)}`,
|
||||||
|
),
|
||||||
|
);
|
||||||
recordRemoteNodeInfo({
|
recordRemoteNodeInfo({
|
||||||
nodeId: nodeSession.nodeId,
|
nodeId: nodeSession.nodeId,
|
||||||
displayName: nodeSession.displayName,
|
displayName: nodeSession.displayName,
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ export type NodePairingPairedNode = {
|
|||||||
remoteIp?: string;
|
remoteIp?: string;
|
||||||
createdAtMs: number;
|
createdAtMs: number;
|
||||||
approvedAtMs: number;
|
approvedAtMs: number;
|
||||||
|
lastConnectedAtMs?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type NodePairingList = {
|
export type NodePairingList = {
|
||||||
@@ -295,6 +296,7 @@ export async function updatePairedNodeMetadata(
|
|||||||
commands: patch.commands ?? existing.commands,
|
commands: patch.commands ?? existing.commands,
|
||||||
bins: patch.bins ?? existing.bins,
|
bins: patch.bins ?? existing.bins,
|
||||||
permissions: patch.permissions ?? existing.permissions,
|
permissions: patch.permissions ?? existing.permissions,
|
||||||
|
lastConnectedAtMs: patch.lastConnectedAtMs ?? existing.lastConnectedAtMs,
|
||||||
};
|
};
|
||||||
|
|
||||||
state.pairedByNodeId[normalized] = next;
|
state.pairedByNodeId[normalized] = next;
|
||||||
|
|||||||
Reference in New Issue
Block a user