desky-agent 0.3.4 → 0.3.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.
Binary file
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clawd-desk",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
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": "5659a1054909953c4098ea3bde923eb32b00622911703a1e0f0fb260d09c69fb"
30
+ "sha256": "fe2d9de15fc5bf2964fd01ed6930e315364c6ad63e3ba52ac0087aefa4d82d3b"
31
31
  }
32
32
  ]
33
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "desky-agent",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
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
5
  "keywords": [
6
6
  "claude-code",
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
@@ -1052,14 +1052,17 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
1052
1052
  { n: 2, name: 'Нахил голови', short: 'Нахил', base: 0, plus: 10, ref: 0,
1053
1053
  plusText: 'Голова нахилилася <b>вперед</b>, до ноутбука.',
1054
1054
  refText: 'голова стоїть <b>рівно</b>: не нахилена ні вперед, ні назад', lo: 'назад', hi: 'вперед' },
1055
- { n: 3, name: 'Права рука', short: 'Права рука', base: 65, plus: 20, ref: 0,
1055
+ { n: 3, name: 'Права рука', short: 'Права рука', base: 65, plus: 20, ref: 65, pic: 0,
1056
1056
  plusText: 'Права рука Desky <b>піднялася вперед</b>. Це та, що в тебе <b>зліва</b>, коли дивишся йому в обличчя.',
1057
1057
  refText: 'права рука <b>висить рівно вниз</b>', lo: 'назад', hi: 'вперед' },
1058
- { n: 4, name: 'Ліва рука', short: 'Ліва рука', base: 65, plus: 20, ref: 0,
1058
+ { n: 4, name: 'Ліва рука', short: 'Ліва рука', base: 65, plus: 20, ref: 65, pic: 0,
1059
1059
  plusText: 'Ліва рука Desky <b>піднялася вперед</b>. Це та, що в тебе <b>справа</b>, коли дивишся йому в обличчя.',
1060
1060
  refText: 'ліва рука <b>висить рівно вниз</b>', lo: 'назад', hi: 'вперед' },
1061
1061
  ];
1062
1062
  const HOME = [0, 0, 65, 65];
1063
+ // ref: the angle the centre is set at (sent to the board). An arm hangs straight down at the servo centre, home's
1064
+ // 65 (the horn goes on hanging), so its centre is set there; pic: how the pictures draw that pose (0 = hanging).
1065
+ const refPic = j => poseWith(j, J[j].pic ?? J[j].ref);
1063
1066
  const FACTORY_DIR = [1, 1, 1, -1]; // play.cpp dirOf: the arms are mirror images
1064
1067
  const poseWith = (j, v) => { const p = HOME.slice(); p[j] = v; return p; };
1065
1068
  const trimToDeg = j => CAL[j].trim * CAL[j].dir / US_PER_DEG;
@@ -1138,7 +1141,7 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
1138
1141
  c.appendChild(dir);
1139
1142
  const [front, other] = c.querySelectorAll('svg');
1140
1143
  c.draw = () => {
1141
- const P = poseWith(j, jj.ref);
1144
+ const P = refPic(j);
1142
1145
  drawFront(front, P, j);
1143
1146
  if (j === 0) { other.setAttribute('viewBox', '0 0 160 170'); drawTop(other, 0); } else drawSide(other, P, j);
1144
1147
  dir.querySelector('b').textContent = CAL[j].dir === FACTORY_DIR[j] ? 'як із заводу' : 'розвернутий';
@@ -1507,7 +1510,7 @@ svg.alive .eye { transform-box: fill-box; transform-origin: center; animation: b
1507
1510
  const jj = J[j];
1508
1511
  const [f1, s1] = fig('0 0 160 120', 'в обличчя: має бути так');
1509
1512
  const [f2, s2] = j === 0 ? fig('0 0 160 170', 'згори') : fig('0 0 240 170', 'збоку');
1510
- const ref = poseWith(j, jj.ref);
1513
+ const ref = refPic(j);
1511
1514
  drawFront(s1, ref, j); j === 0 ? drawTop(s2, 0) : drawSide(s2, ref, j);
1512
1515
  W.orig = CAL[j].trim;
1513
1516
  const dial = makeDial(j);