@standardagents/sc-system-stats-plugin
v0.1.3
Published
CPU, memory, and disk statistics for Standard Code machines
Keywords
Readme
Resource monitor
Public npm package: @standardagents/sc-system-stats-plugin.
standard plugin install @standardagents/sc-system-stats-plugin --accept-capabilities surfacesThe package uses the published Standard Code plugin SDK. Its plugin ID stays
resource-monitor so upgrades retain configuration and account state.
This example draws one line inside its machine's frame in the sidebar: CPU, memory, and disk use, with a sparkline of recent CPU load.
The plugin draws that line itself. It publishes a one-row canvas to a
machine.after slot and writes ANSI to it: icons, a chart for CPU and for
memory on the true 0% to 100% scale, and the disk value. Standard Code puts
the row in the machine card's footer and gives the footer its tint and edges;
render.mjs decides every cell inside. A cell in the default colour shows the
footer's tint.
The canvas also publishes one line of hover metadata. After the host's short
hover delay, it shows the current CPU and memory percentages beside their
rolling one-minute averages. A ~ marks an average based on a partial or
gapped history, and n/a marks a missing current value or history window.
The host owns hover placement and dismissal, so the same detail is available
when a viewer is looking at another machine's card.
The plugin reads every value itself and needs nothing from Standard Code
beyond the SDK. sample.mjs takes a reading every five seconds:
- CPU use is the busy share of processor time between two
os.cpus()readings, summed over every core. The first reading has no interval, so CPU showsunavailablefor the first five seconds. - Memory comes from
vm_staton macOS, whereos.freemem()counts file cache as used. Other platforms useos.totalmem()andos.freemem(). - Disk is the volume that holds the user's home directory, read with
fs.statfs.
A reading outside its valid range shows unavailable instead of a number.
The sparkline keeps two minutes of history. The plugin saves that history
with ctx.state once a minute, under a key that carries the machine id.
Standard Code stores ctx.state in the user's account and shares it across
their machines, so a key per machine keeps one machine from replacing the
history of another. After a restart, samples newer than two minutes return to
the sparkline.
SDK compatibility
Hover requires the public SDK 1.0.0-alpha.5-usage.0 or a compatible later
version, plus a native client that renders canvas hover metadata. The plugin
uses Canvas.replace from that package. Its tests use the public /testing
export. The workspace pins its SDK development dependency to the same published
version used for this feature's native runtime.
The hover uses the owning machine's background tint. CPU and memory labels and
current values are bold. Usage values are green below 60%, amber from 60%, and
red from 85%; one-minute averages use the same thresholds. The plugin publishes
a styled span array in the public hover field.
