desky-agent 0.3.2 → 0.3.4
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/assets/clawd.ico +0 -0
- package/assets/clawd.png +0 -0
- package/electron/icons.js +10 -8
- package/firmware/firmware.bin +0 -0
- package/firmware/manifest.json +2 -2
- package/package.json +1 -1
- package/src/release.js +131 -131
- package/src/selfupdate.js +1 -1
- package/ui/app.html +48 -13
package/assets/clawd.ico
CHANGED
|
Binary file
|
package/assets/clawd.png
CHANGED
|
Binary file
|
package/electron/icons.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
// Tray icons:
|
|
2
|
+
// Tray icons: Desky's head from the brand sheet, drawn here as PNGs so there are no image files to keep in
|
|
3
3
|
// step. One pose per thing worth seeing at a glance in the tray.
|
|
4
4
|
|
|
5
5
|
const zlib = require('zlib');
|
|
@@ -12,14 +12,16 @@ const BODY = { orange: ORANGE, white: [0xec, 0xe8, 0xe1, 255], mint: [0x7c, 0xc4
|
|
|
12
12
|
const GREY = [0x8a, 0x85, 0x80, 255];
|
|
13
13
|
const EYE = [0x22, 0x22, 0x22, 255];
|
|
14
14
|
|
|
15
|
-
/** 16x16 grid of the pose: [x, y, w, h, colour] rectangles.
|
|
15
|
+
/** 16x16 grid of the pose: [x, y, w, h, colour] rectangles. Desky's head from the brand sheet: the screen with
|
|
16
|
+
* rounded corners, a servo ear on each side, the face the state shows. */
|
|
16
17
|
function pose(kind, body) {
|
|
17
|
-
const r = [[
|
|
18
|
-
if (kind === '
|
|
19
|
-
else r.push([
|
|
20
|
-
if (kind === '
|
|
21
|
-
else if (kind === '
|
|
22
|
-
|
|
18
|
+
const r = [[3, 3, 10, 10, body], [2, 4, 12, 8, body], [0, 6, 2, 4, body], [14, 6, 2, 4, body]];
|
|
19
|
+
if (kind === 'sleep') r.push([4, 8, 3, 1, EYE], [9, 8, 3, 1, EYE]); // eyes shut
|
|
20
|
+
else if (kind === 'read') r.push([4, 8, 2, 2, EYE], [9, 8, 2, 2, EYE]); // looking down at the screen
|
|
21
|
+
else if (kind === 'ask') r.push([4, 5, 3, 4, EYE], [9, 5, 3, 4, EYE]); // wide eyes: a call for you
|
|
22
|
+
else if (kind === 'done') r.push([4, 7, 1, 1, EYE], [5, 6, 1, 1, EYE], [6, 7, 1, 1, EYE],
|
|
23
|
+
[9, 7, 1, 1, EYE], [10, 6, 1, 1, EYE], [11, 7, 1, 1, EYE]); // ^ ^, the logo's face
|
|
24
|
+
else r.push([5, 5, 2, 4, EYE], [9, 5, 2, 4, EYE]);
|
|
23
25
|
return r;
|
|
24
26
|
}
|
|
25
27
|
|
package/firmware/firmware.bin
CHANGED
|
Binary file
|
package/firmware/manifest.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clawd-desk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"chip": "esp32s3",
|
|
5
5
|
"board": "waveshare-esp32-s3-zero",
|
|
6
6
|
"flash_size": "4MB",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"file": "firmware.bin",
|
|
28
28
|
"address": "0x10000",
|
|
29
29
|
"size": 339200,
|
|
30
|
-
"sha256": "
|
|
30
|
+
"sha256": "5659a1054909953c4098ea3bde923eb32b00622911703a1e0f0fb260d09c69fb"
|
|
31
31
|
}
|
|
32
32
|
]
|
|
33
33
|
}
|
package/package.json
CHANGED
package/src/release.js
CHANGED
|
@@ -1,131 +1,131 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
// New versions of the app: npm's "latest" for this package, and the update the control app starts with one button.
|
|
3
|
-
//
|
|
4
|
-
// latest() the version npm calls latest, or throws (offline, the registry is down)
|
|
5
|
-
// newer(a, b) a is a later release than b
|
|
6
|
-
// canUpdate() the Node that installed Desky is still there: the app can update itself
|
|
7
|
-
// start(v) run the installer of version v in a process of its own (src/selfupdate.js): it stops this app,
|
|
8
|
-
// installs, starts the app again with its window open
|
|
9
|
-
// takeResult() what the last update did, once: { state: done | failed, text } or null
|
|
10
|
-
//
|
|
11
|
-
// The update is the very same "npx desky-agent@<v>" a person types: the installer of the new version does the work,
|
|
12
|
-
// this app only starts it and gets out of the way.
|
|
13
|
-
|
|
14
|
-
const fs = require('fs');
|
|
15
|
-
const os = require('os');
|
|
16
|
-
const path = require('path');
|
|
17
|
-
const https = require('https');
|
|
18
|
-
const { spawn } = require('child_process');
|
|
19
|
-
const paths = require('./paths');
|
|
20
|
-
|
|
21
|
-
const PKG = require('../package.json');
|
|
22
|
-
const RESULT = path.join(paths.STATE, 'app-update.json');
|
|
23
|
-
const UPDATE_LOG = path.join(paths.STATE, 'update.log');
|
|
24
|
-
const PLAIN = /^\d+\.\d+\.\d+$/; // a release; anything else never reaches a command line
|
|
25
|
-
|
|
26
|
-
function registry() {
|
|
27
|
-
const r = process.env.npm_config_registry || 'https://registry.npmjs.org/';
|
|
28
|
-
return r.endsWith('/') ? r : r + '/';
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function latest({ name = PKG.name, timeout = 10000 } = {}) {
|
|
32
|
-
return new Promise((resolve, reject) => {
|
|
33
|
-
const req = https.get(registry() + name + '/latest', {
|
|
34
|
-
timeout, headers: { accept: 'application/json', 'user-agent': `${PKG.name}/${PKG.version}` },
|
|
35
|
-
}, res => {
|
|
36
|
-
if (res.statusCode !== 200) {
|
|
37
|
-
res.resume();
|
|
38
|
-
return reject(new Error('реєстр npm відповів ' + res.statusCode));
|
|
39
|
-
}
|
|
40
|
-
let data = '';
|
|
41
|
-
res.setEncoding('utf8');
|
|
42
|
-
res.on('data', c => { if (data.length < 1 << 20) data += c; });
|
|
43
|
-
res.on('end', () => {
|
|
44
|
-
try {
|
|
45
|
-
const v = JSON.parse(data).version;
|
|
46
|
-
if (!PLAIN.test(v)) throw new Error('дивна версія ' + v);
|
|
47
|
-
resolve(v);
|
|
48
|
-
} catch (e) {
|
|
49
|
-
reject(e);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
return undefined;
|
|
53
|
-
});
|
|
54
|
-
req.on('timeout', () => req.destroy(new Error('реєстр npm не відповів')));
|
|
55
|
-
req.on('error', reject);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function newer(a, b) {
|
|
60
|
-
if (!PLAIN.test(String(a)) || !PLAIN.test(String(b))) return false;
|
|
61
|
-
const x = a.split('.').map(Number);
|
|
62
|
-
const y = b.split('.').map(Number);
|
|
63
|
-
for (let i = 0; i < 3; i++) if (x[i] !== y[i]) return x[i] > y[i];
|
|
64
|
-
return false;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** npm's own script next to a Node: the update runs npm with that Node, not with whatever is on PATH. */
|
|
68
|
-
function npmCliFor(node) {
|
|
69
|
-
const bin = path.dirname(node);
|
|
70
|
-
return [path.join(bin, 'node_modules', 'npm', 'bin', 'npm-cli.js'),
|
|
71
|
-
path.join(bin, '..', 'lib', 'node_modules', 'npm', 'bin', 'npm-cli.js')].find(f => fs.existsSync(f)) || null;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/** The Node that installed Desky: launch.json says so since 0.3; before that, the hooks in settings.json ran with it.
|
|
75
|
-
* -> { node, npm } or null */
|
|
76
|
-
function runner({ launchFile = paths.LAUNCH, settingsFile = path.join(os.homedir(), '.claude', 'settings.json') } = {}) {
|
|
77
|
-
const cands = [];
|
|
78
|
-
try {
|
|
79
|
-
cands.push(JSON.parse(fs.readFileSync(launchFile, 'utf8')).node);
|
|
80
|
-
} catch (e) { /* not installed */ }
|
|
81
|
-
try {
|
|
82
|
-
const hooks = JSON.parse(fs.readFileSync(settingsFile, 'utf8')).hooks || {};
|
|
83
|
-
for (const h of Object.values(hooks).flat().flatMap(g => (g && g.hooks) || [])) {
|
|
84
|
-
if (/(clawdydesk|desky-agent)[\\/]src[\\/]hook\.js/i.test((h.args || []).join(' '))) cands.push(h.command);
|
|
85
|
-
}
|
|
86
|
-
} catch (e) { /* no settings */ }
|
|
87
|
-
for (const node of cands) {
|
|
88
|
-
if (typeof node !== 'string' || !path.isAbsolute(node) || !fs.existsSync(node)) continue;
|
|
89
|
-
const npm = npmCliFor(node);
|
|
90
|
-
if (npm) return { node, npm };
|
|
91
|
-
}
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function canUpdate() {
|
|
96
|
-
return fs.existsSync(paths.LAUNCH) && Boolean(runner());
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function start(version) {
|
|
100
|
-
if (!PLAIN.test(String(version))) throw new Error('не версія: ' + version);
|
|
101
|
-
const how = runner();
|
|
102
|
-
if (!how) throw new Error('не знайшов Node, яким ставили Desky. Онови з термінала: npx desky-agent@latest');
|
|
103
|
-
fs.mkdirSync(paths.STATE, { recursive: true });
|
|
104
|
-
fs.rmSync(RESULT, { force: true });
|
|
105
|
-
const env = { ...process.env };
|
|
106
|
-
delete env.ELECTRON_RUN_AS_NODE;
|
|
107
|
-
// a console program: hidden, or Windows shows an empty terminal for the whole minute
|
|
108
|
-
const child = spawn(how.node, [path.join(__dirname, 'selfupdate.js'), version, how.npm],
|
|
109
|
-
{ detached: true, stdio: 'ignore', windowsHide: true, cwd: os.homedir(), env });
|
|
110
|
-
child.unref();
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function writeResult(r) {
|
|
114
|
-
try {
|
|
115
|
-
fs.mkdirSync(paths.STATE, { recursive: true });
|
|
116
|
-
fs.writeFileSync(RESULT, JSON.stringify({ ...r, at: new Date().toISOString() }));
|
|
117
|
-
} catch (e) { /* the log still says it */ }
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function takeResult() {
|
|
121
|
-
try {
|
|
122
|
-
const r = JSON.parse(fs.readFileSync(RESULT, 'utf8'));
|
|
123
|
-
fs.rmSync(RESULT, { force: true });
|
|
124
|
-
return { state: r.ok ? 'done' : 'failed', text: String(r.text || '') };
|
|
125
|
-
} catch (e) {
|
|
126
|
-
return null;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
module.exports = { latest, newer, runner, npmCliFor, canUpdate, start, writeResult, takeResult, RESULT, UPDATE_LOG,
|
|
131
|
-
PLAIN };
|
|
1
|
+
'use strict';
|
|
2
|
+
// New versions of the app: npm's "latest" for this package, and the update the control app starts with one button.
|
|
3
|
+
//
|
|
4
|
+
// latest() the version npm calls latest, or throws (offline, the registry is down)
|
|
5
|
+
// newer(a, b) a is a later release than b
|
|
6
|
+
// canUpdate() the Node that installed Desky is still there: the app can update itself
|
|
7
|
+
// start(v) run the installer of version v in a process of its own (src/selfupdate.js): it stops this app,
|
|
8
|
+
// installs, starts the app again with its window open
|
|
9
|
+
// takeResult() what the last update did, once: { state: done | failed, text } or null
|
|
10
|
+
//
|
|
11
|
+
// The update is the very same "npx desky-agent@<v>" a person types: the installer of the new version does the work,
|
|
12
|
+
// this app only starts it and gets out of the way.
|
|
13
|
+
|
|
14
|
+
const fs = require('fs');
|
|
15
|
+
const os = require('os');
|
|
16
|
+
const path = require('path');
|
|
17
|
+
const https = require('https');
|
|
18
|
+
const { spawn } = require('child_process');
|
|
19
|
+
const paths = require('./paths');
|
|
20
|
+
|
|
21
|
+
const PKG = require('../package.json');
|
|
22
|
+
const RESULT = path.join(paths.STATE, 'app-update.json');
|
|
23
|
+
const UPDATE_LOG = path.join(paths.STATE, 'update.log');
|
|
24
|
+
const PLAIN = /^\d+\.\d+\.\d+$/; // a release; anything else never reaches a command line
|
|
25
|
+
|
|
26
|
+
function registry() {
|
|
27
|
+
const r = process.env.npm_config_registry || 'https://registry.npmjs.org/';
|
|
28
|
+
return r.endsWith('/') ? r : r + '/';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function latest({ name = PKG.name, timeout = 10000 } = {}) {
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
const req = https.get(registry() + name + '/latest', {
|
|
34
|
+
timeout, headers: { accept: 'application/json', 'user-agent': `${PKG.name}/${PKG.version}` },
|
|
35
|
+
}, res => {
|
|
36
|
+
if (res.statusCode !== 200) {
|
|
37
|
+
res.resume();
|
|
38
|
+
return reject(new Error('реєстр npm відповів ' + res.statusCode));
|
|
39
|
+
}
|
|
40
|
+
let data = '';
|
|
41
|
+
res.setEncoding('utf8');
|
|
42
|
+
res.on('data', c => { if (data.length < 1 << 20) data += c; });
|
|
43
|
+
res.on('end', () => {
|
|
44
|
+
try {
|
|
45
|
+
const v = JSON.parse(data).version;
|
|
46
|
+
if (!PLAIN.test(v)) throw new Error('дивна версія ' + v);
|
|
47
|
+
resolve(v);
|
|
48
|
+
} catch (e) {
|
|
49
|
+
reject(e);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
return undefined;
|
|
53
|
+
});
|
|
54
|
+
req.on('timeout', () => req.destroy(new Error('реєстр npm не відповів')));
|
|
55
|
+
req.on('error', reject);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function newer(a, b) {
|
|
60
|
+
if (!PLAIN.test(String(a)) || !PLAIN.test(String(b))) return false;
|
|
61
|
+
const x = a.split('.').map(Number);
|
|
62
|
+
const y = b.split('.').map(Number);
|
|
63
|
+
for (let i = 0; i < 3; i++) if (x[i] !== y[i]) return x[i] > y[i];
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** npm's own script next to a Node: the update runs npm with that Node, not with whatever is on PATH. */
|
|
68
|
+
function npmCliFor(node) {
|
|
69
|
+
const bin = path.dirname(node);
|
|
70
|
+
return [path.join(bin, 'node_modules', 'npm', 'bin', 'npm-cli.js'),
|
|
71
|
+
path.join(bin, '..', 'lib', 'node_modules', 'npm', 'bin', 'npm-cli.js')].find(f => fs.existsSync(f)) || null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The Node that installed Desky: launch.json says so since 0.3; before that, the hooks in settings.json ran with it.
|
|
75
|
+
* -> { node, npm } or null */
|
|
76
|
+
function runner({ launchFile = paths.LAUNCH, settingsFile = path.join(os.homedir(), '.claude', 'settings.json') } = {}) {
|
|
77
|
+
const cands = [];
|
|
78
|
+
try {
|
|
79
|
+
cands.push(JSON.parse(fs.readFileSync(launchFile, 'utf8')).node);
|
|
80
|
+
} catch (e) { /* not installed */ }
|
|
81
|
+
try {
|
|
82
|
+
const hooks = JSON.parse(fs.readFileSync(settingsFile, 'utf8')).hooks || {};
|
|
83
|
+
for (const h of Object.values(hooks).flat().flatMap(g => (g && g.hooks) || [])) {
|
|
84
|
+
if (/(clawdydesk|desky-agent)[\\/]src[\\/]hook\.js/i.test((h.args || []).join(' '))) cands.push(h.command);
|
|
85
|
+
}
|
|
86
|
+
} catch (e) { /* no settings */ }
|
|
87
|
+
for (const node of cands) {
|
|
88
|
+
if (typeof node !== 'string' || !path.isAbsolute(node) || !fs.existsSync(node)) continue;
|
|
89
|
+
const npm = npmCliFor(node);
|
|
90
|
+
if (npm) return { node, npm };
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function canUpdate() {
|
|
96
|
+
return fs.existsSync(paths.LAUNCH) && Boolean(runner());
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function start(version) {
|
|
100
|
+
if (!PLAIN.test(String(version))) throw new Error('не версія: ' + version);
|
|
101
|
+
const how = runner();
|
|
102
|
+
if (!how) throw new Error('не знайшов Node, яким ставили Desky. Онови з термінала: npx desky-agent@latest');
|
|
103
|
+
fs.mkdirSync(paths.STATE, { recursive: true });
|
|
104
|
+
fs.rmSync(RESULT, { force: true });
|
|
105
|
+
const env = { ...process.env };
|
|
106
|
+
delete env.ELECTRON_RUN_AS_NODE;
|
|
107
|
+
// a console program: hidden, or Windows shows an empty terminal for the whole minute
|
|
108
|
+
const child = spawn(how.node, [path.join(__dirname, 'selfupdate.js'), version, how.npm],
|
|
109
|
+
{ detached: true, stdio: 'ignore', windowsHide: true, cwd: os.homedir(), env });
|
|
110
|
+
child.unref();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function writeResult(r) {
|
|
114
|
+
try {
|
|
115
|
+
fs.mkdirSync(paths.STATE, { recursive: true });
|
|
116
|
+
fs.writeFileSync(RESULT, JSON.stringify({ ...r, at: new Date().toISOString() }));
|
|
117
|
+
} catch (e) { /* the log still says it */ }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function takeResult() {
|
|
121
|
+
try {
|
|
122
|
+
const r = JSON.parse(fs.readFileSync(RESULT, 'utf8'));
|
|
123
|
+
fs.rmSync(RESULT, { force: true });
|
|
124
|
+
return { state: r.ok ? 'done' : 'failed', text: String(r.text || '') };
|
|
125
|
+
} catch (e) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
module.exports = { latest, newer, runner, npmCliFor, canUpdate, start, writeResult, takeResult, RESULT, UPDATE_LOG,
|
|
131
|
+
PLAIN };
|
package/src/selfupdate.js
CHANGED
|
@@ -15,7 +15,7 @@ const release = require('./release');
|
|
|
15
15
|
const { launch } = require('./hook');
|
|
16
16
|
|
|
17
17
|
const [version, npm] = process.argv.slice(2);
|
|
18
|
-
const PKG = require('../package.json').name;
|
|
18
|
+
const PKG = require('../package.json').name;
|
|
19
19
|
const INSTALLED = path.join(paths.HOME, 'node_modules', PKG, 'package.json');
|
|
20
20
|
|
|
21
21
|
function installedVersion() {
|
package/ui/app.html
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Crect x='2' y='3' width='12' height='9' fill='%23D9774B'/%3E%3Crect x='5' y='5' width='2' height='3' fill='%23222'/%3E%3Crect x='9' y='5' width='2' height='3' fill='%23222'/%3E%3Crect x='0' y='6' width='2' height='3' fill='%23D9774B'/%3E%3Crect x='14' y='6' width='2' height='3' fill='%23D9774B'/%3E%3Crect x='3' y='12' width='2' height='3' fill='%23D9774B'/%3E%3Crect x='11' y='12' width='2' height='3' fill='%23D9774B'/%3E%3C/svg%3E">
|
|
8
8
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
9
9
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
10
|
-
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Unbounded:wght@500;600&family=Onest:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap">
|
|
10
|
+
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Unbounded:wght@500;600&family=Onest:wght@400;500;600&family=JetBrains+Mono:wght@400;500;800&display=swap">
|
|
11
11
|
<script type="importmap">{ "imports": { "three": "/vendor/three.module.min.js" } }</script>
|
|
12
12
|
<script type="module" src="/clawd3d.js"></script>
|
|
13
13
|
<style>
|
|
@@ -44,9 +44,14 @@ h1, h2, h3, p { margin: 0; }
|
|
|
44
44
|
aside { background: var(--side); border-right: 1px solid var(--line); padding: 20px 16px; display: flex; flex-direction: column; gap: 18px;
|
|
45
45
|
position: sticky; top: 0; height: 100vh; overflow-y: auto; }
|
|
46
46
|
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; font: 600 17px var(--f-display); letter-spacing: -.01em; }
|
|
47
|
-
.brand
|
|
48
|
-
.brand .
|
|
49
|
-
.brand .
|
|
47
|
+
.brand { gap: 8px; }
|
|
48
|
+
.brand svg.head { width: 34px; height: auto; margin-right: 2px; }
|
|
49
|
+
.brand svg.chev { width: 10px; height: 16px; }
|
|
50
|
+
.brand svg.chev path { fill: none; stroke: var(--clawd); stroke-width: 3; stroke-linecap: square; }
|
|
51
|
+
.brand .wm { font: 800 19px/1 var(--f-mono, 'JetBrains Mono', monospace); letter-spacing: -.01em; margin-left: -3px; }
|
|
52
|
+
.brand .cur { width: 9px; height: 17px; background: var(--clawd); margin-left: -4px; animation: blink 1.1s steps(1) infinite; }
|
|
53
|
+
@keyframes blink { 50% { opacity: 0; } }
|
|
54
|
+
@media (prefers-reduced-motion: reduce) { .brand .cur { animation: none; } }
|
|
50
55
|
.who { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 18px 16px 16px; display: grid; justify-items: center;
|
|
51
56
|
gap: 4px; text-align: center; box-shadow: var(--shadow); }
|
|
52
57
|
.who svg { width: 136px; height: 102px; margin-bottom: 10px; border-radius: 12px; box-shadow: 0 8px 24px var(--clawd-glow); }
|
|
@@ -407,7 +412,7 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
407
412
|
<body>
|
|
408
413
|
<div class="app">
|
|
409
414
|
<aside>
|
|
410
|
-
<div class="brand"><svg viewBox="
|
|
415
|
+
<div class="brand" aria-label="Desky Agent"><svg class="head" viewBox="-8 0 80 48" aria-hidden="true" id="logo" data-head="1"></svg><svg class="chev" viewBox="0 0 10 16" aria-hidden="true"><path d="M1.5 2 L8 8 L1.5 14"/></svg><span class="wm">desky</span><span class="cur"></span></div>
|
|
411
416
|
<nav role="tablist">
|
|
412
417
|
<button type="button" role="tab" data-tab="home" aria-selected="true"><svg viewBox="0 0 24 24"><path d="M4 11l8-7 8 7v8.5a.5.5 0 0 1-.5.5H15v-6H9v6H4.5a.5.5 0 0 1-.5-.5z"/></svg>Огляд</button>
|
|
413
418
|
<button type="button" role="tab" data-tab="move"><svg viewBox="0 0 24 24"><path d="M4 7h9M19 7h1M4 17h3M13 17h7"/><circle cx="16" cy="7" r="2.5"/><circle cx="10" cy="17" r="2.5"/></svg>Рухи</button>
|
|
@@ -592,7 +597,7 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
592
597
|
<div class="wiz" id="wiz" hidden role="dialog" aria-modal="true" aria-labelledby="wizTitle">
|
|
593
598
|
<div class="panel">
|
|
594
599
|
<div class="top">
|
|
595
|
-
<div class="brand"><svg viewBox="
|
|
600
|
+
<div class="brand" aria-label="Desky Agent"><svg class="head" viewBox="-8 0 80 48" aria-hidden="true" id="wizLogo" data-head="1"></svg><svg class="chev" viewBox="0 0 10 16" aria-hidden="true"><path d="M1.5 2 L8 8 L1.5 14"/></svg><span class="wm">desky</span><span class="cur"></span></div>
|
|
596
601
|
<div class="prog"><div class="bars" id="wizBars"></div><div class="lbl" id="wizLbl"></div></div>
|
|
597
602
|
<button type="button" class="ghost x" id="wizClose" title="закрити майстер"><svg viewBox="0 0 16 16"><path d="M3.5 3.5l9 9M12.5 3.5l-9 9"/></svg></button>
|
|
598
603
|
</div>
|
|
@@ -656,6 +661,28 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
656
661
|
|
|
657
662
|
// ---------------------------------------------------------------- talking to the daemon
|
|
658
663
|
let up = false, connected = false, manual = false, beat = null;
|
|
664
|
+
// "on" powers the servos one by one, 400 ms each (play.cpp attachAll), and the board reads nothing meanwhile: a move
|
|
665
|
+
// sent behind it waits, and the "home" that ends a demo is already queued and cuts that move off at once. So "on"
|
|
666
|
+
// goes only when the servos are let go (the heartbeat says so), and the next command waits until the board is back.
|
|
667
|
+
// a move the wizard waits for: any line that reaches the board mid-move stops that move (play.cpp pollStop), so a
|
|
668
|
+
// demo's "home", then its move, then "home" again only work one after another. Done on the board's "ok <cmd>",
|
|
669
|
+
// refused on "Нельзя"/"err", and 4 s at most whatever happens (an old firmware, a lost line).
|
|
670
|
+
const waiters = [];
|
|
671
|
+
function move(cmd, ms = 4000) {
|
|
672
|
+
const word = cmd.trim().split(/\s+/)[0].toLowerCase();
|
|
673
|
+
return new Promise(resolve => {
|
|
674
|
+
const w = { word };
|
|
675
|
+
w.done = ok => { clearTimeout(w.t); const i = waiters.indexOf(w); if (i >= 0) waiters.splice(i, 1); resolve(ok); };
|
|
676
|
+
w.t = setTimeout(() => w.done(false), ms);
|
|
677
|
+
waiters.push(w);
|
|
678
|
+
send(cmd);
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
let onUntil = 0; // until then the board is still busy with the last "on" (any page sends it)
|
|
682
|
+
async function servosOn() {
|
|
683
|
+
if (!beat || /отпущены/.test(beat)) await send('on');
|
|
684
|
+
await wait(Math.max(0, onUntil - Date.now()));
|
|
685
|
+
}
|
|
659
686
|
async function api(path, body) {
|
|
660
687
|
const r = await fetch(path, body === undefined ? {} : { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) });
|
|
661
688
|
if (!r.ok) throw new Error((await r.json().catch(() => ({}))).error || r.status);
|
|
@@ -676,6 +703,7 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
676
703
|
const FACTORY = ['trim', 'inv', 'here', 'save', 'swap', 'flip', 'probe', 'hold', 'yawhold', 'sn', 'calset', 'face'];
|
|
677
704
|
async function send(cmd, quiet) {
|
|
678
705
|
if (FACTORY.includes(cmd.trim().split(/\s+/)[0].toLowerCase())) await api('/cmd', { line: 'factory on', hand: false }).catch(() => {});
|
|
706
|
+
if (cmd === 'on') onUntil = Date.now() + 1800;
|
|
679
707
|
if (!quiet) { lastHand = Date.now(); manual = true; showMode(); if (!/^trim /.test(cmd)) atRef = null; }
|
|
680
708
|
try { await api('/cmd', { line: cmd, hand: !quiet }); } catch (e) { log('не надіслано: ' + e.message, 'dim'); }
|
|
681
709
|
}
|
|
@@ -846,7 +874,11 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
846
874
|
r.setAttribute('x', x); r.setAttribute('y', y); r.setAttribute('width', w); r.setAttribute('height', h); r.setAttribute('fill', c);
|
|
847
875
|
if (cls) r.setAttribute('class', cls); s.appendChild(r); };
|
|
848
876
|
const bg = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
|
|
849
|
-
bg.setAttribute('width', 64); bg.setAttribute('height', 48); bg.setAttribute('rx', 4); bg.setAttribute('fill', PALETTE[COLOR].body); s.appendChild(bg);
|
|
877
|
+
bg.setAttribute('width', 64); bg.setAttribute('height', 48); bg.setAttribute('rx', s.dataset.head ? 8 : 4); bg.setAttribute('fill', PALETTE[COLOR].body); s.appendChild(bg);
|
|
878
|
+
// the logo: the head from the brand sheet, a servo ear on each side of the screen
|
|
879
|
+
if (s.dataset.head) for (const x of [-8, 64]) { const e = document.createElementNS('http://www.w3.org/2000/svg', 'rect');
|
|
880
|
+
e.setAttribute('x', x); e.setAttribute('y', 15); e.setAttribute('width', 8); e.setAttribute('height', 18); e.setAttribute('rx', 2);
|
|
881
|
+
e.setAttribute('fill', PALETTE[COLOR].body); s.appendChild(e); }
|
|
850
882
|
const eyes = { work: [9, 7, 0, 6], read: [7, 8, -4, 6], ask: [13, 13, 0, 0], sleep: [11, 2, 0, 4], idle: [8, 14, 0, 0],
|
|
851
883
|
wait: [8, 11, 0, 3], limit: [11, 3, 0, 4],
|
|
852
884
|
wake: [8, 14, 0, 0], listen: [8, 14, 0, 0] }[state];
|
|
@@ -904,7 +936,7 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
904
936
|
st.setProperty('--clawd', a); st.setProperty('--clawd-hi', hi); st.setProperty('--clawd-ink', ink);
|
|
905
937
|
st.setProperty('--clawd-soft', `color-mix(in srgb, ${a} ${dark ? 18 : 12}%, var(--card))`);
|
|
906
938
|
st.setProperty('--clawd-glow', `color-mix(in srgb, ${a} 24%, transparent)`);
|
|
907
|
-
['logo', 'bigface', 'wizLogo'].forEach(id => $(id) && drawFace($(id), id === 'wizLogo' ? '
|
|
939
|
+
['logo', 'bigface', 'wizLogo'].forEach(id => $(id) && drawFace($(id), id === 'wizLogo' ? 'done' : lastState || 'idle'));
|
|
908
940
|
if (C3) C3.colors(c.body, c.eye);
|
|
909
941
|
document.querySelectorAll('.swatch').forEach(b => b.setAttribute('aria-checked', String(b.dataset.color === COLOR)));
|
|
910
942
|
$('colorNow').textContent = c.name;
|
|
@@ -942,6 +974,9 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
942
974
|
let SWAP = null, FLIP = null;
|
|
943
975
|
const touched = [0, 0, 0, 0]; // when this window last moved a joint's trim: ignore echoes then
|
|
944
976
|
function onLine(line) {
|
|
977
|
+
const ok = line.match(/^ok (\S+)/);
|
|
978
|
+
if (ok) { const w = waiters.find(x => x.word === ok[1]); if (w) w.done(true); }
|
|
979
|
+
else if (/^(Нельзя|err )/.test(line) && waiters.length) waiters[0].done(false);
|
|
945
980
|
if (/^Серво отпущены/i.test(line)) $('limpbox').hidden = false;
|
|
946
981
|
if (/^Нельзя:/.test(line)) toast('Desky так не стане: зачепить стіл або ноутбук', true);
|
|
947
982
|
let m = line.match(/поза: J1 ([+-]?\d+)\s+J2 ([+-]?\d+)\s+J3 (-?\d+)\s+J4 (-?\d+)/);
|
|
@@ -1228,7 +1263,7 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
1228
1263
|
|
|
1229
1264
|
function wizOpen(from) {
|
|
1230
1265
|
$('wiz').hidden = false; showMode();
|
|
1231
|
-
drawFace($('wizLogo'), '
|
|
1266
|
+
drawFace($('wizLogo'), 'done');
|
|
1232
1267
|
go(from || 'hello');
|
|
1233
1268
|
setTimeout(() => { const b = $('wizBody').querySelector('button.pri'); b && b.focus(); }, 50);
|
|
1234
1269
|
}
|
|
@@ -1378,7 +1413,7 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
1378
1413
|
foot: [back('color'), spacer(), fix, ok],
|
|
1379
1414
|
});
|
|
1380
1415
|
$('wizBody').querySelector('.slot .row').appendChild(replay);
|
|
1381
|
-
async function demo() { C3 && C3.state('wave', true); await
|
|
1416
|
+
async function demo() { C3 && C3.state('wave', true); await servosOn(); await move('home'); await move('wave', 8000); await move('home'); }
|
|
1382
1417
|
busy(replay, demo);
|
|
1383
1418
|
}
|
|
1384
1419
|
|
|
@@ -1403,7 +1438,7 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
1403
1438
|
foot: [back('check'), spacer(), btn('Пропустити крок', 'ghost', () => go('screen'))],
|
|
1404
1439
|
});
|
|
1405
1440
|
const ch = $('wizBody').querySelector('.choices'); ch.append(ca, cb);
|
|
1406
|
-
async function show() { await
|
|
1441
|
+
async function show() { await servosOn(); await move('home'); await move('j1 10'); await wait(1200); await move('home'); }
|
|
1407
1442
|
async function answer(ok) {
|
|
1408
1443
|
if (ok) { go('screen'); return; }
|
|
1409
1444
|
if (W.retried) { note.hidden = false; note.className = 'note bad';
|
|
@@ -1456,7 +1491,7 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
1456
1491
|
foot: [back(j === 0 ? 'screen' : 'j' + (j - 1)), spacer(), btn('Пропустити суглоб', 'ghost', () => go(j < 3 ? 'j' + (j + 1) : 'done'))],
|
|
1457
1492
|
});
|
|
1458
1493
|
$('wizBody').querySelector('.choices').append(yes, no);
|
|
1459
|
-
async function show() { await
|
|
1494
|
+
async function show() { await servosOn(); await move('home'); await move('j' + jj.n + ' ' + (jj.base + jj.plus)); await wait(1200); await move('home'); }
|
|
1460
1495
|
async function answer(ok) {
|
|
1461
1496
|
if (ok) { await send('home'); go('j' + j, 'centre'); return; }
|
|
1462
1497
|
if (W.retried) { note.hidden = false; note.className = 'note bad';
|
|
@@ -1488,7 +1523,7 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
|
|
|
1488
1523
|
foot: [back('j' + j), spacer(), done],
|
|
1489
1524
|
});
|
|
1490
1525
|
W.onCal = k => { if (k === j) dial.sync(); };
|
|
1491
|
-
(async () => { await
|
|
1526
|
+
(async () => { await servosOn(); await toRef(j); await send('cal', true); })();
|
|
1492
1527
|
setTimeout(() => dial.querySelector('input').focus(), 80);
|
|
1493
1528
|
}
|
|
1494
1529
|
|