feat(system-info): include disk usage in health output
This commit is contained in:
@@ -5612,6 +5612,18 @@
|
|||||||
"docs/plans/state.json"
|
"docs/plans/state.json"
|
||||||
],
|
],
|
||||||
"test_status": "pnpm test:run src/gateway/handlers/agent.test.ts + pnpm typecheck passing"
|
"test_status": "pnpm test:run src/gateway/handlers/agent.test.ts + pnpm typecheck passing"
|
||||||
|
},
|
||||||
|
"system-info-disk-usage-reporting": {
|
||||||
|
"status": "completed",
|
||||||
|
"date": "2026-02-19",
|
||||||
|
"updated": "2026-02-19",
|
||||||
|
"summary": "Extended `system.info` tool output to include disk usage metrics (path, total/free/used, and used percentage) so machine health summaries include storage headroom in addition to memory.",
|
||||||
|
"files_modified": [
|
||||||
|
"src/tools/builtin/system-info.ts",
|
||||||
|
"src/tools/builtin/system-info.test.ts",
|
||||||
|
"docs/plans/state.json"
|
||||||
|
],
|
||||||
|
"test_status": "pnpm test:run src/tools/builtin/system-info.test.ts + pnpm typecheck passing"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"overall_progress": {
|
"overall_progress": {
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ describe('system.info tool', () => {
|
|||||||
'Node.js:',
|
'Node.js:',
|
||||||
'Uptime:',
|
'Uptime:',
|
||||||
'Memory Total:',
|
'Memory Total:',
|
||||||
|
'Disk',
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const field of expectedFields) {
|
for (const field of expectedFields) {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import os from 'os';
|
import os from 'os';
|
||||||
|
import { statfsSync } from 'fs';
|
||||||
import type { Tool, ToolResult } from '../types.js';
|
import type { Tool, ToolResult } from '../types.js';
|
||||||
|
|
||||||
function formatUptime(seconds: number): string {
|
function formatUptime(seconds: number): string {
|
||||||
@@ -12,6 +13,34 @@ function formatBytes(bytes: number): string {
|
|||||||
return (bytes / (1024 * 1024 * 1024)).toFixed(2) + ' GB';
|
return (bytes / (1024 * 1024 * 1024)).toFixed(2) + ' GB';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getDiskUsageSummary(): string[] {
|
||||||
|
try {
|
||||||
|
const rootPath = process.platform === 'win32' ? process.cwd().slice(0, 3) : '/';
|
||||||
|
const stat = statfsSync(rootPath);
|
||||||
|
const blockSize = typeof stat.bsize === 'number' ? stat.bsize : Number(stat.bsize);
|
||||||
|
const totalBlocks = typeof stat.blocks === 'number' ? stat.blocks : Number(stat.blocks);
|
||||||
|
const freeBlocks = typeof stat.bavail === 'number' ? stat.bavail : Number(stat.bavail);
|
||||||
|
|
||||||
|
if (!Number.isFinite(blockSize) || !Number.isFinite(totalBlocks) || !Number.isFinite(freeBlocks)) {
|
||||||
|
return ['Disk: unavailable'];
|
||||||
|
}
|
||||||
|
|
||||||
|
const totalBytes = totalBlocks * blockSize;
|
||||||
|
const freeBytes = freeBlocks * blockSize;
|
||||||
|
const usedBytes = Math.max(0, totalBytes - freeBytes);
|
||||||
|
const usedPct = totalBytes > 0 ? (usedBytes / totalBytes) * 100 : 0;
|
||||||
|
|
||||||
|
return [
|
||||||
|
`Disk Path: ${rootPath}`,
|
||||||
|
`Disk Total: ${formatBytes(totalBytes)}`,
|
||||||
|
`Disk Free: ${formatBytes(freeBytes)}`,
|
||||||
|
`Disk Used: ${formatBytes(usedBytes)} (${usedPct.toFixed(1)}%)`,
|
||||||
|
];
|
||||||
|
} catch {
|
||||||
|
return ['Disk: unavailable'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const systemInfoTool: Tool = {
|
export const systemInfoTool: Tool = {
|
||||||
name: 'system.info',
|
name: 'system.info',
|
||||||
description: 'Get current system information including date, time, hostname, OS, platform, architecture, uptime, Node.js version, and memory usage.',
|
description: 'Get current system information including date, time, hostname, OS, platform, architecture, uptime, Node.js version, and memory usage.',
|
||||||
@@ -52,6 +81,7 @@ export const systemInfoTool: Tool = {
|
|||||||
`Node.js: ${process.version}`,
|
`Node.js: ${process.version}`,
|
||||||
`Memory Total: ${formatBytes(totalMem)}`,
|
`Memory Total: ${formatBytes(totalMem)}`,
|
||||||
`Memory Free: ${formatBytes(freeMem)}`,
|
`Memory Free: ${formatBytes(freeMem)}`,
|
||||||
|
...getDiskUsageSummary(),
|
||||||
`Working Dir: ${process.cwd()}`,
|
`Working Dir: ${process.cwd()}`,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user