diff --git a/README.md b/README.md index 2d95f2b..b845dbf 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,9 @@ second instance and the two fight over the device. | Solid green | The turn finished, or you cancelled it. | | Red breathing | The turn failed, or opencode is retrying a failed provider call. | +The Dot has two LEDs, which are too few for the comet. On the Dot, the two LEDs pulse cyan +one after the other. The other states look the same on both devices. + A cancelled turn deliberately looks the same as a finished one. The device is there to tell you things you cannot see. You already know that you cancelled it. diff --git a/package.json b/package.json index aecf7ca..bbdecce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "opencode-sidepulse", - "version": "0.4.0", + "version": "0.4.1", "description": "Show opencode agent status on a SidePulse Pro or SidePulse Dot LED device.", "keywords": [ "opencode", diff --git a/plugin.mjs b/plugin.mjs index f04e6a3..4f363ec 100644 --- a/plugin.mjs +++ b/plugin.mjs @@ -2,7 +2,7 @@ import { spawn, spawnSync } from "node:child_process" import { randomUUID } from "node:crypto" import { existsSync, readdirSync, utimesSync, writeFileSync } from "node:fs" import { homedir } from "node:os" -import { join } from "node:path" +import { basename, join } from "node:path" // Two ways to drive a SidePulse device, picked per event: // @@ -35,6 +35,12 @@ const PROGRAMS = { done: "#00ff22 0.6s cosine\n", } +// The Dot has two LEDs, so the comet above shows only a slice of itself and flickers. +// This pulses both LEDs with an offset, like upstream's cyan-roll-2.LED. +const DOT_PROGRAMS = { + busy: "off\n0:#00ccff 760ms pulse 0ms; 1:#00ccff 760ms pulse 260ms\nrepeat\n", +} + // Volume names differ by model (SidePulse, SidePulsePro, PulseDot), so match the prefix // and confirm the control file exists. The Dot is FAT12, and its 11-character label limit // rules out "SidePulseDot". @@ -68,8 +74,10 @@ function configure(options) { shown = undefined } -function program(state) { - return brightness === undefined ? PROGRAMS[state] : `brightness ${brightness}\n${PROGRAMS[state]}` +function program(state, dir) { + const dot = /^pulsedot/i.test(basename(dir)) + const base = (dot && DOT_PROGRAMS[state]) || PROGRAMS[state] + return brightness === undefined ? base : `brightness ${brightness}\n${base}` } let shown @@ -82,7 +90,7 @@ function write(state) { return false } try { - writeFileSync(join(dir, "LEDS.LED"), program(state)) + writeFileSync(join(dir, "LEDS.LED"), program(state, dir)) shown = state return true } catch { @@ -453,7 +461,8 @@ export default plugin const selfCheck = import.meta.main || process.argv[1]?.endsWith("plugin.mjs") if (selfCheck) { - for (const [name, plain] of Object.entries(PROGRAMS)) { + const all = [...Object.entries(PROGRAMS), ...Object.entries(DOT_PROGRAMS).map(([k, v]) => [`dot ${k}`, v])] + for (const [name, plain] of all) { const program = `brightness 255\n${plain}` const bytes = Buffer.byteLength(program) const lines = program.trimEnd().split("\n").length diff --git a/test/run.mjs b/test/run.mjs index 6013e15..b7bf901 100644 --- a/test/run.mjs +++ b/test/run.mjs @@ -23,6 +23,7 @@ const DRIVER = join(here, "driver.mjs") // twice, once in the plugin and once here. const LED = { busy: "off\n0:#00ccff 1:#0088cc 2:#004466 3:#001a26\nroll 1.2s linear\nrepeat\n", + dotBusy: "off\n0:#00ccff 760ms pulse 0ms; 1:#00ccff 760ms pulse 260ms\nrepeat\n", waiting: "off\n#ffb000 1.4s pulse\nrepeat\n", error: "off\n#ff2000 0.9s pulse\nrepeat\n", done: "#00ff22 0.6s cosine\n", @@ -545,14 +546,23 @@ test("direct mode: a device that appears later is painted on the next event", { led: "busy", }) -for (const volume of ["SidePulsePro", "PulseDot", "sidepulse lower"]) +for (const [volume, busy] of [["SidePulsePro", "busy"], ["PulseDot", "dotBusy"], ["sidepulse lower", "busy"]]) test(`direct mode: the volume ${volume} is a device`, { service: "none", volume, steps: [["prompt", A]], - led: "busy", + led: busy, }) +test("direct mode: the Dot gets its own busy program, and the shared ones otherwise", { + service: "none", + volume: "PulseDot", + options: { brightness: 40 }, + steps: [["prompt", A], ["led"], asked(A), ["led"]], + leds: [`brightness 40\n${LED.dotBusy}`, `brightness 40\n${LED.waiting}`], + led: `brightness 40\n${LED.waiting}`, +}) + for (const volume of ["Macintosh HD", "My SidePulse"]) test(`direct mode: the volume ${volume} is not a device`, { service: "none",