wingmirror Download
Docs Writing a widget

Docs · Guides

Writing a widget

A widget is a folder with two files, manifest.json and index.html. It runs on the panel in a sandboxed frame, gets its data from the panel through a small SDK, and is placed and resized in the layout editor. This page is everything needed to write one.

Start

swift run Wingmirror widget new build-status "Build Status"

This creates ~/Library/Application Support/Wingmirror/widgets/build-status/ with a working widget. Within a couple of seconds it is listed under Widgets in the settings area (the four-squares button on the panel). Every time you save a file in the folder, the panel reloads it.

swift run Wingmirror widget validate ~/Library/Application\ Support/Wingmirror/widgets/build-status
swift run Wingmirror widget pack     ~/Library/Application\ Support/Wingmirror/widgets/build-status

validate lists what is wrong. A widget with errors is not shown on the panel. pack zips a valid widget as build-status.wmwidget; to install one, unzip it into the widgets folder.

The panel

  • 2560 × 720 pixels, about 37 cm wide and 10 cm high, viewed from arm's length and usually from above. It is not a high-density screen: thin strokes and small type look soft.
  • Widgets sit on a grid of 12 columns by 4 rows. A widget that is c columns by r rows is 204c + 8(c − 1) pixels wide and 144r + 8(r − 1) high: 2 × 2 is 416 × 296, 4 × 2 is 840 × 296, 4 × 4 is 840 × 600, 12 × 4 is 2536 × 600. The panel itself places widgets to the half cell (its grid is 24 by 8), which matters only to a widget that gives min_size: it can then be any size from that up, and size.width and size.height are what to lay out from.
  • The bottom 96 pixels belong to the rail and are not available.
  • Input is one finger. There is no hover, no right click, no keyboard and no scrolling.

manifest.json

{
  "id": "build-status",
  "name": "Build Status",
  "version": "0.1.0",
  "sizes": [[2, 2], [4, 2]],
  "data": ["sessions"],
  "actions": [],
  "network": [],
  "settings": [
    { "key": "title", "type": "text", "label": "Title", "default": "Build Status" }
  ]
}
FieldMeaning
idMust equal the folder name: lower-case letters, digits and hyphens, up to 40 characters. A built-in widget's id cannot be reused.
nameShown in the layout editor.
descriptionOptional. One short line, about thirty characters, saying what the widget shows. It is under the name in the list of widgets to add and at the top of the widget's panel. Without it the list says "A widget of your own".
sizesEvery [columns, rows] the widget can be drawn at, 1 to 12 by 1 to 4. The editor offers them as the widget's Size buttons. List only sizes you have looked at.
min_sizeOptional. The least [columns, rows] the widget needs at the large type size, in the same cells; halves are allowed, as in [1.5, 1]. With it the owner can pull the widget to any size from there up (max_size sets a ceiling), to the half cell, and to proportionally less under a finer type setting. Give it only if the widget lays itself out from size.width and size.height.
dataThe topics the widget may subscribe to. Subscribing to one that is not listed does nothing.
actionsThe actions the widget may ask for. Asking for one that is not listed is refused.
networkHost names the widget may connect to over HTTPS, for example ["api.example.com"]. Empty means no network at all, which is what most widgets should have.
settingsControls shown in the widget's panel in the editor. Types: toggle, select (with options), slider (with min, max, step), colour, text. Each needs a key and should have a default. A setting may also have a description: one line, about sixty characters, shown under it in the widget's panel. Give one to any switch that changes what a single tap can do, saying what the tap then does, as in { "key": "quick", "type": "toggle", "label": "Approve from the card", "description": "One tap approves a change without opening it", "default": false }. A switch with a description takes the whole width of the panel; any other setting has the line under its row. On the panel a text setting opens the editor's own keyboard (unaccented letters, digits and a few marks, up to 60 characters), and a colour is chosen from swatches (your default first, then the accent colours) or a hue slider; either way the widget receives a colour as #rrggbb.

index.html

Load the panel's stylesheet and the SDK from the panel, and keep everything else inside the folder:

<link rel="stylesheet" href="/web/tokens.css">
<script src="/web/sdk/wm.js"></script>

The page is served with a security policy: scripts, styles, images and fonts load only from the panel itself (so from your widget's own folder, or /web/), and the network is closed except for the hosts in network. A <script src="https://…"> will not load. Put libraries in the folder.

The frame is sandboxed with scripts only. There are no forms, pop-ups, top-level navigation, cookies or local storage, and the widget cannot see the panel's page or call the bus. Anything it needs comes through wm.

The SDK

const { size, settings, theme } = await wm.ready();
  • size is { cols, rows, width, height }. cols and rows count in the cells sizes uses and can be halves, since the panel places widgets on a grid twice as fine (24 by 8). Lay out from width and height.
  • settings holds the manifest's defaults overlaid with what the owner chose.
  • theme holds the token values, for the rare case where CSS variables will not do (drawing on a canvas). It also has theme.id, the theme the owner chose (classic, midnight or guildhall), theme.effects, which is true while the owner's short effects are on and the Mac is not set to reduce motion, and theme.wording, which is true while a theme with words of its own for states and labels is to use them.

The owner's look reaches a widget without any work from it. The accent and, with cards, the surface colours arrive as the same custom properties tokens.css defines, so use var(--wm-accent) and the rest and never a colour of your own for them. With a finer type setting the whole widget is drawn smaller in the same frame: size.width and size.height are then larger than the frame's real pixels, which is the room you have to lay out in, and anything with the wm-button class is scaled back up so it stays full size under a finger.

Effects

When the owner answers a request, and when one arrives, the built-in widgets play a short effect. The part over the card is drawn by the SDK inside the widget's own frame; the part that crosses the panel is drawn by the panel, since a widget cannot draw outside its frame.

  • wm.lively() is true while effects are on (theme.effects) and the Mac is not set to reduce motion.
  • wm.spot(element) gives { x, y, w, h }: where an element is in the frame, in pixels on the glass whatever the type size.
  • wm.effect(kind, spot, more) plays one over a card. kind is granted, refused, answered, arrival or finish; more may have button (the spot of the button pressed), others (spots of the buttons that were not), and label (a word for the seal, the slash or the banner, which only Guildhall shows). It does nothing when wm.lively() is false. The layer it draws in takes no touches and is no part of your layout, so the card may be redrawn underneath. What each kind looks like is in tokens.css.

Any widget may use these three: they draw only inside its own frame. wm.effect also takes more.style and more.soft for an arrival, as the panel gives them back. The panel-wide part is not open to widgets you write. The built-in widgets send the card's spot as from with resolve_pending and answer_pending, and the panel plays its part only when the bus has taken the answer; from is ignored from any other widget.

A session starting to need the owner is noticed by the panel itself, from what the bus says, so it is said once whichever page is on show. The panel then asks the built-in widgets on the page where that session's card is, with a message that reaches wm.onEffect(fn) as { kind: "arrival", session }. A widget that has the card answers with play_effect and { kind: "arrival", rect, session }, which resolves with { played, style, soft }: the way the owner chose (quiet, sweep, beacon, ping or banner) and whether it is the gentler reminder, for the widget to pass to wm.effect. play_effect is refused to any other widget, and does nothing unless the panel has just asked about that session. If no widget answers within a quarter of a second the panel points at the bar's count instead. The panel checks that a spot is four numbers, keeps it inside the frame it came from, plays no more than four effects at once, and plays none with effects off, over the lock, the ambient page or the settings area. The banner's words go to the bar alone, as { kind: "banner", who, what }: a project's name and the kind of thing wanted.

An effect is decoration. Send the action first and never wait on an effect; play it only once the action has resolved.

Notes for the log

The owner can switch on diagnostics in the app's menu, and the app then records what each touch and tap came to in its log. While they are on, a widget can add a line of its own:

wm.note("sync", "fell back to the cache");
if (wm.noting()) wm.note("draw", `${rows.length} rows in ${Math.round(took)} ms`);
  • wm.note(kind, text) writes diag widget <your widget's id>: <kind>: <text>. kind is a word of up to 24 characters for what the line is about; the whole line is cut to 120 characters and kept to one line.
  • It does nothing at all while diagnostics are off, which is nearly always. wm.noting() says whether they are on; ask it before building a line that takes work to build.
  • A widget gets five lines in any ten seconds; the rest are dropped. It is for the odd thing worth knowing afterwards, not for a running commentary.
  • The log is the owner's, and they may pass its report on. Never put in a note anything from a request, a command, a path, or anything the owner typed. The report counts a widget's notes and does not quote them.
  • A widget's notes are always marked as its own. It cannot write a line about a touch or a tap, or one that looks like the app's.

Themes

The SDK also sets two attributes on the widget's root element, <html>: data-surface (flat or cards) and data-theme, the theme's id. Most themes are colours and typefaces only and need nothing from a widget. Guildhall goes further, and tokens.css carries its shared pieces under [data-theme="guildhall"]:

  • With cards, the widget gets a leather ground and a gold frame drawn over its edge. The frame takes no room and no touches, but its corner plates cover about 14 px of each corner on the glass, so keep lettering out of the very corners. A widget laid out with the usual 20 px or more of padding needs nothing.
  • .wm-button and .wm-label take the theme's form. Those rules weigh no more than the plain ones, so your own rules for the same classes still win.
  • Custom properties for anything of your own: --gh-frame and --gh-frame-bright (frames, for border-image with a slice of 30), --gh-grain and --gh-leather (grounds), --gh-trough, --gh-trough-rim, --gh-ticks and the --gh-fill-… gradients (bars), --gh-rule and --gh-rule-down (gold rules), --gh-plate and --gh-plate-ground (a title on a plate), and --gh-px, one pixel on the glass at any type size.
/* A bar of your own, under Guildhall only. */
[data-theme="guildhall"] .bar { background: var(--gh-trough); box-shadow: var(--gh-trough-rim); }
[data-theme="guildhall"] .bar div { background: var(--gh-fill-gold); }

Keep such rules together and under the attribute, so the other themes are untouched. If the widget has words of its own for states, change them only when theme.wording is true, keep them in one small table, and leave alone anything the owner acts on: the names of actions, commands, figures.

wm.subscribe("sessions", (sessions) => { … });   // called with the current value at once, then on every change
await wm.action("show_page", { index: 1 });      // resolves with the result, rejects with an Error

A widget is loaded afresh when the owner changes its size or a setting, so wm.ready() always has the current ones; wm.onResize and wm.onSettings exist but are not called today.

sessions arrives every few seconds whether or not anything you show has changed, because each session keeps reporting in. If the widget has buttons, redraw only when what you draw from is different: replacing a button between a finger going down and coming up loses the tap.

Covered and shown

The panel tells a widget whether its frame can be seen, so that whatever moves by itself in it can rest while it cannot:

await wm.ready();
if (wm.seen()) loop.start();
wm.onSeen((seen) => { if (seen) loop.start(); else loop.stop(); });
  • wm.seen() is how things stand now. Ask it once wm.ready() has resolved: a widget can be made already covered, as every widget is while the panel opens behind its mark.
  • wm.onSeen(fn) is called with false when the widget is covered and with true when it is on show again, and only when the answer changes.

A widget on a page, and the bar, are not seen while the ambient page is up, while the panel is blanked or the Mac is locked, while the panel is still opening, while the panel's page itself is hidden, and in the settings area, except on its Look screen, which shows the page and the bar themselves. A widget on the ambient page is seen while that page is up, and so is one in the settings area's picture of it under Display. A widget on a page that is left is not told anything: its frame is taken down, and made again when the page is next shown.

Stop a timer or a frame loop of your own on false, and on true start it again and bring up to date whatever it would have changed meanwhile. Topics go on arriving while a widget is covered, so one that only draws when a topic arrives has nothing to do. The Agents widget rests the picture in its empty space this way, and the Ambient widget its backdrop and its clock.

The shared backdrop

The slow pictures behind the ambient page (Drift, Flow and Stars) are in a file of their own, so a widget can have one behind an empty area of its own. Load it after the SDK and give it somewhere to draw:

<div id="quiet"></div>
<script src="/web/sdk/wm.js"></script>
<script src="/web/sdk/backdrop.js"></script>
const { theme } = await wm.ready();
const backdrop = wmBackdrop(document.getElementById("quiet"), "stars", theme, { intensity: 0.5 });
wm.subscribe("sessions", (sessions) => backdrop.update({ sessions }));

wmBackdrop(target, style, theme, options):

  • target is an element, which is given a canvas that fills it; the element must be positioned (position: relative or absolute). Keep that element for the backdrop alone and lay what goes over it in a positioned element after it. It can also be a canvas of your own, sized with CSS: do not set its width and height attributes, the backdrop does.
  • style is "drift", "flow" or "stars". Under Guildhall, Drift is drawn as embers rising from a hearth, as on the ambient page. Nothing is asked of you for that.
  • theme is the one from wm.ready(). The accent, the theme's id and the type scale are read from it.
  • options are all optional: sessions (the sessions topic's value, or a list of ids; Drift has one light for each, and five of its own with none), intensity (0 to 1, how bright; 1 if left out), still (true for one frame and no movement) and ground (false for the lights alone on a canvas that is otherwise clear; read once, when the backdrop is made).

It draws at once and gives back a handle:

CallWhat it does
update(options)Takes the same options and changes only the ones given. Passing sessions every time the topic arrives is fine: nothing is rebuilt.
stop()Ends the frame loop and leaves the last frame up.
start()Sets it moving again.
destroy()Stops it for good, lets go of its listeners, and removes a canvas it made.

What it looks after itself:

  • Size. It draws at the size the canvas really is, follows it when that changes, and counts in pixels on the glass under any type setting. On a screen with finer pixels a small canvas is drawn finer, but never with more pixels than the whole panel has. How many stars, lines and sparks there are goes by area, so a 4 × 4 widget shows a piece of what the whole panel would show, not all of it squeezed in. Drift, on anything smaller than the whole panel, has its share of the lights by area and never fewer than one.
  • Rest. Nothing is drawn while the panel's page is hidden, and where the Mac is set to reduce motion there is one still frame. Call stop() yourself while the area the backdrop is in is covered or empty of it, and while wm.seen() is false: the backdrop does not know what the panel has put over the widget.
  • Colour. The ground is black and the light is the accent and a few fixed greys, as on the ambient page. Where the page shows through your widget (a Dusk or Glow background, or a theme's own, with widgets flat), a black ground would be a slab over it: pass ground: false there and the lights are drawn over whatever is behind. The Agents widget does this for its empty space. Draw your own content over it with the tokens as usual, and use intensity to keep it behind what matters: about 0.5 under text.

It is decoration. Twenty frames a second on a canvas the size of the whole panel is what the ambient page costs, so keep one to a widget.

On the ambient page

The owner can place any widget on the ambient page, the one the panel shows when nothing is going on, over its backdrop. A widget there is drawn at the same sizes as on a page and gets its topics as usual, with two differences:

  • It is for looking at. A touch anywhere on that page sends the page away, so nothing in the widget can be pressed, and every wm.action is refused with not_allowed while the widget is there, whatever the manifest lists and whatever has been granted. Draw so that the widget reads well with nothing to press.
  • It may be up for hours. With widgets flat on the page its ground is see-through, so the backdrop shows behind it; with cards it has its card. Keep large bright areas that never change out of it, for the panel's sake.

The theme from wm.ready() carries ambient: true there and no such key on a numbered page. Most widgets have no use for it. One that draws a backdrop of its own should leave it out there, as the Agents widget does where its ground is see-through: the page already has one behind everything.

Topics

TopicValue
sessionsA list of agent sessions. Each has id, agent (claude, codex, or any other name), project, cwd, model, state (running, waiting_permission, needs_input, idle, completed), state_since, last_active (when an idle or completed session last worked, or null: null while it works, and for one only ever heard from at rest), stale, context_pct, last_tool ({tool, summary} or null), recent_tools (the last eight lines of what the session did, oldest first: a tool it finished is {kind: "tool", tool, summary, at}, and what the owner decided on the panel is {kind: "decision", outcome, tool, summary, answer, at}, where outcome is approved, denied or answered and answer is the choice tapped for a question, otherwise null), pending_action ({id, tool, summary, truncated, created_at, expires_at, lapses_at} or null; lapses_at is as under pending), started_at, updated_at.
pendingA list of requests waiting for a decision: id, session_id, agent_id, tool, summary, truncated, advisory, choices, created_at, expires_at, lapses_at. lapses_at is when the hold on the request runs out and it can no longer be answered here, for counting down to; it is null for an advisory request, whose agent is not held to any time.
usage{ raw, tokens }. raw.rate_limits has five_hour and seven_day, each { used_percentage, resets_at } (resets_at in Unix seconds). tokens is { day, estimate, agents: { claude: { input, output, cache_read, cache_creation, messages } } }. Either may be null.
activityA list of { id, project, agent, segments }, where each segment is { state, from, to } and to is null for the one still open. Kept for a day after a session ends.
display{ brightness, contrast, sharpness, preset, power, max, presets }, or null if the panel cannot be reached. power is on, blank or standby.
clock{ now }, once a second. Use it to redraw anything that shows elapsed time.
pages{ pages: [{ id, name, widgets }], current }. widgets is the ids of the widgets on that page, in the order they were placed, one for each time a widget is there; current is the place in the list of the page on show.
status{ online, offline_since }: whether the panel can reach the app on the Mac, and, while it cannot, the time it stopped answering (otherwise null). While online is false every other topic holds what it last had, so a figure drawn from them is as old as offline_since.
cardsNotes agents have put on the panel, newest first: [{ id, agent, session_id, title, text, progress, created_at, updated_at, expires_at }].
connectionsWhat is known of each agent's connection: { claude, codex, copilot, cursor, other }, each { installed, seen }. installed is true when the agent's hooks are all in place, false when they are not, and null when that is not known (always for other, which is any agent that reports without an adapter of its own, and for every agent on a run that was not told). seen is true once anything has been heard from the agent since the app started, and stays true after its sessions have gone. Two separate facts: hooks in place with nothing seen may only mean no session has been opened yet.
hiddenThe sessions whose cards the owner has hidden and that are still away, oldest first: [{ id, agent, project }]. Empty when none are.
tallyThe last fourteen days, counted: { days: [{ day, held, outcomes, panel, elsewhere, sessions }] }, oldest first, ending with today, and with a record for a day on which nothing happened. day is the local day as YYYY-MM-DD. held is how many requests were held for the owner. outcomes is { approved, denied, answered, answered_elsewhere, lapsed }, counts of how they ended: the first three on the panel, answered_elsewhere at the keyboard or by the agent moving on while the request was still held, lapsed when the hold ran out unanswered. They can add up to less than held: a request still open, or one that ended with its session, is in none. panel and elsewhere are each { count, total_seconds, median_seconds }, the time from a request being held to its being answered on the panel or elsewhere; the median is null when there were none, and for elsewhere the time is until the app learned of the answer, less the time the tool ran where Claude Code reports it, so at most what it took. sessions is { total, by_agent }, the different sessions heard from that day and the same by agent name. Sent again when any figure changes and when the day does.
systemThe Mac's own figures, every two seconds while a widget that lists the topic is on a page: { cpu, cores, load, memory: { used_gb, total_gb, pressure, level }, disk: { free_gb, total_gb }, battery: { percent, charging, on_battery } or null, thermal, uptime_s, history: { cpu, memory } }. Null until the first reading.
git{ repos: [{ folder, name, branch, ahead, behind, staged, unstaged, untracked, last: { subject, at }, pr }] } for the folders the open Claude Code sessions are working in, every ten seconds while a widget lists the topic. pr ({ number, title, state, draft, checks: { passing, failing, pending } }) is null unless the owner has switched pull requests on in the menu.
gridThe owner's actions for the action grid: { actions: [{ id, label, icon, colour, confirm, kind }], problem, running, last: { id, ok, message, at } }. Never the commands themselves.

A request's whole text (pending_action.detail, which can be an entire file) is given only to the built-in widgets; yours gets the summary.

Times are ISO 8601 strings unless noted. Any field can be null; write for that.

Actions

ActionParametersNotes
show_page{ index }Switches the panel to another page.
edit_layoutnoneOpens the layout editor.
show_ambientnoneShows the ambient page until a touch or an agent sends it away.
remember{ value }Keeps a small value (up to 4,000 characters as JSON) with this widget's place in the layout. It comes back as settings.remembered the next time the widget is drawn. Refused for a widget that is not on a page, and while the layout editor is open.
answer_pending{ id, index }Guarded. Answers an agent's question with one of the choices it came with.
dismiss_card{ id }Takes one of the agents' notes off the panel.
hide_session{ session_id }Guarded. Takes a session's card off the panel until the session next changes state or asks for something. Refused while the session has a request open.
show_hidden{ session_id }, or nothingBrings back a card that hide_session took away, or every such card when no session is named. Resolves with { shown }, how many came back.
end_session{ session_id }Guarded. Stops a Claude Code session's own process. Refused for other agents, while a request is open, and when the process cannot be found for certain.
run_action{ id }Guarded. Runs one of the owner's own actions by its id. A widget can only choose among the actions the owner defined in actions.json; it cannot define one or pass a command.
resolve_pending{ id, behavior }, behavior is allow or denyGuarded. Answers an agent's request on the owner's behalf.
play_effect{ kind, rect, session }Built-in widgets only, and not in the list widget validate accepts. Asks the panel for the part of an effect that crosses the whole panel; see Effects.
open_terminal{ session_id }Guarded.
set_display{ brightness } and/or { power }Guarded.

Guarded actions reach outside the panel. Listing one in the manifest is a request. It does nothing until the owner allows it for that widget under Widget Permissions in the menubar, and the permission is withdrawn automatically whenever any file in the widget's folder changes. Do not ask for one unless the widget is for answering requests, and never offer Approve for a request the widget is not showing in full: check truncated, and check that the text fits.

Looking right

Use the tokens. Nothing in a widget should name a colour, a font or a base size of its own.

TokenUse
--wm-bgBackground, and text on the accent
--wm-surfaceA raised or selected area
--wm-trackThe empty part of a meter
--wm-lineDividers and quiet borders
--wm-borderThe outline of a secondary button
--wm-dimTertiary text
--wm-mutedLabels and secondary text
--wm-fgPrimary text and meters
--wm-accentNeeds you. Nothing else.
--wm-font-text, --wm-font-label, --wm-font-monoText, upper-case labels, numbers and code

Shared classes: wm-label (an upper-case label), wm-mono (tabular numbers), wm-button (a 112 px button; add primary for the filled one).

Rules that keep a widget readable on this panel:

  1. One thing, large. A widget answers one question. The answer is the biggest thing in it.
  2. Nothing under 22 px, and labels at 24 to 26 px. Numbers that matter are 40 px and up.
  3. The accent means "needs you". A calm panel has no colour on it at all. Do not use the accent for decoration, branding or emphasis.
  4. Every control is at least 96 px in both directions as written, with at least 10 px between controls. A wm-button is drawn smaller under the finer looks, down to 64 px on the glass and no further.
  5. Tabular numbers wherever a number can change, so nothing shifts as it counts.
  6. No scrolling and no overflow. Decide what to drop when there is too much: cut the list and say how many more there are.
  7. Design every size you list. A widget at 2 × 2 is not the 4 × 4 one shrunk.
  8. Draw from the data, not from a timer. Redraw when a topic changes; use clock only for elapsed time.
  9. Whole pixels. Avoid transforms and fractional sizes on text; they blur on this panel.

Example: a count

How many agents are waiting for you, as one number. No actions, no network.

manifest.json

{
  "id": "waiting-count",
  "name": "Waiting",
  "version": "1.0.0",
  "sizes": [[2, 2], [2, 4]],
  "data": ["sessions"],
  "actions": [],
  "network": [],
  "settings": []
}

index.html

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Waiting</title>
<link rel="stylesheet" href="/web/tokens.css">
<style>
  #root { position: absolute; inset: 0; box-sizing: border-box; border: 1px solid var(--wm-line); border-radius: var(--wm-radius);
          padding: 20px 24px; display: flex; flex-direction: column; justify-content: space-between; }
  #root.asking { border: 2px solid var(--wm-accent); }
  #count { font-size: 150px; font-weight: 500; line-height: 1; }
  .asking #count, .asking .wm-label { color: var(--wm-accent); }
</style>
</head>
<body>
<div id="root">
  <span class="wm-label">Waiting for you</span>
  <span id="count" class="wm-mono">0</span>
</div>
<script src="/web/sdk/wm.js"></script>
<script>
(async () => {
  await wm.ready();
  wm.subscribe("sessions", (sessions) => {
    const waiting = sessions.filter((s) => s.state === "waiting_permission" || s.state === "needs_input").length;
    document.getElementById("count").textContent = String(waiting);
    document.getElementById("root").classList.toggle("asking", waiting > 0);
  });
})();
</script>
</body>
</html>

What to notice: the border and the number turn amber only when something is waiting, the number is the whole widget, and both listed sizes work because the layout is a label at the top and a number at the bottom.

Example: a setting, a list and an action

The sessions using the most context, with a threshold the owner sets, and a tap that jumps to the Agents page.

manifest.json

{
  "id": "context-watch",
  "name": "Context Watch",
  "version": "1.0.0",
  "sizes": [[3, 2], [3, 4], [4, 4]],
  "data": ["sessions"],
  "actions": ["show_page"],
  "network": [],
  "settings": [
    { "key": "threshold", "type": "slider", "label": "Warn above", "min": 50, "max": 95, "step": 5, "default": 80 }
  ]
}

index.html

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Context Watch</title>
<link rel="stylesheet" href="/web/tokens.css">
<style>
  #root { position: absolute; inset: 0; box-sizing: border-box; border: 1px solid var(--wm-line); border-radius: var(--wm-radius);
          padding: 18px 22px; display: flex; flex-direction: column; gap: 12px; }
  .rows { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; justify-content: space-evenly; }
  .row { display: grid; grid-template-columns: minmax(0, 1fr) 96px; align-items: center; gap: 14px; }
  .name { font-size: 30px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .pct { font-size: 34px; text-align: right; }
  .meter { grid-column: 1 / -1; height: 10px; background: var(--wm-track); }
  .meter div { height: 100%; background: var(--wm-fg); }
  .over .pct { color: var(--wm-accent); }
  .over .meter div { background: var(--wm-accent); }
  button#go { height: 96px; }
</style>
</head>
<body>
<div id="root"></div>
<script src="/web/sdk/wm.js"></script>
<script>
(async () => {
  const root = document.getElementById("root");
  const { size, settings } = await wm.ready();
  let rows = size.rows, threshold = settings.threshold, sessions = [];

  function render() {
    const label = document.createElement("span");
    label.className = "wm-label";
    label.textContent = "Context";
    const list = document.createElement("div");
    list.className = "rows";
    const known = sessions.filter((s) => typeof s.context_pct === "number").sort((a, b) => b.context_pct - a.context_pct);
    // Two fit a two-row widget, four a four-row one, with room left for the button.
    for (const s of known.slice(0, rows >= 4 ? 4 : 1)) {
      const row = document.createElement("div");
      row.className = "row" + (s.context_pct >= threshold ? " over" : "");
      const name = document.createElement("span");
      name.className = "name";
      name.textContent = s.project || s.id;
      const pct = document.createElement("span");
      pct.className = "pct wm-mono";
      pct.textContent = Math.round(s.context_pct) + "%";
      const meter = document.createElement("div");
      meter.className = "meter";
      const fill = document.createElement("div");
      fill.style.width = Math.min(100, s.context_pct) + "%";
      meter.append(fill);
      row.append(name, pct, meter);
      list.append(row);
    }
    const go = document.createElement("button");
    go.id = "go";
    go.type = "button";
    go.className = "wm-button";
    go.textContent = known.length > list.children.length ? `All ${known.length}` : "Agents";
    go.addEventListener("click", () => wm.action("show_page", { index: 0 }).catch(() => {}));
    root.replaceChildren(label, list, go);
  }

  wm.subscribe("sessions", (value) => { sessions = value || []; render(); });
  wm.onSettings((next) => { threshold = next.threshold; render(); });
  wm.onResize((next) => { rows = next.rows; render(); });
})();
</script>
</body>
</html>

What to notice: the row count depends on the size and the button says how many were left out; amber appears only above the owner's threshold; text is set with textContent, never by building HTML from data, because project names come from outside; context_pct can be null and those sessions are skipped; and the action is one that needs no permission.

Checklist

  • Wingmirror widget validate reports no errors.
  • It looks right at every size in sizes, with no sessions, one session, and more sessions than fit.
  • Nothing is smaller than 22 px and every control is at least 96 px as written (64 px on the glass under the finest look).
  • The accent appears only when something needs the owner.
  • No file is loaded from another site, and network lists only what is used.
  • No guarded action unless answering requests is the widget's purpose.
  • Anything that moves by itself (a timer, a frame loop, the shared backdrop) rests while wm.seen() is false and starts again from wm.onSeen.

Edit source on GitHub docs/widget-authoring.md