@evandu/super-pi 0.1.3 → 0.1.5

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.
@@ -0,0 +1,39 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ let runningVersion = "0.1.3";
4
+ /**
5
+ * Initializes the version captured when this server process booted up.
6
+ */
7
+ export function initRunningVersion(rootDir) {
8
+ try {
9
+ const pkg = JSON.parse(readFileSync(join(rootDir, "package.json"), "utf8"));
10
+ if (pkg.version)
11
+ runningVersion = pkg.version;
12
+ }
13
+ catch {
14
+ // fallback to default
15
+ }
16
+ return runningVersion;
17
+ }
18
+ /**
19
+ * Checks whether the package.json version on disk has been updated beyond
20
+ * the version currently executing in this process.
21
+ */
22
+ export function checkDiskVersion(rootDir) {
23
+ try {
24
+ const pkg = JSON.parse(readFileSync(join(rootDir, "package.json"), "utf8"));
25
+ const diskVersion = pkg.version ?? runningVersion;
26
+ return {
27
+ runningVersion,
28
+ diskVersion,
29
+ needsRestart: diskVersion !== runningVersion,
30
+ };
31
+ }
32
+ catch {
33
+ return {
34
+ runningVersion,
35
+ diskVersion: runningVersion,
36
+ needsRestart: false,
37
+ };
38
+ }
39
+ }
@@ -25,6 +25,7 @@ export interface WsServerOptions {
25
25
  commandHandler: CommandHandler;
26
26
  catalogService: CatalogService;
27
27
  accessToken?: string;
28
+ rootDir?: string;
28
29
  }
29
30
  /**
30
31
  * WebSocket transport manager handling upgrade, connection lifecycles, and command dispatch.
@@ -35,6 +36,7 @@ export declare class WsServer {
35
36
  private readonly commandHandler;
36
37
  private readonly catalogService;
37
38
  private readonly accessToken?;
39
+ private readonly rootDir?;
38
40
  constructor(options: WsServerOptions);
39
41
  private setupUpgrade;
40
42
  private setupConnectionHandling;
@@ -34,6 +34,7 @@ export class WsBroadcaster {
34
34
  return this.getState();
35
35
  }
36
36
  }
37
+ import { checkDiskVersion } from "./version.js";
37
38
  /**
38
39
  * WebSocket transport manager handling upgrade, connection lifecycles, and command dispatch.
39
40
  */
@@ -43,11 +44,13 @@ export class WsServer {
43
44
  commandHandler;
44
45
  catalogService;
45
46
  accessToken;
47
+ rootDir;
46
48
  constructor(options) {
47
49
  this.broadcaster = options.broadcaster;
48
50
  this.commandHandler = options.commandHandler;
49
51
  this.catalogService = options.catalogService;
50
52
  this.accessToken = options.accessToken;
53
+ this.rootDir = options.rootDir;
51
54
  this.websocketServer = new WebSocketServer({ noServer: true });
52
55
  this.setupUpgrade(options.httpServer);
53
56
  this.setupConnectionHandling();
@@ -67,6 +70,9 @@ export class WsServer {
67
70
  this.websocketServer.on("connection", (socket) => {
68
71
  this.broadcaster.register(socket);
69
72
  socket.send(JSON.stringify({ type: "state", state: this.broadcaster.getStateSnapshot() }));
73
+ if (this.rootDir) {
74
+ socket.send(JSON.stringify({ type: "server.version", version: checkDiskVersion(this.rootDir) }));
75
+ }
70
76
  void this.catalogService.agentCatalog().then((catalog) => {
71
77
  if (socket.readyState === WebSocket.OPEN) {
72
78
  socket.send(JSON.stringify({ type: "agent.catalog", catalog }));
@@ -80,6 +86,12 @@ export class WsServer {
80
86
  const heartbeat = setInterval(() => {
81
87
  if (socket.readyState === WebSocket.OPEN) {
82
88
  socket.ping();
89
+ if (this.rootDir) {
90
+ const v = checkDiskVersion(this.rootDir);
91
+ if (v.needsRestart) {
92
+ socket.send(JSON.stringify({ type: "server.version", version: v }));
93
+ }
94
+ }
83
95
  }
84
96
  }, 30_000);
85
97
  socket.on("close", () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evandu/super-pi",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Web control plane and companion for Pi",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -72,7 +72,8 @@
72
72
  "scripts/task-tool.test.mjs",
73
73
  "scripts/fork-server.test.mjs",
74
74
  "scripts/styles-no-dangling.test.mjs",
75
- "scripts/theme-no-hardcoded-colours.test.mjs"
75
+ "scripts/theme-no-hardcoded-colours.test.mjs",
76
+ "scripts/agent-config-regression.test.mjs"
76
77
  ],
77
78
  "check:browser": [
78
79
  "scripts/extension-ui-browser.test.mjs",
@@ -102,7 +103,8 @@
102
103
  "scripts/theme-switch-state.test.mjs",
103
104
  "scripts/settings-window-structure.test.mjs",
104
105
  "scripts/file-tab-selected-contrast.test.mjs",
105
- "scripts/help-window.test.mjs"
106
+ "scripts/help-window.test.mjs",
107
+ "scripts/composer-regression-browser.test.mjs"
106
108
  ],
107
109
  "dependencies": {
108
110
  "ws": "latest"