Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
19 changes: 14 additions & 5 deletions plugin.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
//
Expand Down Expand Up @@ -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".
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions test/run.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
Loading