@sirenodeck/sirenodeck 0.4.0 → 0.4.1
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/config-ui/vite.config.ts +2 -0
- package/dist/main.mjs +345 -30
- package/frontend/vite.config.ts +2 -0
- package/package.json +1 -1
- package/src/api/protocol-internal.ts +4 -0
- package/src/cli/commands/run.ts +4 -0
- package/src/cli/commands/status-probes.ts +126 -0
- package/src/cli/commands/status.ts +166 -16
- package/src/outputClient/real.ts +18 -1
- package/src/render/browser-renderer.ts +68 -12
- package/src/render/ws-bridge.ts +2 -0
- package/src/util/build-fingerprint.ts +32 -0
- package/src/util/daemon-control.ts +41 -0
- package/src/util/runtime-health.ts +57 -0
- package/src/util/runtime-identity.ts +25 -0
- package/src/vite/component-identity.ts +48 -0
package/config-ui/vite.config.ts
CHANGED
|
@@ -4,6 +4,7 @@ import tailwindcss from "@tailwindcss/vite"
|
|
|
4
4
|
import { resolve } from "node:path"
|
|
5
5
|
import { sirenoDeck2 } from "../src/vite/index"
|
|
6
6
|
import { frontendBridgeUrl } from "../src/render/frontend-bridge-url"
|
|
7
|
+
import { componentIdentity } from "../src/vite/component-identity"
|
|
7
8
|
|
|
8
9
|
const wsUrl = frontendBridgeUrl()
|
|
9
10
|
const frontendUrl =
|
|
@@ -66,6 +67,7 @@ const addonsFromEnv = () => {
|
|
|
66
67
|
export default defineConfig({
|
|
67
68
|
root: __dirname,
|
|
68
69
|
plugins: [
|
|
70
|
+
componentIdentity(resolve(__dirname, ".."), "config-ui"),
|
|
69
71
|
react(),
|
|
70
72
|
tailwindcss(),
|
|
71
73
|
sirenoDeck2({
|
package/dist/main.mjs
CHANGED
|
@@ -23,9 +23,9 @@ import { YAMLMap, YAMLParseError, YAMLSeq, isMap, isScalar, isSeq, parse, parseA
|
|
|
23
23
|
import { execa } from "execa";
|
|
24
24
|
import { sessionBus } from "dbus-next";
|
|
25
25
|
import chokidar from "chokidar";
|
|
26
|
-
import { WebSocketServer } from "ws";
|
|
27
|
-
import { getStreamDeckModelName, listStreamDecks, openStreamDeck } from "@elgato-stream-deck/node";
|
|
26
|
+
import WebSocket, { WebSocketServer } from "ws";
|
|
28
27
|
import sharp from "sharp";
|
|
28
|
+
import { getStreamDeckModelName, listStreamDecks, openStreamDeck } from "@elgato-stream-deck/node";
|
|
29
29
|
import { promisify, styleText } from "node:util";
|
|
30
30
|
import { applyEdits, modify, parse as parse$1 } from "jsonc-parser";
|
|
31
31
|
import qrcode from "qrcode";
|
|
@@ -74,7 +74,7 @@ const LEVEL_LABEL = {
|
|
|
74
74
|
50: "ERROR",
|
|
75
75
|
60: "FATAL"
|
|
76
76
|
};
|
|
77
|
-
const colorize = (color, text) => process.stdout.isTTY ? `${color}${text}${RESET}` : text;
|
|
77
|
+
const colorize$1 = (color, text) => process.stdout.isTTY ? `${color}${text}${RESET}` : text;
|
|
78
78
|
const COMPONENT_COLOR = {
|
|
79
79
|
runtime: CYAN,
|
|
80
80
|
methods: CYAN,
|
|
@@ -154,25 +154,25 @@ const formatHuman = (jsonLine, options = {}) => {
|
|
|
154
154
|
const level = LEVEL_LABEL[levelNum] ?? "INFO";
|
|
155
155
|
const levelColor = LEVEL_COLOR[levelNum] ?? CYAN;
|
|
156
156
|
const msg = typeof entry["msg"] === "string" ? entry["msg"] : "";
|
|
157
|
-
const head = colorize(levelColor, level.padEnd(5));
|
|
157
|
+
const head = colorize$1(levelColor, level.padEnd(5));
|
|
158
158
|
const time = options.timestamps === true ? formatLogTime(entry["time"]) : null;
|
|
159
|
-
const timeTag = time !== null ? `${colorize(DIM, time)} ` : "";
|
|
159
|
+
const timeTag = time !== null ? `${colorize$1(DIM, time)} ` : "";
|
|
160
160
|
const component = typeof entry["component"] === "string" ? entry["component"] : "";
|
|
161
|
-
const componentTag = component.length > 0 ? ` ${colorize(colorForComponent(component), `[${component}]`)}` : "";
|
|
161
|
+
const componentTag = component.length > 0 ? ` ${colorize$1(colorForComponent(component), `[${component}]`)}` : "";
|
|
162
162
|
const ctxParts = [];
|
|
163
163
|
for (const key of CONTEXT_FIELDS) {
|
|
164
164
|
const value = entry[key];
|
|
165
165
|
if (value === void 0 || value === null) continue;
|
|
166
166
|
const display = formatContextValue(key, value);
|
|
167
167
|
if (display.length === 0) continue;
|
|
168
|
-
ctxParts.push(`${colorize(DIM, `${key}:`)} ${display}`);
|
|
168
|
+
ctxParts.push(`${colorize$1(DIM, `${key}:`)} ${display}`);
|
|
169
169
|
}
|
|
170
170
|
const err = entry["err"];
|
|
171
171
|
if (err !== null && typeof err === "object") {
|
|
172
172
|
const e = err;
|
|
173
173
|
const errType = typeof e.type === "string" ? e.type : "Error";
|
|
174
174
|
const errMsg = typeof e.message === "string" ? e.message : "";
|
|
175
|
-
if (errMsg.length > 0) ctxParts.push(`${colorize(DIM, "err:")} ${colorize(RED, `${errType}: ${errMsg}`)}`);
|
|
175
|
+
if (errMsg.length > 0) ctxParts.push(`${colorize$1(DIM, "err:")} ${colorize$1(RED, `${errType}: ${errMsg}`)}`);
|
|
176
176
|
}
|
|
177
177
|
return `${timeTag}${head}${componentTag} ${msg}${ctxParts.length > 0 ? ` (${ctxParts.join(", ")})` : ""}`;
|
|
178
178
|
};
|
|
@@ -308,7 +308,7 @@ const levelNameFromNumber = (level) => {
|
|
|
308
308
|
};
|
|
309
309
|
//#endregion
|
|
310
310
|
//#region package.json
|
|
311
|
-
var version$1 = "0.4.
|
|
311
|
+
var version$1 = "0.4.1";
|
|
312
312
|
//#endregion
|
|
313
313
|
//#region src/version.ts
|
|
314
314
|
const PACKAGE_NAME = "@sirenodeck/sirenodeck";
|
|
@@ -2022,6 +2022,61 @@ const startHttpServer = async (options) => {
|
|
|
2022
2022
|
};
|
|
2023
2023
|
};
|
|
2024
2024
|
//#endregion
|
|
2025
|
+
//#region src/util/runtime-identity.ts
|
|
2026
|
+
const development = process.env.SIRENO_DEV_MODE === "true";
|
|
2027
|
+
let buildId = null;
|
|
2028
|
+
buildId = "8d333f4a04af63988df6c4ecb9ac6da7bbfc3a40389d8d8c532391bdaa7f448a";
|
|
2029
|
+
const runtimeIdentity = {
|
|
2030
|
+
version: `${VERSION}${development ? "-dev" : ""}`,
|
|
2031
|
+
buildId
|
|
2032
|
+
};
|
|
2033
|
+
//#endregion
|
|
2034
|
+
//#region src/util/runtime-health.ts
|
|
2035
|
+
const runtimeHealthSchema = z.object({
|
|
2036
|
+
identity: z.object({
|
|
2037
|
+
version: z.string(),
|
|
2038
|
+
buildId: z.string().nullable()
|
|
2039
|
+
}).strict(),
|
|
2040
|
+
core: z.enum([
|
|
2041
|
+
"starting",
|
|
2042
|
+
"ready",
|
|
2043
|
+
"stopping"
|
|
2044
|
+
]),
|
|
2045
|
+
renderer: z.object({
|
|
2046
|
+
state: z.enum([
|
|
2047
|
+
"starting",
|
|
2048
|
+
"healthy",
|
|
2049
|
+
"recovering",
|
|
2050
|
+
"failed",
|
|
2051
|
+
"not-applicable"
|
|
2052
|
+
]),
|
|
2053
|
+
lastFrameAt: z.number().finite().nullable()
|
|
2054
|
+
}).strict()
|
|
2055
|
+
}).strict();
|
|
2056
|
+
const health = {
|
|
2057
|
+
identity: runtimeIdentity,
|
|
2058
|
+
core: "starting",
|
|
2059
|
+
renderer: {
|
|
2060
|
+
state: "starting",
|
|
2061
|
+
lastFrameAt: null
|
|
2062
|
+
}
|
|
2063
|
+
};
|
|
2064
|
+
const runtimeHealth = {
|
|
2065
|
+
snapshot: () => ({
|
|
2066
|
+
...health,
|
|
2067
|
+
renderer: { ...health.renderer }
|
|
2068
|
+
}),
|
|
2069
|
+
setCore: (state) => {
|
|
2070
|
+
health.core = state;
|
|
2071
|
+
},
|
|
2072
|
+
setRenderer: (state, lastFrameAt = health.renderer.lastFrameAt) => {
|
|
2073
|
+
health.renderer = {
|
|
2074
|
+
state,
|
|
2075
|
+
lastFrameAt
|
|
2076
|
+
};
|
|
2077
|
+
}
|
|
2078
|
+
};
|
|
2079
|
+
//#endregion
|
|
2025
2080
|
//#region src/util/daemon-control.ts
|
|
2026
2081
|
const GET_TOKEN = "get-token\n";
|
|
2027
2082
|
/**
|
|
@@ -2039,6 +2094,7 @@ const startDaemonControl = async (token, paths, logger) => {
|
|
|
2039
2094
|
socket.setEncoding("utf8");
|
|
2040
2095
|
socket.on("data", (data) => {
|
|
2041
2096
|
if (String(data).trim() === "get-token") socket.end(`${token}\n`);
|
|
2097
|
+
else if (String(data).trim() === "get-health") socket.end(`${JSON.stringify(runtimeHealth.snapshot())}\n`);
|
|
2042
2098
|
else socket.destroy();
|
|
2043
2099
|
});
|
|
2044
2100
|
});
|
|
@@ -2083,6 +2139,35 @@ const requestDaemonToken = (paths, timeoutMs = 1e3) => new Promise((resolve) =>
|
|
|
2083
2139
|
const removeDaemonControl = (paths) => {
|
|
2084
2140
|
if (existsSync(paths.controlSocket)) unlinkSync(paths.controlSocket);
|
|
2085
2141
|
};
|
|
2142
|
+
const requestDaemonHealth = (paths, timeoutMs = 1e3) => new Promise((resolve) => {
|
|
2143
|
+
if (!existsSync(paths.controlSocket)) return resolve(null);
|
|
2144
|
+
const socket = connect(paths.controlSocket);
|
|
2145
|
+
let data = "";
|
|
2146
|
+
let settled = false;
|
|
2147
|
+
const finish = (value) => {
|
|
2148
|
+
if (settled) return;
|
|
2149
|
+
settled = true;
|
|
2150
|
+
clearTimeout(timer);
|
|
2151
|
+
socket.destroy();
|
|
2152
|
+
resolve(value);
|
|
2153
|
+
};
|
|
2154
|
+
const timer = setTimeout(() => finish(null), timeoutMs);
|
|
2155
|
+
socket.setEncoding("utf8");
|
|
2156
|
+
socket.on("connect", () => socket.write("get-health\n"));
|
|
2157
|
+
socket.on("data", (chunk) => {
|
|
2158
|
+
data += chunk;
|
|
2159
|
+
if (!data.includes("\n")) return;
|
|
2160
|
+
try {
|
|
2161
|
+
const parsed = JSON.parse(data.split("\n", 1)[0]);
|
|
2162
|
+
const result = runtimeHealthSchema.safeParse(parsed);
|
|
2163
|
+
finish(result.success ? result.data : null);
|
|
2164
|
+
} catch {
|
|
2165
|
+
finish(null);
|
|
2166
|
+
}
|
|
2167
|
+
});
|
|
2168
|
+
socket.on("error", () => finish(null));
|
|
2169
|
+
socket.on("close", () => finish(null));
|
|
2170
|
+
});
|
|
2086
2171
|
//#endregion
|
|
2087
2172
|
//#region src/cli/commands/addon-registry.ts
|
|
2088
2173
|
const buildAddonByType = (scanned) => {
|
|
@@ -18889,6 +18974,10 @@ const helloAckMessageSchema = baseServerMessage.extend({
|
|
|
18889
18974
|
type: z.literal("hello-ack"),
|
|
18890
18975
|
version: z.literal(1),
|
|
18891
18976
|
device: deviceInfoSchema.optional(),
|
|
18977
|
+
build: z.object({
|
|
18978
|
+
version: z.string(),
|
|
18979
|
+
buildId: z.string().nullable()
|
|
18980
|
+
}).strict().optional(),
|
|
18892
18981
|
config: z.unknown()
|
|
18893
18982
|
}).strict();
|
|
18894
18983
|
const deviceInfoMessageSchema = baseServerMessage.extend({
|
|
@@ -19384,6 +19473,7 @@ const startWsBridge = (options) => {
|
|
|
19384
19473
|
const ack = helloAckMessageSchema.parse({
|
|
19385
19474
|
type: "hello-ack",
|
|
19386
19475
|
version: 1,
|
|
19476
|
+
build: runtimeIdentity,
|
|
19387
19477
|
...currentDevice !== null ? { device: currentDevice } : {},
|
|
19388
19478
|
config: currentTheme !== void 0 ? { theme: currentTheme.name } : {}
|
|
19389
19479
|
});
|
|
@@ -20568,6 +20658,7 @@ var BrowserRenderer = class BrowserRenderer {
|
|
|
20568
20658
|
context = null;
|
|
20569
20659
|
page = null;
|
|
20570
20660
|
running = false;
|
|
20661
|
+
recovering = null;
|
|
20571
20662
|
logger;
|
|
20572
20663
|
constructor(options) {
|
|
20573
20664
|
this.options = options;
|
|
@@ -20598,6 +20689,12 @@ var BrowserRenderer = class BrowserRenderer {
|
|
|
20598
20689
|
(original error: ${message.split("\n")[0] ?? ""})`);
|
|
20599
20690
|
throw err;
|
|
20600
20691
|
}
|
|
20692
|
+
await this.openPage();
|
|
20693
|
+
if (this.pubSub) this.subscriptions.push({ unsubscribe: this.pubSub.subscribe("runtime:activeDeck", () => this.debouncer.trigger()) }, { unsubscribe: this.pubSub.subscribe("runtime:invalidate", () => this.debouncer.trigger()) });
|
|
20694
|
+
this.cadence.start();
|
|
20695
|
+
this.running = true;
|
|
20696
|
+
}
|
|
20697
|
+
async openPage() {
|
|
20601
20698
|
const { columns, rows } = gridForKeyCount(this.options.device.getKeyCount());
|
|
20602
20699
|
const vpWidth = columns * 96;
|
|
20603
20700
|
const vpHeight = rows * 96;
|
|
@@ -20607,9 +20704,6 @@ var BrowserRenderer = class BrowserRenderer {
|
|
|
20607
20704
|
} });
|
|
20608
20705
|
this.page = await this.context.newPage();
|
|
20609
20706
|
await this.page.goto(this.options.frontendUrl, { waitUntil: "networkidle" });
|
|
20610
|
-
if (this.pubSub) this.subscriptions.push({ unsubscribe: this.pubSub.subscribe("runtime:activeDeck", () => this.debouncer.trigger()) }, { unsubscribe: this.pubSub.subscribe("runtime:invalidate", () => this.debouncer.trigger()) });
|
|
20611
|
-
this.cadence.start();
|
|
20612
|
-
this.running = true;
|
|
20613
20707
|
}
|
|
20614
20708
|
/**
|
|
20615
20709
|
* Repaints every key on the next tick.
|
|
@@ -20630,16 +20724,53 @@ var BrowserRenderer = class BrowserRenderer {
|
|
|
20630
20724
|
this.debouncer.dispose();
|
|
20631
20725
|
for (const sub of this.subscriptions) sub.unsubscribe();
|
|
20632
20726
|
this.subscriptions.length = 0;
|
|
20633
|
-
|
|
20634
|
-
|
|
20635
|
-
|
|
20727
|
+
await this.recovering;
|
|
20728
|
+
await Promise.allSettled([
|
|
20729
|
+
this.page?.close(),
|
|
20730
|
+
this.context?.close(),
|
|
20731
|
+
this.browser?.close()
|
|
20732
|
+
]);
|
|
20636
20733
|
this.page = null;
|
|
20637
20734
|
this.context = null;
|
|
20638
20735
|
this.browser = null;
|
|
20639
20736
|
}
|
|
20640
20737
|
static BLANK_THRESHOLD = 20;
|
|
20738
|
+
async recover() {
|
|
20739
|
+
runtimeHealth.setRenderer("recovering");
|
|
20740
|
+
const factory = this.options.playwrightFactory ?? (async () => await import("playwright"));
|
|
20741
|
+
for (let attempt = 1; attempt <= 3 && this.running; attempt++) {
|
|
20742
|
+
await Promise.allSettled([
|
|
20743
|
+
this.page?.close(),
|
|
20744
|
+
this.context?.close(),
|
|
20745
|
+
this.browser?.close()
|
|
20746
|
+
]);
|
|
20747
|
+
this.page = null;
|
|
20748
|
+
this.context = null;
|
|
20749
|
+
this.browser = null;
|
|
20750
|
+
if (!this.running) break;
|
|
20751
|
+
try {
|
|
20752
|
+
const playwright = await factory();
|
|
20753
|
+
this.browser = await playwright.chromium.launch({ headless: true });
|
|
20754
|
+
await this.openPage();
|
|
20755
|
+
await this.page.screenshot({ type: "png" });
|
|
20756
|
+
this.tracker.reset();
|
|
20757
|
+
this.logger.info({ attempt }, "browser renderer recovered");
|
|
20758
|
+
return;
|
|
20759
|
+
} catch (err) {
|
|
20760
|
+
this.logger.warn({
|
|
20761
|
+
err,
|
|
20762
|
+
attempt
|
|
20763
|
+
}, "browser renderer recovery failed");
|
|
20764
|
+
}
|
|
20765
|
+
}
|
|
20766
|
+
if (this.running) {
|
|
20767
|
+
this.cadence.stop();
|
|
20768
|
+
runtimeHealth.setRenderer("failed");
|
|
20769
|
+
await this.options.onFatalCrash?.();
|
|
20770
|
+
}
|
|
20771
|
+
}
|
|
20641
20772
|
async tick(source) {
|
|
20642
|
-
if (!this.page) return;
|
|
20773
|
+
if (!this.page || this.recovering) return;
|
|
20643
20774
|
try {
|
|
20644
20775
|
const png = await this.page.screenshot({ type: "png" });
|
|
20645
20776
|
const { columns, rows } = gridForKeyCount(this.options.device.getKeyCount());
|
|
@@ -20673,11 +20804,18 @@ var BrowserRenderer = class BrowserRenderer {
|
|
|
20673
20804
|
source
|
|
20674
20805
|
}, "frontend appears blank — React tree may have crashed (check the browser console or HMR errors)");
|
|
20675
20806
|
}
|
|
20807
|
+
runtimeHealth.setRenderer("healthy", Date.now());
|
|
20676
20808
|
} catch (err) {
|
|
20677
20809
|
this.logger.warn({
|
|
20678
20810
|
err,
|
|
20679
20811
|
source
|
|
20680
20812
|
}, "renderer tick failed");
|
|
20813
|
+
if (/target crashed|target page, context or browser has been closed/i.test(err.message)) {
|
|
20814
|
+
this.recovering ??= this.recover().finally(() => {
|
|
20815
|
+
this.recovering = null;
|
|
20816
|
+
});
|
|
20817
|
+
await this.recovering;
|
|
20818
|
+
}
|
|
20681
20819
|
}
|
|
20682
20820
|
}
|
|
20683
20821
|
};
|
|
@@ -21045,10 +21183,23 @@ var RealOutputClient = class {
|
|
|
21045
21183
|
logger
|
|
21046
21184
|
});
|
|
21047
21185
|
logger.info({ frontendUrl }, "real mode: frontend URL");
|
|
21186
|
+
let rendererFailed = false;
|
|
21048
21187
|
renderer = new BrowserRenderer({
|
|
21049
21188
|
frontendUrl: `${frontendUrl}${frontendUrl.includes("?") ? "&" : "?"}compact=1`,
|
|
21050
21189
|
device,
|
|
21051
21190
|
logger,
|
|
21191
|
+
onFatalCrash: async () => {
|
|
21192
|
+
rendererFailed = true;
|
|
21193
|
+
try {
|
|
21194
|
+
const svg = Buffer.from("<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"72\" height=\"72\"><rect width=\"72\" height=\"72\" fill=\"#7f1d1d\"/><text x=\"36\" y=\"28\" fill=\"white\" text-anchor=\"middle\" font-family=\"sans-serif\" font-weight=\"bold\" font-size=\"12\">RENDER</text><text x=\"36\" y=\"47\" fill=\"white\" text-anchor=\"middle\" font-family=\"sans-serif\" font-weight=\"bold\" font-size=\"12\">ERROR</text></svg>");
|
|
21195
|
+
const pixels = await sharp(svg).removeAlpha().raw().toBuffer();
|
|
21196
|
+
for (let i = 0; i < device.getKeyCount(); i++) await device.fillKeyBuffer(i, pixels);
|
|
21197
|
+
} catch (err) {
|
|
21198
|
+
logger.error({ err }, "failed to display renderer error");
|
|
21199
|
+
} finally {
|
|
21200
|
+
opts.onChildCrash?.();
|
|
21201
|
+
}
|
|
21202
|
+
},
|
|
21052
21203
|
...opts.intervalMs !== void 0 ? { intervalMs: opts.intervalMs } : {},
|
|
21053
21204
|
pubSub: opts.pubSub
|
|
21054
21205
|
});
|
|
@@ -21074,7 +21225,7 @@ var RealOutputClient = class {
|
|
|
21074
21225
|
wsUrl: opts.bridge.url,
|
|
21075
21226
|
childPids,
|
|
21076
21227
|
async pushBlackFrame() {
|
|
21077
|
-
await pushBlackFrame(device, logger);
|
|
21228
|
+
if (!rendererFailed) await pushBlackFrame(device, logger);
|
|
21078
21229
|
},
|
|
21079
21230
|
async pushRawImage(filePath) {
|
|
21080
21231
|
try {
|
|
@@ -22557,6 +22708,8 @@ const runPipeline = async (options) => {
|
|
|
22557
22708
|
lanAddresses: lanAddresses.map((a) => a.address)
|
|
22558
22709
|
});
|
|
22559
22710
|
currentOutputHandle = outputHandle;
|
|
22711
|
+
runtimeHealth.setCore("ready");
|
|
22712
|
+
if (options.emulator === true) runtimeHealth.setRenderer("not-applicable");
|
|
22560
22713
|
let refreshQueue = Promise.resolve();
|
|
22561
22714
|
editorMutationService = createConfigMutationService({ configPath: loadedConfig.configPath });
|
|
22562
22715
|
const refreshConfig = async (notifyEditor = true) => {
|
|
@@ -22655,6 +22808,7 @@ const runPipeline = async (options) => {
|
|
|
22655
22808
|
});
|
|
22656
22809
|
await done;
|
|
22657
22810
|
} finally {
|
|
22811
|
+
runtimeHealth.setCore("stopping");
|
|
22658
22812
|
unsubscribeBrightnessSettings?.();
|
|
22659
22813
|
settingsStore?.close();
|
|
22660
22814
|
if (unregisterSignal !== null) unregisterSignal();
|
|
@@ -25554,6 +25708,96 @@ const restart = async (options) => {
|
|
|
25554
25708
|
};
|
|
25555
25709
|
const isDevInvocation = () => (process.argv[1] ?? "").endsWith(".ts");
|
|
25556
25710
|
//#endregion
|
|
25711
|
+
//#region src/cli/commands/status-probes.ts
|
|
25712
|
+
const parseIdentity = (value) => {
|
|
25713
|
+
if (!value || typeof value !== "object") return null;
|
|
25714
|
+
const v = value;
|
|
25715
|
+
if (typeof v.version !== "string" || !(typeof v.buildId === "string" || v.buildId === null)) return null;
|
|
25716
|
+
return {
|
|
25717
|
+
version: v.version,
|
|
25718
|
+
buildId: v.buildId
|
|
25719
|
+
};
|
|
25720
|
+
};
|
|
25721
|
+
const probeWebIdentity = async (value, component) => {
|
|
25722
|
+
const base = localUrl(value, ["http:", "https:"]);
|
|
25723
|
+
if (!base) return null;
|
|
25724
|
+
try {
|
|
25725
|
+
const response = await fetch(new URL("/assets/sirenodeck-build.json", base), {
|
|
25726
|
+
signal: AbortSignal.timeout(1500),
|
|
25727
|
+
redirect: "manual"
|
|
25728
|
+
});
|
|
25729
|
+
if (!response.ok || !response.headers.get("content-type")?.includes("application/json")) return null;
|
|
25730
|
+
const body = await response.json();
|
|
25731
|
+
if (!body || typeof body !== "object" || !("component" in body) || body.component !== component) return null;
|
|
25732
|
+
return parseIdentity(body);
|
|
25733
|
+
} catch {
|
|
25734
|
+
return null;
|
|
25735
|
+
}
|
|
25736
|
+
};
|
|
25737
|
+
const localUrl = (value, protocols) => {
|
|
25738
|
+
try {
|
|
25739
|
+
const url = new URL(value);
|
|
25740
|
+
if (!protocols.includes(url.protocol)) return null;
|
|
25741
|
+
if (![
|
|
25742
|
+
"localhost",
|
|
25743
|
+
"127.0.0.1",
|
|
25744
|
+
"[::1]"
|
|
25745
|
+
].includes(url.hostname)) return null;
|
|
25746
|
+
return url;
|
|
25747
|
+
} catch {
|
|
25748
|
+
return null;
|
|
25749
|
+
}
|
|
25750
|
+
};
|
|
25751
|
+
const probeHttp = async (value) => {
|
|
25752
|
+
const url = localUrl(value, ["http:", "https:"]);
|
|
25753
|
+
if (!url) return "unknown";
|
|
25754
|
+
try {
|
|
25755
|
+
return (await fetch(url, {
|
|
25756
|
+
signal: AbortSignal.timeout(1500),
|
|
25757
|
+
redirect: "manual"
|
|
25758
|
+
})).ok ? "responding" : "unreachable";
|
|
25759
|
+
} catch {
|
|
25760
|
+
return "unreachable";
|
|
25761
|
+
}
|
|
25762
|
+
};
|
|
25763
|
+
const probeBridgeInfo = (value, token) => {
|
|
25764
|
+
const url = localUrl(value, ["ws:", "wss:"]);
|
|
25765
|
+
if (!url || token === null) return Promise.resolve({
|
|
25766
|
+
status: "unknown",
|
|
25767
|
+
identity: null
|
|
25768
|
+
});
|
|
25769
|
+
return new Promise((resolve) => {
|
|
25770
|
+
const socket = new WebSocket(url);
|
|
25771
|
+
const timer = setTimeout(() => finish("unreachable"), 1500);
|
|
25772
|
+
let finished = false;
|
|
25773
|
+
const finish = (result, identity = null) => {
|
|
25774
|
+
if (finished) return;
|
|
25775
|
+
finished = true;
|
|
25776
|
+
clearTimeout(timer);
|
|
25777
|
+
socket.terminate();
|
|
25778
|
+
resolve({
|
|
25779
|
+
status: result,
|
|
25780
|
+
identity
|
|
25781
|
+
});
|
|
25782
|
+
};
|
|
25783
|
+
socket.on("open", () => socket.send(JSON.stringify({
|
|
25784
|
+
type: "hello",
|
|
25785
|
+
version: 1,
|
|
25786
|
+
token
|
|
25787
|
+
})));
|
|
25788
|
+
socket.on("message", (data) => {
|
|
25789
|
+
try {
|
|
25790
|
+
const message = JSON.parse(data.toString());
|
|
25791
|
+
if (message.type === "hello-ack") finish(message.version === 1 ? "responding" : "unreachable", parseIdentity(message.build));
|
|
25792
|
+
} catch {
|
|
25793
|
+
finish("unreachable");
|
|
25794
|
+
}
|
|
25795
|
+
});
|
|
25796
|
+
socket.on("error", () => finish("unreachable"));
|
|
25797
|
+
socket.on("close", () => finish("unreachable"));
|
|
25798
|
+
});
|
|
25799
|
+
};
|
|
25800
|
+
//#endregion
|
|
25557
25801
|
//#region src/cli/commands/status.ts
|
|
25558
25802
|
const formatUptime = (ms) => {
|
|
25559
25803
|
if (ms < 0) return "—";
|
|
@@ -25565,12 +25809,32 @@ const formatUptime = (ms) => {
|
|
|
25565
25809
|
if (minutes > 0) return `${minutes}m ${seconds}s`;
|
|
25566
25810
|
return `${seconds}s`;
|
|
25567
25811
|
};
|
|
25812
|
+
const group = (title, details) => [title, ...details.map((detail, i) => {
|
|
25813
|
+
const separator = detail.indexOf(": ");
|
|
25814
|
+
const formatted = separator < 0 ? detail : `${detail.slice(0, separator + 2)}${colorize(detail.slice(separator + 2), 97)}`;
|
|
25815
|
+
return `${i === details.length - 1 ? "└─" : "├─"} ${formatted}`;
|
|
25816
|
+
})].join("\n");
|
|
25817
|
+
const colorize = (value, color) => {
|
|
25818
|
+
return process.env.NO_COLOR === void 0 && process.env.FORCE_COLOR !== "0" && (process.stdout.isTTY || process.env.FORCE_COLOR !== void 0 && process.env.FORCE_COLOR !== "") ? `\u001b[${color}m${value.replaceAll("\x1B[39m", `\u001b[${color}m`)}\u001b[39m` : value;
|
|
25819
|
+
};
|
|
25820
|
+
const coloredStatus = (value) => {
|
|
25821
|
+
const color = /^(running|ready|healthy|responding|same source)/i.test(value) ? 32 : /^(failed|unreachable|MISMATCH|stale)/i.test(value) ? 31 : 33;
|
|
25822
|
+
return colorize(value, color);
|
|
25823
|
+
};
|
|
25568
25824
|
const status = async ({ logger }) => {
|
|
25569
25825
|
const paths = resolveDaemonPaths();
|
|
25570
25826
|
const pid = readPid(paths);
|
|
25571
25827
|
if (pid === null) {
|
|
25572
25828
|
intro("sirenodeck status");
|
|
25573
25829
|
log$1.error("Daemon is not running");
|
|
25830
|
+
for (const component of [
|
|
25831
|
+
"Core",
|
|
25832
|
+
"Bridge",
|
|
25833
|
+
"Frontend",
|
|
25834
|
+
"Config UI",
|
|
25835
|
+
"Renderer",
|
|
25836
|
+
"Device"
|
|
25837
|
+
]) log$1.info(`${component}: unknown (daemon not running)`);
|
|
25574
25838
|
cancel("✗ No daemon process found");
|
|
25575
25839
|
return;
|
|
25576
25840
|
}
|
|
@@ -25580,36 +25844,87 @@ const status = async ({ logger }) => {
|
|
|
25580
25844
|
const childPids = readChildren(paths)?.pids ?? [];
|
|
25581
25845
|
const configPath = readConfigPath(paths);
|
|
25582
25846
|
intro("sirenodeck status");
|
|
25847
|
+
let daemonDetails = [];
|
|
25583
25848
|
if (alive) {
|
|
25584
25849
|
const startedAt = state?.startedAt ?? null;
|
|
25585
25850
|
const uptime = startedAt !== null ? formatUptime(Date.now() - startedAt) : "—";
|
|
25586
|
-
|
|
25851
|
+
daemonDetails = [
|
|
25852
|
+
`PID: ${pid}`,
|
|
25853
|
+
`Uptime: ${uptime}`,
|
|
25854
|
+
`Children: ${childPids.length > 0 ? `${childPids.length} (${childPids.join(", ")})` : "none tracked"}`
|
|
25855
|
+
];
|
|
25587
25856
|
} else log$1.warn(`Status: stale pid file (pid ${pid} not alive)`);
|
|
25588
25857
|
const isEmulator = state?.emulatorMode === true || flags?.emulator === true;
|
|
25589
25858
|
const deviceModel = typeof flags?.deviceModel === "string" ? flags.deviceModel : "mk2";
|
|
25590
|
-
if (isEmulator) log$1.info(
|
|
25859
|
+
if (isEmulator) log$1.info(group("Device", [`Mode: emulator`, `Model: ${deviceModel}`]));
|
|
25591
25860
|
else {
|
|
25592
25861
|
let hardwareLabel = "—";
|
|
25593
25862
|
try {
|
|
25594
25863
|
const devices = await listDevices();
|
|
25595
25864
|
if (devices.length > 0 && devices[0] !== void 0) hardwareLabel = devices[0].label;
|
|
25596
25865
|
} catch {}
|
|
25597
|
-
log$1.info(
|
|
25866
|
+
log$1.info(group("Device", [`Mode: hardware`, `Model: ${hardwareLabel}`]));
|
|
25598
25867
|
}
|
|
25599
25868
|
const remoteOn = state?.remote === true || flags?.remote === true;
|
|
25600
|
-
log$1.info(`Remote: ${remoteOn ? "on" : "off"}`);
|
|
25601
|
-
log$1.info(`Config: ${configPath ?? "—"}`);
|
|
25602
25869
|
const theme = state?.theme ?? "default";
|
|
25603
|
-
log$1.info(
|
|
25604
|
-
|
|
25605
|
-
|
|
25870
|
+
log$1.info(group("Configuration", [
|
|
25871
|
+
`Config: ${configPath ?? "—"}`,
|
|
25872
|
+
`Theme: ${theme}`,
|
|
25873
|
+
`Remote: ${remoteOn ? "on" : "off"}`
|
|
25874
|
+
]));
|
|
25875
|
+
if (!alive && childPids.length > 0) log$1.info(`Children: ${childPids.length} (${childPids.join(", ")})`);
|
|
25876
|
+
else if (!alive) log$1.info("Children: none tracked");
|
|
25606
25877
|
if (alive && state !== null) {
|
|
25607
|
-
const
|
|
25608
|
-
|
|
25609
|
-
|
|
25610
|
-
|
|
25878
|
+
const [token, health, frontend, configUi, frontendIdentity, configUiIdentity] = await Promise.all([
|
|
25879
|
+
requestDaemonToken(paths),
|
|
25880
|
+
requestDaemonHealth(paths),
|
|
25881
|
+
probeHttp(state.frontendUrl),
|
|
25882
|
+
state.configUiUrl ? probeHttp(state.configUiUrl) : Promise.resolve("unknown"),
|
|
25883
|
+
probeWebIdentity(state.frontendUrl, "frontend"),
|
|
25884
|
+
state.configUiUrl ? probeWebIdentity(state.configUiUrl, "config-ui") : Promise.resolve(null)
|
|
25885
|
+
]);
|
|
25886
|
+
const bridge = await probeBridgeInfo(state.wsUrl, token);
|
|
25887
|
+
const identityLabel = (identity) => {
|
|
25888
|
+
if (!identity) return "version/build unknown";
|
|
25889
|
+
const matches = identity.buildId && health?.identity?.buildId ? identity.buildId === health.identity.buildId && identity.version === health.identity.version ? "same source as daemon" : "MISMATCH" : "comparison unknown";
|
|
25890
|
+
return `${identity.version} build ${identity.buildId?.slice(0, 12) ?? "unknown"} (${coloredStatus(matches)})`;
|
|
25891
|
+
};
|
|
25892
|
+
log$1.info(group(`Daemon: ${coloredStatus("running")}`, [...daemonDetails, `Version: ${identityLabel(health?.identity ?? null)}`]));
|
|
25893
|
+
log$1.info(group("CLI", [`Version: ${identityLabel(runtimeIdentity)}`]));
|
|
25894
|
+
log$1.info(group(`Core: ${coloredStatus(health?.core ?? "unknown")}`, [`Version: ${identityLabel(health?.identity ?? null)}`]));
|
|
25895
|
+
log$1.info(group(`Bridge: ${coloredStatus(bridge.status)}`, [
|
|
25896
|
+
`Check: authenticated WebSocket handshake`,
|
|
25897
|
+
`URL: ${state.wsUrl}`,
|
|
25898
|
+
`Version: ${identityLabel(bridge.identity)}`
|
|
25899
|
+
]));
|
|
25900
|
+
log$1.info(group(`Frontend: ${coloredStatus(frontend)}`, [
|
|
25901
|
+
`Check: HTTP`,
|
|
25902
|
+
`URL: ${state.frontendUrl}`,
|
|
25903
|
+
`Version: ${identityLabel(frontendIdentity)}`
|
|
25904
|
+
]));
|
|
25905
|
+
log$1.info(group(`Config UI: ${coloredStatus(configUi)}`, [
|
|
25906
|
+
`Check: HTTP`,
|
|
25907
|
+
...state.configUiUrl ? [`URL: ${state.configUiUrl}`] : [],
|
|
25908
|
+
`Version: ${identityLabel(configUiIdentity)}`
|
|
25909
|
+
]));
|
|
25910
|
+
if (isEmulator) log$1.info("Renderer: not applicable (emulator mode)");
|
|
25911
|
+
else {
|
|
25912
|
+
const rendererState = health?.renderer?.state === "healthy" && health.renderer.lastFrameAt !== null && Date.now() - health.renderer.lastFrameAt > 1e4 ? "degraded (no recent frame)" : health?.renderer?.state ?? "unknown";
|
|
25913
|
+
const lastFrame = health?.renderer?.lastFrameAt ? new Date(health.renderer.lastFrameAt).toISOString() : "unknown";
|
|
25914
|
+
log$1.info(group(`Renderer: ${coloredStatus(rendererState)}`, [`Last frame: ${lastFrame}`, `Version: ${identityLabel(health?.identity ?? null)}`]));
|
|
25915
|
+
}
|
|
25611
25916
|
outro("✓ Status snapshot");
|
|
25612
|
-
} else
|
|
25917
|
+
} else {
|
|
25918
|
+
if (alive) log$1.info(group(`Daemon: ${coloredStatus("running")}`, daemonDetails));
|
|
25919
|
+
for (const component of [
|
|
25920
|
+
"Core",
|
|
25921
|
+
"Bridge",
|
|
25922
|
+
"Frontend",
|
|
25923
|
+
"Config UI",
|
|
25924
|
+
"Renderer"
|
|
25925
|
+
]) log$1.info(`${component}: unknown (runtime state unavailable)`);
|
|
25926
|
+
cancel(alive ? "✗ Daemon is running but runtime state is unavailable" : "✗ Stale pid file — daemon process is not running");
|
|
25927
|
+
}
|
|
25613
25928
|
};
|
|
25614
25929
|
//#endregion
|
|
25615
25930
|
//#region src/outputClient/open-browser.ts
|
package/frontend/vite.config.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { fileURLToPath } from "node:url"
|
|
|
6
6
|
import { readFileSync } from "node:fs"
|
|
7
7
|
import { sirenoDeck2 } from "../src/vite/index"
|
|
8
8
|
import { frontendBridgeUrl } from "../src/render/frontend-bridge-url"
|
|
9
|
+
import { componentIdentity } from "../src/vite/component-identity"
|
|
9
10
|
|
|
10
11
|
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
11
12
|
|
|
@@ -60,6 +61,7 @@ const themeFromEnv = ():
|
|
|
60
61
|
|
|
61
62
|
export default defineConfig({
|
|
62
63
|
plugins: [
|
|
64
|
+
componentIdentity(resolve(__dirname, ".."), "frontend"),
|
|
63
65
|
react(),
|
|
64
66
|
tailwindcss(),
|
|
65
67
|
sirenoDeck2({
|
package/package.json
CHANGED
|
@@ -42,6 +42,10 @@ export const helloAckMessageSchema = baseServerMessage
|
|
|
42
42
|
type: z.literal("hello-ack"),
|
|
43
43
|
version: z.literal(PROTOCOL_VERSION),
|
|
44
44
|
device: deviceInfoSchema.optional(),
|
|
45
|
+
build: z
|
|
46
|
+
.object({ version: z.string(), buildId: z.string().nullable() })
|
|
47
|
+
.strict()
|
|
48
|
+
.optional(),
|
|
45
49
|
config: z.unknown(),
|
|
46
50
|
})
|
|
47
51
|
.strict()
|
package/src/cli/commands/run.ts
CHANGED
|
@@ -96,6 +96,7 @@ import {
|
|
|
96
96
|
import { getHostContext } from "@/deck/host-context"
|
|
97
97
|
import { StatePublisher } from "@/render/state-publisher"
|
|
98
98
|
import { startWsBridge, type WsBridge } from "@/render/ws-bridge"
|
|
99
|
+
import { runtimeHealth } from "@/util/runtime-health"
|
|
99
100
|
import { DEFAULT_BRIDGE_PORT } from "./emulator-mode"
|
|
100
101
|
import { createConfigMutationService } from "@/config/mutation"
|
|
101
102
|
import {
|
|
@@ -1933,6 +1934,8 @@ export const runPipeline = async (options: RunOptions): Promise<void> => {
|
|
|
1933
1934
|
})
|
|
1934
1935
|
|
|
1935
1936
|
currentOutputHandle = outputHandle
|
|
1937
|
+
runtimeHealth.setCore("ready")
|
|
1938
|
+
if (options.emulator === true) runtimeHealth.setRenderer("not-applicable")
|
|
1936
1939
|
let refreshQueue = Promise.resolve()
|
|
1937
1940
|
|
|
1938
1941
|
// Note: do NOT overwrite the accumulated `trackedPids` Set with the initial
|
|
@@ -2149,6 +2152,7 @@ export const runPipeline = async (options: RunOptions): Promise<void> => {
|
|
|
2149
2152
|
|
|
2150
2153
|
await done
|
|
2151
2154
|
} finally {
|
|
2155
|
+
runtimeHealth.setCore("stopping")
|
|
2152
2156
|
unsubscribeBrightnessSettings?.()
|
|
2153
2157
|
settingsStore?.close()
|
|
2154
2158
|
if (unregisterSignal !== null) unregisterSignal()
|