feature/pi-refactor
1/**
2 * Status Tool - Show system status (uptime, memory, load)
3 */
4
5import { Type } from "@sinclair/typebox";
6import type { AgentTool } from "@mariozechner/pi-agent-core";
7import * as os from "os";
8
9export const statusTool: AgentTool = {
10 name: "status",
11 label: "System Status",
12 description: "Show system status including uptime, memory usage, and load average",
13 parameters: Type.Object({}),
14 execute: async (_toolCallId, _params, _signal, _onUpdate) => {
15 // Get system information
16 const uptimeSeconds = os.uptime();
17 const totalMemory = os.totalmem();
18 const freeMemory = os.freemem();
19 const usedMemory = totalMemory - freeMemory;
20 const memoryUsagePercent = ((usedMemory / totalMemory) * 100).toFixed(1);
21 const loadAvg = os.loadavg();
22
23 // Format uptime
24 const hours = Math.floor(uptimeSeconds / 3600);
25 const minutes = Math.floor((uptimeSeconds % 3600) / 60);
26 const uptimeFormatted = `${hours}h ${minutes}m`;
27
28 // Format memory
29 const totalMemoryGB = (totalMemory / (1024 * 1024 * 1024)).toFixed(2);
30 const usedMemoryGB = (usedMemory / (1024 * 1024 * 1024)).toFixed(2);
31
32 const statusText = `System Status:
33
34Uptime: ${uptimeFormatted} (${Math.floor(uptimeSeconds)}s)
35
36Memory:
37 Total: ${totalMemoryGB} GB
38 Used: ${usedMemoryGB} GB (${memoryUsagePercent}%)
39 Free: ${(freeMemory / (1024 * 1024 * 1024)).toFixed(2)} GB
40
41Load Average:
42 1 min: ${loadAvg[0].toFixed(2)}
43 5 min: ${loadAvg[1].toFixed(2)}
44 15 min: ${loadAvg[2].toFixed(2)}
45
46Platform: ${os.platform()} ${os.arch()}
47CPUs: ${os.cpus().length}`;
48
49 return {
50 content: [
51 {
52 type: "text" as const,
53 text: statusText,
54 },
55 ],
56 details: {
57 uptime: uptimeSeconds,
58 memory: {
59 total: totalMemory,
60 used: usedMemory,
61 free: freeMemory,
62 usagePercent: parseFloat(memoryUsagePercent),
63 },
64 load: loadAvg,
65 },
66 };
67 },
68};