feat: add on-demand OpenCode system monitor

Add a Desktop dashboard and text status command for disk space, RAM, CPU and Intel integrated graphics. Include visibility-driven sampling, tests, development tooling, and installation documentation.
This commit is contained in:
David Meincke
2026-11-20 13:35:00 +01:00
commit 7ab4e9fd0b
26 changed files with 6862 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
import assert from "node:assert/strict"
import { execFileSync } from "node:child_process"
const cli = process.argv[2]
if (!cli) throw new Error("Pass the OpenCode CLI executable path")
function api(method, route, body) {
const args = ["api", method, route]
if (body !== undefined) args.push("--data", JSON.stringify(body))
const result = execFileSync(cli, args, { encoding: "utf8", windowsHide: true, timeout: 20000 })
return result.trim() ? JSON.parse(result) : undefined
}
const plugins = api("get", "/api/plugin").data
const plugin = plugins.find(item => item.id === "local-system-monitor")
assert.equal(plugin?.state.status, "active")
assert.equal(plugin.features.gui, true)
assert.equal(plugin.features.rpc, true)
const snapshot = api("post", "/api/rpc/local-system-monitor/snapshot", { input: {} }).output
assert.match(snapshot.gpu.adapter.name, /Intel/)
assert.equal(snapshot.gpu.error, null)
assert.ok(snapshot.disks.items.length > 0)
console.log("Installed plugin, GUI feature, RPC, and Intel-only readings: passed")
let sessionID
try {
const result = api("post", "/api/session", { title: "System Monitor self-test" })
sessionID = (result.data ?? result).id
assert.ok(sessionID)
api("post", `/api/session/${sessionID}/command`, { name: "system_status", text: "" })
const inbox = api("get", `/api/session/${sessionID}/inbox`)
const text = JSON.stringify(inbox)
assert.match(text, /local-system-monitor.report/)
assert.match(text, /Integrated GPU/)
const messages = api("get", `/api/session/${sessionID}/message`)
assert.doesNotMatch(JSON.stringify(messages), /"type":"assistant"/)
console.log("/system_status posts a report without starting a model turn: passed")
} finally {
if (sessionID) api("delete", `/api/session/${sessionID}`)
}
+27
View File
@@ -0,0 +1,27 @@
// Development-only live visual test. Never loaded by the installed plugin.
import { createServer } from "vite"
import solid from "vite-plugin-solid"
import { monitor } from "../dist/metrics.js"
const server = await createServer({
configFile: false,
plugins: [solid(), {
name: "local-monitor-preview",
configureServer(server) {
server.middlewares.use("/__metrics", async (_request, response) => {
try {
response.setHeader("Content-Type", "application/json")
response.setHeader("Cache-Control", "no-store")
response.end(JSON.stringify(await monitor.snapshot()))
} catch {
response.statusCode = 503
response.end('{"error":"Collection failed"}')
}
})
},
}],
server: { host: "127.0.0.1", port: 5098, strictPort: true },
})
await server.listen()
console.log("System Monitor live preview: http://127.0.0.1:5098/preview.html")
for (const signal of ["SIGINT", "SIGTERM"]) process.on(signal, async () => { await server.close(); process.exit(0) })
+14
View File
@@ -0,0 +1,14 @@
import assert from "node:assert/strict"
import { monitor } from "../dist/metrics.js"
import { report } from "../dist/format.js"
const snapshot = await monitor.snapshot()
console.log(report(snapshot))
assert.ok(snapshot.cpu.percent !== null && snapshot.cpu.percent >= 0 && snapshot.cpu.percent <= 100)
assert.ok(snapshot.ram.total > 0 && snapshot.ram.used <= snapshot.ram.total)
assert.ok(snapshot.disks.items.length > 0, snapshot.disks.error ?? "No disks")
assert.equal(snapshot.gpu.error, null)
assert.match(snapshot.gpu.adapter.name, /intel/i)
assert.ok(snapshot.gpu.adapter.percent !== null)
assert.ok(snapshot.gpu.adapter.sharedUsed !== null)
console.log("\nLive disk, CPU, RAM, and Intel GPU checks passed.")