@sirenodeck/sirenodeck 0.2.5 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.mjs CHANGED
@@ -7,7 +7,7 @@ import { basename, dirname, extname, isAbsolute, join, normalize, resolve, sep }
7
7
  import { Writable } from "node:stream";
8
8
  import { cancel, confirm, intro, isCancel, log, log as log$1, note, outro, select, spinner } from "@clack/prompts";
9
9
  import pino from "pino";
10
- import { chmodSync, closeSync, copyFileSync, cpSync, createWriteStream, existsSync, fchmodSync, fsyncSync, mkdirSync, mkdtempSync, openSync, readFileSync, readSync, readdirSync, readlinkSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
10
+ import { chmodSync, closeSync, copyFileSync, cpSync, createWriteStream, existsSync, fchmodSync, fsyncSync, mkdirSync, mkdtempSync, openSync, readFileSync, readSync, readdirSync, readlinkSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync, writeSync } from "node:fs";
11
11
  import { createHash, randomBytes } from "node:crypto";
12
12
  import { arch, homedir, hostname, networkInterfaces, platform, tmpdir, userInfo } from "node:os";
13
13
  import { getuid, platform as platform$1 } from "node:process";
@@ -328,7 +328,7 @@ const levelNameFromNumber = (level) => {
328
328
  };
329
329
  //#endregion
330
330
  //#region package.json
331
- var version$1 = "0.2.5";
331
+ var version$1 = "0.2.7";
332
332
  //#endregion
333
333
  //#region src/version.ts
334
334
  const PACKAGE_NAME = "@sirenodeck/sirenodeck";
@@ -1066,8 +1066,8 @@ const findConfigPath = (options) => {
1066
1066
  };
1067
1067
  //#endregion
1068
1068
  //#region src/cli/commands/pipeline/helpers.ts
1069
- const resolveXdgConfigHome$1 = (options) => options.xdgConfigHome ?? process.env["XDG_CONFIG_HOME"] ?? `${options.homeDir ?? homedir()}/.config`;
1070
- const resolveXdgConfigPath = (options) => resolve(resolveXdgConfigHome$1(options), XDG_CONFIG_SUBDIR, "config.yml");
1069
+ const resolveXdgConfigHome$2 = (options) => options.xdgConfigHome ?? process.env["XDG_CONFIG_HOME"] ?? `${options.homeDir ?? homedir()}/.config`;
1070
+ const resolveXdgConfigPath = (options) => resolve(resolveXdgConfigHome$2(options), XDG_CONFIG_SUBDIR, "config.yml");
1071
1071
  const resolveRunFolderConfigPath = () => resolve(getOriginalCwd(), "config.yml");
1072
1072
  const resolveConfigPath$1 = (options) => {
1073
1073
  if (options.config !== void 0) {
@@ -61206,7 +61206,6 @@ const pushBlackFrame = async (device, logger) => {
61206
61206
  try {
61207
61207
  const buf = buildBlackBuffer(device.getKeyCount());
61208
61208
  for (let i = 0; i < device.getKeyCount(); i++) await device.fillKeyBuffer(i, buf.subarray(0, 192));
61209
- await device.setBrightness(0);
61210
61209
  await new Promise((r) => setTimeout(r, 200));
61211
61210
  logger.info("black-frame: pushed");
61212
61211
  } catch (err) {
@@ -61806,6 +61805,8 @@ var RealOutputClient = class {
61806
61805
  let frontendSupervisor = null;
61807
61806
  let configUiSupervisor = null;
61808
61807
  try {
61808
+ this.deviceBrightness = opts.runtime.getBrightness();
61809
+ await device.setBrightness(this.deviceBrightness);
61809
61810
  const logoCandidates = [new URL("../assets/logo72x72.png", import.meta.url), new URL("../src/assets/logo72x72.png", import.meta.url)].map((url) => fileURLToPath(url));
61810
61811
  await pushStartupScreen({
61811
61812
  logoPath: logoCandidates.find(existsSync) ?? logoCandidates[0],
@@ -62057,6 +62058,121 @@ const selectOutputClient = (options) => {
62057
62058
  return new RealOutputClient({ xdgConfigHome: options.xdgConfigHome });
62058
62059
  };
62059
62060
  //#endregion
62061
+ //#region src/core/settings.ts
62062
+ const settingsSchema = z.object({
62063
+ brightness: z.number().int().min(10).max(100),
62064
+ activeDeck: z.string().min(1)
62065
+ }).strict();
62066
+ const DEFAULT_SETTINGS = {
62067
+ brightness: 50,
62068
+ activeDeck: "main"
62069
+ };
62070
+ const SETTINGS_DIR = "sirenodeck";
62071
+ const SETTINGS_FILE = "settings.json";
62072
+ const resolveXdgConfigHome$1 = () => process.env["XDG_CONFIG_HOME"] ?? join(homedir(), ".config");
62073
+ const resolveSettingsPath = (xdgConfigHome = resolveXdgConfigHome$1()) => {
62074
+ const dir = join(xdgConfigHome, SETTINGS_DIR);
62075
+ return join(dir, SETTINGS_FILE);
62076
+ };
62077
+ const loadSettings = (path = resolveSettingsPath(), logger) => {
62078
+ if (!existsSync(path)) return DEFAULT_SETTINGS;
62079
+ let raw;
62080
+ try {
62081
+ raw = readFileSync(path, "utf8");
62082
+ } catch (err) {
62083
+ logger?.warn({
62084
+ err,
62085
+ path
62086
+ }, "settings: read failed; using defaults");
62087
+ return DEFAULT_SETTINGS;
62088
+ }
62089
+ let parsed;
62090
+ try {
62091
+ parsed = JSON.parse(raw);
62092
+ } catch (err) {
62093
+ logger?.warn({
62094
+ err,
62095
+ path
62096
+ }, "settings: corrupt JSON; using defaults");
62097
+ return DEFAULT_SETTINGS;
62098
+ }
62099
+ const result = settingsSchema.safeParse(parsed);
62100
+ if (!result.success) {
62101
+ logger?.warn({
62102
+ err: result.error.message,
62103
+ path
62104
+ }, "settings: schema mismatch; using defaults");
62105
+ return DEFAULT_SETTINGS;
62106
+ }
62107
+ return result.data;
62108
+ };
62109
+ const atomicWriteJson = (path, data) => {
62110
+ mkdirSync(dirname(path), { recursive: true });
62111
+ const tmpPath = `${path}.${randomBytes(6).toString("hex")}.tmp`;
62112
+ const fd = openSync(tmpPath, "w", 384);
62113
+ try {
62114
+ writeSync(fd, JSON.stringify(data, null, 2));
62115
+ } finally {
62116
+ closeSync(fd);
62117
+ }
62118
+ renameSync(tmpPath, path);
62119
+ };
62120
+ const DEBOUNCE_MS = 500;
62121
+ const createSettingsStore = ({ path = resolveSettingsPath(), logger, writeJson = atomicWriteJson } = {}) => {
62122
+ let current = loadSettings(path, logger);
62123
+ let timer = null;
62124
+ let pending = false;
62125
+ const writeNow = () => {
62126
+ try {
62127
+ writeJson(path, current);
62128
+ } catch (err) {
62129
+ logger?.warn({
62130
+ err,
62131
+ path
62132
+ }, "settings: write failed");
62133
+ }
62134
+ };
62135
+ const schedule = () => {
62136
+ pending = true;
62137
+ if (timer !== null) return;
62138
+ timer = setTimeout(() => {
62139
+ timer = null;
62140
+ if (pending) {
62141
+ pending = false;
62142
+ writeNow();
62143
+ }
62144
+ }, DEBOUNCE_MS);
62145
+ };
62146
+ return {
62147
+ get: () => ({ ...current }),
62148
+ update: (partial) => {
62149
+ current = {
62150
+ ...current,
62151
+ ...partial
62152
+ };
62153
+ schedule();
62154
+ },
62155
+ flush: () => {
62156
+ if (timer !== null) {
62157
+ clearTimeout(timer);
62158
+ timer = null;
62159
+ }
62160
+ pending = false;
62161
+ writeNow();
62162
+ },
62163
+ close: () => {
62164
+ if (timer !== null) {
62165
+ clearTimeout(timer);
62166
+ timer = null;
62167
+ }
62168
+ if (pending) {
62169
+ pending = false;
62170
+ writeNow();
62171
+ }
62172
+ }
62173
+ };
62174
+ };
62175
+ //#endregion
62060
62176
  //#region src/cli/commands/addon-decks.ts
62061
62177
  const resolveTriggerProcessNames = (trigger) => {
62062
62178
  if (typeof trigger !== "object" || trigger === null) return void 0;
@@ -62702,7 +62818,7 @@ const buildRuntime = (options, loaded, keyCount, lockActive = false) => {
62702
62818
  const allDecsWithSystemButtons = injectSystemButtons(sourceDecks, keyCount, { lockActive });
62703
62819
  const { decks: allDecks, errorsByDeck } = applyConfigErrorReplacements(allDecsWithSystemButtons, config, registry, logger);
62704
62820
  const token = process.env["SIRENO_TOKEN"] ?? "";
62705
- const configUiUrl = new URL(`http://127.0.0.1:${DEFAULT_CONFIG_UI_PORT}/`);
62821
+ const configUiUrl = new URL(options.configUiUrl ?? `http://127.0.0.1:${DEFAULT_CONFIG_UI_PORT}/`);
62706
62822
  if (token.length > 0) configUiUrl.searchParams.set("token", token);
62707
62823
  configUiUrl.hash = "/config";
62708
62824
  const runtimeDecks = injectConfigUiButton(allDecks, configUiUrl.toString());
@@ -63055,7 +63171,7 @@ const buildExternalAddonDirs = (addonEntries, configPath, addonEntryPaths = /* @
63055
63171
  };
63056
63172
  const runPipeline = async (options) => {
63057
63173
  const { logger } = options;
63058
- const xdgConfigHome = resolveXdgConfigHome$1(options);
63174
+ const xdgConfigHome = resolveXdgConfigHome$2(options);
63059
63175
  let loadedConfig = null;
63060
63176
  let outputClient = null;
63061
63177
  let providers = null;
@@ -63077,6 +63193,8 @@ const runPipeline = async (options) => {
63077
63193
  let configWatcher = null;
63078
63194
  let outputHandle = null;
63079
63195
  let currentOutputHandle = null;
63196
+ let settingsStore = null;
63197
+ let unsubscribeBrightnessSettings = null;
63080
63198
  let unregisterSignal = null;
63081
63199
  let unregisterReload = null;
63082
63200
  let unsubscribeLockMode = null;
@@ -63090,6 +63208,10 @@ const runPipeline = async (options) => {
63090
63208
  resolveDoneForCrash = resolve;
63091
63209
  });
63092
63210
  try {
63211
+ settingsStore = createSettingsStore({
63212
+ path: resolveSettingsPath(xdgConfigHome),
63213
+ logger
63214
+ });
63093
63215
  loadedConfig = await validateAndLoadConfig(options);
63094
63216
  outputClient = selectOutputClient({
63095
63217
  emulator: options.emulator === true,
@@ -63105,8 +63227,10 @@ const runPipeline = async (options) => {
63105
63227
  decks = loaded.decks;
63106
63228
  pubSub = loaded.pubSub;
63107
63229
  runtime = loaded.runtime;
63230
+ runtime.setBrightness(settingsStore.get().brightness);
63108
63231
  methods = loaded.methods;
63109
63232
  store = loaded.store;
63233
+ unsubscribeBrightnessSettings = pubSub.subscribe("methods:adjustBrightness", ({ value }) => settingsStore?.update({ brightness: value }));
63110
63234
  providers = await startSystemProviders(options, methods);
63111
63235
  hostPolicy = createHostPolicyCoordinator({
63112
63236
  runtime,
@@ -63235,6 +63359,7 @@ const runPipeline = async (options) => {
63235
63359
  logger
63236
63360
  });
63237
63361
  addonServicesDispose = () => addonServices?.dispose();
63362
+ pubSub.publish("sireno:settings:brightness", { value: runtime.getBrightness() });
63238
63363
  for (const deck of decks) {
63239
63364
  registerDeckIcon(deck, resolverOptions, logger);
63240
63365
  registerIconForDeck(deck.buttons ?? [], resolverOptions, logger);
@@ -63281,6 +63406,7 @@ const runPipeline = async (options) => {
63281
63406
  resolveDoneForCrash();
63282
63407
  },
63283
63408
  ...options.frontendUrl !== void 0 ? { frontendUrl: options.frontendUrl } : {},
63409
+ ...options.configUiUrl !== void 0 ? { configUiUrl: options.configUiUrl } : {},
63284
63410
  ...options.port !== void 0 ? { port: options.port } : {},
63285
63411
  ...options.intervalMs !== void 0 ? { intervalMs: options.intervalMs } : {},
63286
63412
  remote: options.remote === true,
@@ -63386,6 +63512,8 @@ const runPipeline = async (options) => {
63386
63512
  });
63387
63513
  await done;
63388
63514
  } finally {
63515
+ unsubscribeBrightnessSettings?.();
63516
+ settingsStore?.close();
63389
63517
  if (unregisterSignal !== null) unregisterSignal();
63390
63518
  if (unregisterReload !== null) unregisterReload();
63391
63519
  if (bridgeSignal !== null) bridgeSignal.abort();
@@ -63418,7 +63546,7 @@ const preflight = async (options) => {
63418
63546
  await validateAndLoadConfig(options);
63419
63547
  const outputClient = selectOutputClient({
63420
63548
  emulator: options.emulator === true,
63421
- xdgConfigHome: resolveXdgConfigHome$1(options)
63549
+ xdgConfigHome: resolveXdgConfigHome$2(options)
63422
63550
  });
63423
63551
  if (outputClient.kind === "real") {
63424
63552
  if ((await outputClient.listDevices()).length === 0) throw new Error("No Stream Deck devices found. Connect a device and try again. On Linux, udev rules for vendor 0fd9 may be required — see packages/cli/src/device/linux-udev.ts for the rule file template.");
@@ -65211,6 +65339,30 @@ const saveOfferChoice = (choice) => {
65211
65339
  } catch {}
65212
65340
  };
65213
65341
  //#endregion
65342
+ //#region src/cli/install-root.ts
65343
+ /**
65344
+ * Resolve the install root of the distributed bundle:
65345
+ * <root>/sirenodeck, <root>/lib/cli/main.mjs, <root>/frontend/dist, <root>/etc/install.json
65346
+ *
65347
+ * Priority: SIRENO_INSTALL_ROOT (set by the launcher/installer) → walk up from
65348
+ * this module looking for the install markers (`etc/install.json`,
65349
+ * `frontend/dist/index.html`). Returns null in the dev checkout so callers
65350
+ * fall back to the monorepo layout.
65351
+ */
65352
+ const resolveInstallRoot = () => {
65353
+ const env = process.env["SIRENO_INSTALL_ROOT"];
65354
+ if (env !== void 0 && env.length > 0) return env;
65355
+ let dir = dirname(fileURLToPath(import.meta.url));
65356
+ for (let i = 0; i < 8; i += 1) {
65357
+ if (existsSync(join(dir, "etc", "install.json"))) return dir;
65358
+ if (existsSync(join(dir, "frontend", "dist", "index.html"))) return dir;
65359
+ const parent = dirname(dir);
65360
+ if (parent === dir) break;
65361
+ dir = parent;
65362
+ }
65363
+ return null;
65364
+ };
65365
+ //#endregion
65214
65366
  //#region src/cli/commands/start.ts
65215
65367
  const toRunOptions = (options, onChildren, onAddonsUpdate) => ({
65216
65368
  logger: options.logger,
@@ -65220,6 +65372,7 @@ const toRunOptions = (options, onChildren, onAddonsUpdate) => ({
65220
65372
  remote: options.remote,
65221
65373
  deviceModel: options.deviceModel,
65222
65374
  frontendUrl: options.frontendUrl,
65375
+ configUiUrl: options.configUiUrl,
65223
65376
  intervalMs: options.intervalMs,
65224
65377
  xdgConfigHome: options.xdgConfigHome,
65225
65378
  homeDir: options.homeDir,
@@ -65229,6 +65382,8 @@ const toRunOptions = (options, onChildren, onAddonsUpdate) => ({
65229
65382
  onAddonsUpdate
65230
65383
  });
65231
65384
  const resolveFrontendDist = () => {
65385
+ const installRoot = resolveInstallRoot();
65386
+ if (installRoot !== null) return join(installRoot, "frontend", "dist");
65232
65387
  const here = dirname(fileURLToPath(import.meta.url));
65233
65388
  return resolve(here, "../../../frontend/dist");
65234
65389
  };
@@ -65571,6 +65726,7 @@ const runInProcessSetup = async (options, logger, releaseLock) => {
65571
65726
  source: resolved.source
65572
65727
  }, `start: using config ${configPath}`);
65573
65728
  const runtimeFlags = buildRuntimeFlags(options);
65729
+ const installedFrontendUrl = resolveInstallRoot() !== null && runtimeFlags.emulator !== true ? `http://127.0.0.1:${runtimeFlags.httpPort}` : void 0;
65574
65730
  writeConfigPath(configPath);
65575
65731
  writeFlags(runtimeFlags);
65576
65732
  const allScanned = [...(await collectBuiltinAddonRegistry()).scanned];
@@ -65581,7 +65737,11 @@ const runInProcessSetup = async (options, logger, releaseLock) => {
65581
65737
  emulator: runtimeFlags.emulator,
65582
65738
  remote: runtimeFlags.remote,
65583
65739
  deviceModel: runtimeFlags.deviceModel,
65584
- httpPort: runtimeFlags.httpPort
65740
+ httpPort: runtimeFlags.httpPort,
65741
+ ...options.frontendUrl === void 0 && installedFrontendUrl !== void 0 ? {
65742
+ frontendUrl: installedFrontendUrl,
65743
+ configUiUrl: installedFrontendUrl
65744
+ } : {}
65585
65745
  }, (pids) => {
65586
65746
  writeChildren({ pids: [...pids] });
65587
65747
  logger.info({ pids }, "daemon: tracked children");
@@ -65991,7 +66151,7 @@ const tryBind = (port) => new Promise((resolve) => {
65991
66151
  cleanup(false);
65992
66152
  }
65993
66153
  });
65994
- const formatFeaturesList = (items) => ["Features", ...items.map((it) => `│ ${it.available ? color.green("✓") : color.red("✗")} ${it.name}${!it.available && it.reason ? ` — ${it.reason}` : ""}`)];
66154
+ const formatFeaturesList = (items) => ["Features", ...items.map((it) => `│ ${it.available ? color.green("✓") : color.red("✗")} ${it.name}${!it.available && it.reason ? ` — ${it.reason}` : ""}`)];
65995
66155
  const printFeaturesList = (items, write = (text) => process.stdout.write(text)) => {
65996
66156
  const lines = formatFeaturesList(items);
65997
66157
  write(`${lines.slice(1).join("\n")}\n`);
@@ -0,0 +1,69 @@
1
+ import { execa } from "execa";
2
+ //#region src/builtin-addons/coding-agents/providers/spawn.ts
3
+ var NotReachableError = class extends Error {
4
+ name = "NotReachableError";
5
+ constructor(message) {
6
+ super(message);
7
+ }
8
+ };
9
+ const defaultSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
10
+ const ensureOpencodeServer = async (baseUrl, signal, deps = {}) => {
11
+ const fetchImpl = deps.fetchImpl ?? fetch;
12
+ const sleep = deps.sleep ?? defaultSleep;
13
+ if (await isReachable(baseUrl, fetchImpl, signal)) return null;
14
+ if (signal.aborted) throw new AbortError();
15
+ const port = parsePort(baseUrl);
16
+ const child = deps.execaImpl ? deps.execaImpl("opencode", [
17
+ "serve",
18
+ "--port",
19
+ String(port)
20
+ ]) : execa("opencode", [
21
+ "serve",
22
+ "--port",
23
+ String(port)
24
+ ]);
25
+ Promise.resolve(child).catch(() => void 0);
26
+ const deadline = Date.now() + 5e3;
27
+ while (Date.now() < deadline) {
28
+ if (signal.aborted) {
29
+ await child.kill().catch(() => void 0);
30
+ throw new AbortError();
31
+ }
32
+ if (await isReachable(baseUrl, fetchImpl, signal)) return {
33
+ baseUrl,
34
+ child: { kill: async () => {
35
+ await child.kill().catch(() => void 0);
36
+ } }
37
+ };
38
+ await sleep(200);
39
+ }
40
+ await child.kill().catch(() => void 0);
41
+ throw new NotReachableError(`opencode serve did not become reachable at ${baseUrl} within 5 s`);
42
+ };
43
+ const isReachable = async (baseUrl, fetchImpl, signal) => {
44
+ try {
45
+ const res = await fetchImpl(`${baseUrl}/global/health`, { signal });
46
+ if (!res.ok) return false;
47
+ return (await res.json()).healthy === true;
48
+ } catch (err) {
49
+ if (err?.shortMessage) return false;
50
+ return false;
51
+ }
52
+ };
53
+ const parsePort = (baseUrl) => {
54
+ try {
55
+ const parsed = new URL(baseUrl);
56
+ const port = Number.parseInt(parsed.port, 10);
57
+ return Number.isFinite(port) && port > 0 ? port : 4096;
58
+ } catch {
59
+ return 4096;
60
+ }
61
+ };
62
+ var AbortError = class extends Error {
63
+ name = "AbortError";
64
+ constructor() {
65
+ super("aborted");
66
+ }
67
+ };
68
+ //#endregion
69
+ export { ensureOpencodeServer };
@@ -0,0 +1,45 @@
1
+ import { a as withTimeout } from "./main.mjs";
2
+ //#region src/system/providers/notification/windows.ts
3
+ const DEFAULT_TIMEOUT_MS = 5e3;
4
+ const shellQuote = (value) => `'${value.replace(/'/g, "''").replace(/'/g, "'\\''")}'`;
5
+ const buildToastScript = (title, body) => {
6
+ const safeTitle = title.replace(/[`$"\\]/g, "\\$&");
7
+ const safeBody = body.replace(/[`$"\\]/g, "\\$&");
8
+ return [
9
+ "Add-Type -AssemblyName System.Windows.Forms | Out-Null",
10
+ `$balloon = New-Object System.Windows.Forms.NotifyIcon`,
11
+ `$balloon.Icon = [System.Drawing.SystemIcons]::Information`,
12
+ `$balloon.BalloonTipTitle = "${safeTitle}"`,
13
+ `$balloon.BalloonTipText = "${safeBody}"`,
14
+ `$balloon.Visible = $true`,
15
+ `$balloon.ShowBalloonTip(5000)`,
16
+ "Start-Sleep -Milliseconds 5500",
17
+ "$balloon.Dispose()"
18
+ ].join("; ");
19
+ };
20
+ const createWindowsNotificationProvider = async (deps) => {
21
+ const timeoutMs = deps.timeoutMs ?? DEFAULT_TIMEOUT_MS;
22
+ return { async notify(args) {
23
+ const script = buildToastScript(args.title, args.body);
24
+ try {
25
+ await withTimeout(deps.executor.run("powershell", [
26
+ "-NoProfile",
27
+ "-Command",
28
+ script
29
+ ]), timeoutMs);
30
+ } catch (err) {
31
+ deps.logger.warn({ err }, "windows notification: toast failed");
32
+ }
33
+ if (args.sound === true && deps.soundPath !== void 0) try {
34
+ await withTimeout(deps.executor.run("powershell", [
35
+ "-NoProfile",
36
+ "-Command",
37
+ `(New-Object Media.SoundPlayer '${shellQuote(deps.soundPath)}').PlaySync()`
38
+ ]), timeoutMs);
39
+ } catch (err) {
40
+ deps.logger.warn({ err }, "windows notification: sound playback failed");
41
+ }
42
+ } };
43
+ };
44
+ //#endregion
45
+ export { createWindowsNotificationProvider };