desky-agent 0.3.0 → 0.3.2
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/README.md +57 -50
- package/bin/cli.js +217 -206
- package/electron/icons.js +79 -79
- package/electron/main.js +245 -219
- package/firmware/firmware.bin +0 -0
- package/firmware/manifest.json +3 -3
- package/package.json +41 -40
- package/src/autostart.js +106 -106
- package/src/board.js +69 -69
- package/src/core.js +244 -172
- package/src/daemon.js +522 -446
- package/src/firmware.js +207 -207
- package/src/flasher.js +113 -113
- package/src/hook.js +95 -86
- package/src/install.js +418 -375
- package/src/link.js +207 -207
- package/src/paths.js +44 -44
- package/src/release.js +131 -0
- package/src/selfupdate.js +58 -0
- package/src/updater.js +138 -138
- package/ui/app.html +1522 -1470
- package/ui/clawd3d.js +377 -375
- package/ui/vendor/OrbitControls.js +1532 -1532
- package/ui/vendor/RoomEnvironment.js +144 -144
- package/ui/vendor/STLLoader.js +410 -410
- package/ui/vendor/three.LICENSE +21 -21
- package/ui/vendor/three.module.min.js +6 -6
package/firmware/manifest.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clawd-desk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"chip": "esp32s3",
|
|
5
5
|
"board": "waveshare-esp32-s3-zero",
|
|
6
6
|
"flash_size": "4MB",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
{
|
|
27
27
|
"file": "firmware.bin",
|
|
28
28
|
"address": "0x10000",
|
|
29
|
-
"size":
|
|
30
|
-
"sha256": "
|
|
29
|
+
"size": 339200,
|
|
30
|
+
"sha256": "55a4c95fbce83460f9ca5e80ae1deef92846a32b46a38b072c0bb1f6dbf542ea"
|
|
31
31
|
}
|
|
32
32
|
]
|
|
33
33
|
}
|
package/package.json
CHANGED
|
@@ -1,40 +1,41 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "desky-agent",
|
|
3
|
-
"version": "0.3.
|
|
4
|
-
"description": "Desky Agent: Desky, a desk robot that acts out what Claude Code is doing. Tray app, hooks and installer in one npx command",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"claude-code",
|
|
7
|
-
"claude",
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "desky-agent",
|
|
3
|
+
"version": "0.3.2",
|
|
4
|
+
"description": "Desky Agent: Desky, a desk robot that acts out what Claude Code or Codex is doing. Tray app, hooks and installer in one npx command",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"claude-code",
|
|
7
|
+
"claude",
|
|
8
|
+
"codex",
|
|
9
|
+
"hooks",
|
|
10
|
+
"robot",
|
|
11
|
+
"esp32",
|
|
12
|
+
"tray",
|
|
13
|
+
"desk-toy"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"bin": {
|
|
17
|
+
"desky-agent": "bin/cli.js"
|
|
18
|
+
},
|
|
19
|
+
"main": "electron/main.js",
|
|
20
|
+
"files": [
|
|
21
|
+
"bin",
|
|
22
|
+
"src",
|
|
23
|
+
"electron",
|
|
24
|
+
"ui",
|
|
25
|
+
"assets",
|
|
26
|
+
"firmware"
|
|
27
|
+
],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=18"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"test": "node --test",
|
|
33
|
+
"prepack": "node scripts/pack-firmware.js",
|
|
34
|
+
"start": "electron . --open"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"electron": "44.9.3",
|
|
38
|
+
"esptool-js": "0.7.0",
|
|
39
|
+
"serialport": "13.0.0"
|
|
40
|
+
}
|
|
41
|
+
}
|
package/src/autostart.js
CHANGED
|
@@ -1,106 +1,106 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
// Start Desky at login, on each system its own way. Used by the installer and by the tray's checkbox.
|
|
3
|
-
// Windows: HKCU\...\Run "Desky Agent" macOS: ~/Library/LaunchAgents/desk.clawd.app.plist
|
|
4
|
-
// Linux: ~/.config/autostart/clawd.desktop
|
|
5
|
-
// No KeepAlive anywhere: "Выйти" and "desky-agent stop" must stay stopped until the next login.
|
|
6
|
-
|
|
7
|
-
const fs = require('fs');
|
|
8
|
-
const os = require('os');
|
|
9
|
-
const path = require('path');
|
|
10
|
-
const { spawnSync } = require('child_process');
|
|
11
|
-
const paths = require('./paths');
|
|
12
|
-
|
|
13
|
-
const RUN_KEY = 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run';
|
|
14
|
-
const RUN_NAME = 'Desky Agent', OLD_RUN_NAME = 'Clawd'; // the Run value; "Clawd": 0.2.4 and older
|
|
15
|
-
const LABEL = 'desk.clawd.app';
|
|
16
|
-
const OLD_LABEL = 'desk.clawd.agent'; // the Python agent's LaunchAgent
|
|
17
|
-
const agents = () => path.join(os.homedir(), 'Library', 'LaunchAgents');
|
|
18
|
-
const PLIST = () => path.join(agents(), LABEL + '.plist');
|
|
19
|
-
const DESKTOP = () => path.join(process.env.XDG_CONFIG_HOME || path.join(os.homedir(), '.config'), 'autostart',
|
|
20
|
-
'clawd.desktop');
|
|
21
|
-
|
|
22
|
-
function launchInfo() {
|
|
23
|
-
return JSON.parse(fs.readFileSync(paths.LAUNCH, 'utf8'));
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const xml = s => String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
27
|
-
|
|
28
|
-
function plist(command, args) {
|
|
29
|
-
const items = [command, ...args].map(a => `\t\t<string>${xml(a)}</string>`).join('\n');
|
|
30
|
-
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
31
|
-
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
32
|
-
<plist version="1.0">
|
|
33
|
-
<dict>
|
|
34
|
-
\t<key>Label</key>
|
|
35
|
-
\t<string>${LABEL}</string>
|
|
36
|
-
\t<key>ProgramArguments</key>
|
|
37
|
-
\t<array>
|
|
38
|
-
${items}
|
|
39
|
-
\t</array>
|
|
40
|
-
\t<key>RunAtLoad</key>
|
|
41
|
-
\t<true/>
|
|
42
|
-
\t<key>ProcessType</key>
|
|
43
|
-
\t<string>Interactive</string>
|
|
44
|
-
</dict>
|
|
45
|
-
</plist>
|
|
46
|
-
`;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// a .desktop Exec line: quote every argument, escape what the spec says to
|
|
50
|
-
const execLine = argv => argv.map(a => '"' + String(a).replace(/(["`$\\])/g, '\\$1') + '"').join(' ');
|
|
51
|
-
|
|
52
|
-
function desktopEntry(command, args, extra = '') {
|
|
53
|
-
return `[Desktop Entry]
|
|
54
|
-
Type=Application
|
|
55
|
-
Name=Desky Agent
|
|
56
|
-
Comment=Desky shows what Claude Code is doing
|
|
57
|
-
Exec=${execLine([command, ...args])}
|
|
58
|
-
Icon=${path.join(paths.HOME, 'clawd.png')}
|
|
59
|
-
Terminal=false
|
|
60
|
-
Categories=Utility;
|
|
61
|
-
${extra}`;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function winQuote(a) {
|
|
65
|
-
return /[\s"]/.test(a) ? '"' + a.replace(/"/g, '\\"') + '"' : a;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function enable() {
|
|
69
|
-
const { command, args = [] } = launchInfo();
|
|
70
|
-
const argv = [...args, '--login'];
|
|
71
|
-
if (process.platform === 'win32') {
|
|
72
|
-
const value = [command, ...argv].map(winQuote).join(' ');
|
|
73
|
-
spawnSync('reg', ['delete', RUN_KEY, '/v', OLD_RUN_NAME, '/f'], { windowsHide: true, stdio: 'ignore' });
|
|
74
|
-
spawnSync('reg', ['add', RUN_KEY, '/v', RUN_NAME, '/t', 'REG_SZ', '/d', value, '/f'], { windowsHide: true });
|
|
75
|
-
} else if (process.platform === 'darwin') {
|
|
76
|
-
fs.mkdirSync(agents(), { recursive: true });
|
|
77
|
-
fs.writeFileSync(PLIST(), plist(command, argv));
|
|
78
|
-
} else {
|
|
79
|
-
fs.mkdirSync(path.dirname(DESKTOP()), { recursive: true });
|
|
80
|
-
fs.writeFileSync(DESKTOP(), desktopEntry(command, argv, 'X-GNOME-Autostart-enabled=true\n'));
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function disable() {
|
|
85
|
-
if (process.platform === 'win32') {
|
|
86
|
-
for (const v of [RUN_NAME, OLD_RUN_NAME]) spawnSync('reg', ['delete', RUN_KEY, '/v', v, '/f'], { windowsHide: true, stdio: 'ignore' });
|
|
87
|
-
} else if (process.platform === 'darwin') {
|
|
88
|
-
fs.rmSync(PLIST(), { force: true });
|
|
89
|
-
} else {
|
|
90
|
-
fs.rmSync(DESKTOP(), { force: true });
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function isEnabled() {
|
|
95
|
-
if (process.platform === 'win32') {
|
|
96
|
-
return spawnSync('reg', ['query', RUN_KEY, '/v', RUN_NAME], { windowsHide: true, stdio: 'ignore' }).status === 0;
|
|
97
|
-
}
|
|
98
|
-
return fs.existsSync(process.platform === 'darwin' ? PLIST() : DESKTOP());
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// the tray asks every second; the registry or the disk once is enough until the checkbox changes it
|
|
102
|
-
let cached = null;
|
|
103
|
-
const isEnabledCached = () => (cached === null ? (cached = isEnabled()) : cached);
|
|
104
|
-
const forget = () => { cached = null; };
|
|
105
|
-
|
|
106
|
-
module.exports = { enable, disable, isEnabled, isEnabledCached, forget, plist, desktopEntry, execLine, LABEL, OLD_LABEL, RUN_KEY };
|
|
1
|
+
'use strict';
|
|
2
|
+
// Start Desky at login, on each system its own way. Used by the installer and by the tray's checkbox.
|
|
3
|
+
// Windows: HKCU\...\Run "Desky Agent" macOS: ~/Library/LaunchAgents/desk.clawd.app.plist
|
|
4
|
+
// Linux: ~/.config/autostart/clawd.desktop
|
|
5
|
+
// No KeepAlive anywhere: "Выйти" and "desky-agent stop" must stay stopped until the next login.
|
|
6
|
+
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
const os = require('os');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const { spawnSync } = require('child_process');
|
|
11
|
+
const paths = require('./paths');
|
|
12
|
+
|
|
13
|
+
const RUN_KEY = 'HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Run';
|
|
14
|
+
const RUN_NAME = 'Desky Agent', OLD_RUN_NAME = 'Clawd'; // the Run value; "Clawd": 0.2.4 and older
|
|
15
|
+
const LABEL = 'desk.clawd.app';
|
|
16
|
+
const OLD_LABEL = 'desk.clawd.agent'; // the Python agent's LaunchAgent
|
|
17
|
+
const agents = () => path.join(os.homedir(), 'Library', 'LaunchAgents');
|
|
18
|
+
const PLIST = () => path.join(agents(), LABEL + '.plist');
|
|
19
|
+
const DESKTOP = () => path.join(process.env.XDG_CONFIG_HOME || path.join(os.homedir(), '.config'), 'autostart',
|
|
20
|
+
'clawd.desktop');
|
|
21
|
+
|
|
22
|
+
function launchInfo() {
|
|
23
|
+
return JSON.parse(fs.readFileSync(paths.LAUNCH, 'utf8'));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const xml = s => String(s).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
27
|
+
|
|
28
|
+
function plist(command, args) {
|
|
29
|
+
const items = [command, ...args].map(a => `\t\t<string>${xml(a)}</string>`).join('\n');
|
|
30
|
+
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
31
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
32
|
+
<plist version="1.0">
|
|
33
|
+
<dict>
|
|
34
|
+
\t<key>Label</key>
|
|
35
|
+
\t<string>${LABEL}</string>
|
|
36
|
+
\t<key>ProgramArguments</key>
|
|
37
|
+
\t<array>
|
|
38
|
+
${items}
|
|
39
|
+
\t</array>
|
|
40
|
+
\t<key>RunAtLoad</key>
|
|
41
|
+
\t<true/>
|
|
42
|
+
\t<key>ProcessType</key>
|
|
43
|
+
\t<string>Interactive</string>
|
|
44
|
+
</dict>
|
|
45
|
+
</plist>
|
|
46
|
+
`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// a .desktop Exec line: quote every argument, escape what the spec says to
|
|
50
|
+
const execLine = argv => argv.map(a => '"' + String(a).replace(/(["`$\\])/g, '\\$1') + '"').join(' ');
|
|
51
|
+
|
|
52
|
+
function desktopEntry(command, args, extra = '') {
|
|
53
|
+
return `[Desktop Entry]
|
|
54
|
+
Type=Application
|
|
55
|
+
Name=Desky Agent
|
|
56
|
+
Comment=Desky shows what Claude Code is doing
|
|
57
|
+
Exec=${execLine([command, ...args])}
|
|
58
|
+
Icon=${path.join(paths.HOME, 'clawd.png')}
|
|
59
|
+
Terminal=false
|
|
60
|
+
Categories=Utility;
|
|
61
|
+
${extra}`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function winQuote(a) {
|
|
65
|
+
return /[\s"]/.test(a) ? '"' + a.replace(/"/g, '\\"') + '"' : a;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function enable() {
|
|
69
|
+
const { command, args = [] } = launchInfo();
|
|
70
|
+
const argv = [...args, '--login'];
|
|
71
|
+
if (process.platform === 'win32') {
|
|
72
|
+
const value = [command, ...argv].map(winQuote).join(' ');
|
|
73
|
+
spawnSync('reg', ['delete', RUN_KEY, '/v', OLD_RUN_NAME, '/f'], { windowsHide: true, stdio: 'ignore' });
|
|
74
|
+
spawnSync('reg', ['add', RUN_KEY, '/v', RUN_NAME, '/t', 'REG_SZ', '/d', value, '/f'], { windowsHide: true });
|
|
75
|
+
} else if (process.platform === 'darwin') {
|
|
76
|
+
fs.mkdirSync(agents(), { recursive: true });
|
|
77
|
+
fs.writeFileSync(PLIST(), plist(command, argv));
|
|
78
|
+
} else {
|
|
79
|
+
fs.mkdirSync(path.dirname(DESKTOP()), { recursive: true });
|
|
80
|
+
fs.writeFileSync(DESKTOP(), desktopEntry(command, argv, 'X-GNOME-Autostart-enabled=true\n'));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function disable() {
|
|
85
|
+
if (process.platform === 'win32') {
|
|
86
|
+
for (const v of [RUN_NAME, OLD_RUN_NAME]) spawnSync('reg', ['delete', RUN_KEY, '/v', v, '/f'], { windowsHide: true, stdio: 'ignore' });
|
|
87
|
+
} else if (process.platform === 'darwin') {
|
|
88
|
+
fs.rmSync(PLIST(), { force: true });
|
|
89
|
+
} else {
|
|
90
|
+
fs.rmSync(DESKTOP(), { force: true });
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function isEnabled() {
|
|
95
|
+
if (process.platform === 'win32') {
|
|
96
|
+
return spawnSync('reg', ['query', RUN_KEY, '/v', RUN_NAME], { windowsHide: true, stdio: 'ignore' }).status === 0;
|
|
97
|
+
}
|
|
98
|
+
return fs.existsSync(process.platform === 'darwin' ? PLIST() : DESKTOP());
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// the tray asks every second; the registry or the disk once is enough until the checkbox changes it
|
|
102
|
+
let cached = null;
|
|
103
|
+
const isEnabledCached = () => (cached === null ? (cached = isEnabled()) : cached);
|
|
104
|
+
const forget = () => { cached = null; };
|
|
105
|
+
|
|
106
|
+
module.exports = { enable, disable, isEnabled, isEnabledCached, forget, plist, desktopEntry, execLine, LABEL, OLD_LABEL, RUN_KEY };
|
package/src/board.js
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
// The board's "who" answer and what to do about its firmware: docs/firmware_contract.md, sections 2 and 3.
|
|
3
|
-
// Pure functions, no port: the link, the status, doctor and the firmware updater all use them.
|
|
4
|
-
|
|
5
|
-
const PKG_VERSION = require('../package.json').version;
|
|
6
|
-
const PROTO = 3; // the command set this package speaks
|
|
7
|
-
|
|
8
|
-
/** "clawd-desk 3 fw=0.2.0 chip=esp32s3 sn=CD-0007" -> { proto, fw, chip, sn }; null when the line is not Desky's.
|
|
9
|
-
* Protocol 2 boards say only "clawd-desk 2": fw, chip and sn come back null. Unknown fields are kept, order is free. */
|
|
10
|
-
function parseWho(line) {
|
|
11
|
-
const parts = String(line || '').trim().split(/\s+/);
|
|
12
|
-
if (parts[0] !== 'clawd-desk') return null;
|
|
13
|
-
const proto = Number.parseInt(parts[1], 10);
|
|
14
|
-
const info = { proto: Number.isFinite(proto) ? proto : null, fw: null, chip: null, sn: null };
|
|
15
|
-
for (const p of parts.slice(2)) {
|
|
16
|
-
const eq = p.indexOf('=');
|
|
17
|
-
if (eq > 0) info[p.slice(0, eq)] = p.slice(eq + 1);
|
|
18
|
-
}
|
|
19
|
-
if (info.sn === '-') info.sn = null;
|
|
20
|
-
return info;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** semver order, prerelease below its release; -1, 0, 1. Not semver -> null. */
|
|
24
|
-
function compareVersions(a, b) {
|
|
25
|
-
const re = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+.*)?$/;
|
|
26
|
-
const ma = re.exec(String(a || ''));
|
|
27
|
-
const mb = re.exec(String(b || ''));
|
|
28
|
-
if (!ma || !mb) return null;
|
|
29
|
-
for (let i = 1; i <= 3; i++) {
|
|
30
|
-
const d = Number(ma[i]) - Number(mb[i]);
|
|
31
|
-
if (d) return d < 0 ? -1 : 1;
|
|
32
|
-
}
|
|
33
|
-
const pa = ma[4];
|
|
34
|
-
const pb = mb[4];
|
|
35
|
-
if (pa === pb) return 0;
|
|
36
|
-
if (!pa) return 1;
|
|
37
|
-
if (!pb) return -1;
|
|
38
|
-
const xa = pa.split('.');
|
|
39
|
-
const xb = pb.split('.');
|
|
40
|
-
for (let i = 0; i < Math.max(xa.length, xb.length); i++) {
|
|
41
|
-
if (xa[i] === undefined) return -1;
|
|
42
|
-
if (xb[i] === undefined) return 1;
|
|
43
|
-
const na = /^\d+$/.test(xa[i]);
|
|
44
|
-
const nb = /^\d+$/.test(xb[i]);
|
|
45
|
-
if (na && nb && Number(xa[i]) !== Number(xb[i])) return Number(xa[i]) < Number(xb[i]) ? -1 : 1;
|
|
46
|
-
if (na !== nb) return na ? -1 : 1;
|
|
47
|
-
if (xa[i] !== xb[i]) return xa[i] < xb[i] ? -1 : 1;
|
|
48
|
-
}
|
|
49
|
-
return 0;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/** The contract's table (section 3). bundled: the firmware version this package carries.
|
|
53
|
-
* -> { action: 'ok' | 'update' | 'newer' | 'upgrade-package' | 'mismatch', why } */
|
|
54
|
-
function verdict(info, bundled = PKG_VERSION, proto = PROTO) {
|
|
55
|
-
if (!info) return { action: 'mismatch', why: 'плата не відповіла як Desky' };
|
|
56
|
-
if (!info.fw) return { action: 'update', why: 'на платі прошивка без версії (протокол ' + info.proto + ')' };
|
|
57
|
-
const c = compareVersions(info.fw, bundled);
|
|
58
|
-
if (c === null) return { action: 'mismatch', why: 'незрозуміла версія прошивки: ' + info.fw };
|
|
59
|
-
if (c < 0) return { action: 'update', why: `прошивка ${info.fw} старша за ${bundled}` };
|
|
60
|
-
if (c > 0) {
|
|
61
|
-
return info.proto === proto
|
|
62
|
-
? { action: 'newer', why: `прошивка ${info.fw} новіша за пакет ${bundled}, працює` }
|
|
63
|
-
: { action: 'upgrade-package', why: `прошивка ${info.fw} новіша за пакет ${bundled}: npx desky-agent@latest` };
|
|
64
|
-
}
|
|
65
|
-
if (info.proto !== proto) return { action: 'mismatch', why: `та сама версія ${bundled}, але протокол ${info.proto}, а не ${proto}` };
|
|
66
|
-
return { action: 'ok', why: 'прошивка ' + info.fw };
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
module.exports = { parseWho, compareVersions, verdict, PROTO, PKG_VERSION };
|
|
1
|
+
'use strict';
|
|
2
|
+
// The board's "who" answer and what to do about its firmware: docs/firmware_contract.md, sections 2 and 3.
|
|
3
|
+
// Pure functions, no port: the link, the status, doctor and the firmware updater all use them.
|
|
4
|
+
|
|
5
|
+
const PKG_VERSION = require('../package.json').version;
|
|
6
|
+
const PROTO = 3; // the command set this package speaks
|
|
7
|
+
|
|
8
|
+
/** "clawd-desk 3 fw=0.2.0 chip=esp32s3 sn=CD-0007" -> { proto, fw, chip, sn }; null when the line is not Desky's.
|
|
9
|
+
* Protocol 2 boards say only "clawd-desk 2": fw, chip and sn come back null. Unknown fields are kept, order is free. */
|
|
10
|
+
function parseWho(line) {
|
|
11
|
+
const parts = String(line || '').trim().split(/\s+/);
|
|
12
|
+
if (parts[0] !== 'clawd-desk') return null;
|
|
13
|
+
const proto = Number.parseInt(parts[1], 10);
|
|
14
|
+
const info = { proto: Number.isFinite(proto) ? proto : null, fw: null, chip: null, sn: null };
|
|
15
|
+
for (const p of parts.slice(2)) {
|
|
16
|
+
const eq = p.indexOf('=');
|
|
17
|
+
if (eq > 0) info[p.slice(0, eq)] = p.slice(eq + 1);
|
|
18
|
+
}
|
|
19
|
+
if (info.sn === '-') info.sn = null;
|
|
20
|
+
return info;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** semver order, prerelease below its release; -1, 0, 1. Not semver -> null. */
|
|
24
|
+
function compareVersions(a, b) {
|
|
25
|
+
const re = /^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+.*)?$/;
|
|
26
|
+
const ma = re.exec(String(a || ''));
|
|
27
|
+
const mb = re.exec(String(b || ''));
|
|
28
|
+
if (!ma || !mb) return null;
|
|
29
|
+
for (let i = 1; i <= 3; i++) {
|
|
30
|
+
const d = Number(ma[i]) - Number(mb[i]);
|
|
31
|
+
if (d) return d < 0 ? -1 : 1;
|
|
32
|
+
}
|
|
33
|
+
const pa = ma[4];
|
|
34
|
+
const pb = mb[4];
|
|
35
|
+
if (pa === pb) return 0;
|
|
36
|
+
if (!pa) return 1;
|
|
37
|
+
if (!pb) return -1;
|
|
38
|
+
const xa = pa.split('.');
|
|
39
|
+
const xb = pb.split('.');
|
|
40
|
+
for (let i = 0; i < Math.max(xa.length, xb.length); i++) {
|
|
41
|
+
if (xa[i] === undefined) return -1;
|
|
42
|
+
if (xb[i] === undefined) return 1;
|
|
43
|
+
const na = /^\d+$/.test(xa[i]);
|
|
44
|
+
const nb = /^\d+$/.test(xb[i]);
|
|
45
|
+
if (na && nb && Number(xa[i]) !== Number(xb[i])) return Number(xa[i]) < Number(xb[i]) ? -1 : 1;
|
|
46
|
+
if (na !== nb) return na ? -1 : 1;
|
|
47
|
+
if (xa[i] !== xb[i]) return xa[i] < xb[i] ? -1 : 1;
|
|
48
|
+
}
|
|
49
|
+
return 0;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The contract's table (section 3). bundled: the firmware version this package carries.
|
|
53
|
+
* -> { action: 'ok' | 'update' | 'newer' | 'upgrade-package' | 'mismatch', why } */
|
|
54
|
+
function verdict(info, bundled = PKG_VERSION, proto = PROTO) {
|
|
55
|
+
if (!info) return { action: 'mismatch', why: 'плата не відповіла як Desky' };
|
|
56
|
+
if (!info.fw) return { action: 'update', why: 'на платі прошивка без версії (протокол ' + info.proto + ')' };
|
|
57
|
+
const c = compareVersions(info.fw, bundled);
|
|
58
|
+
if (c === null) return { action: 'mismatch', why: 'незрозуміла версія прошивки: ' + info.fw };
|
|
59
|
+
if (c < 0) return { action: 'update', why: `прошивка ${info.fw} старша за ${bundled}` };
|
|
60
|
+
if (c > 0) {
|
|
61
|
+
return info.proto === proto
|
|
62
|
+
? { action: 'newer', why: `прошивка ${info.fw} новіша за пакет ${bundled}, працює` }
|
|
63
|
+
: { action: 'upgrade-package', why: `прошивка ${info.fw} новіша за пакет ${bundled}: npx desky-agent@latest` };
|
|
64
|
+
}
|
|
65
|
+
if (info.proto !== proto) return { action: 'mismatch', why: `та сама версія ${bundled}, але протокол ${info.proto}, а не ${proto}` };
|
|
66
|
+
return { action: 'ok', why: 'прошивка ' + info.fw };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
module.exports = { parseWho, compareVersions, verdict, PROTO, PKG_VERSION };
|