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:
@@ -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}`)
|
||||
}
|
||||
Reference in New Issue
Block a user