desky-agent 0.3.0 → 0.3.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/README.md +10 -3
- package/bin/cli.js +216 -206
- package/electron/icons.js +79 -79
- package/electron/main.js +244 -219
- package/firmware/firmware.bin +0 -0
- package/firmware/manifest.json +2 -2
- package/package.json +41 -40
- package/src/autostart.js +106 -106
- package/src/board.js +69 -69
- package/src/core.js +193 -172
- package/src/daemon.js +522 -446
- package/src/firmware.js +207 -207
- package/src/flasher.js +113 -113
- package/src/hook.js +92 -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 +1519 -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/src/core.js
CHANGED
|
@@ -1,172 +1,193 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
// What Desky shows: Claude Code's hook events in, lines for the C3 out.
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
this.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (name === '
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
set(s, '
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
if (this.
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
// What Desky shows: Claude Code's and Codex's hook events in, lines for the C3 out. Codex sends the same events
|
|
3
|
+
// under the same names (hook.js marks them agent: "codex"), less Notification and PostToolUseFailure, plus Interrupt.
|
|
4
|
+
//
|
|
5
|
+
// No timers, no port, no wall clock: the daemon feeds events and ticks, the tests do the same with a fake clock.
|
|
6
|
+
// The firmware acts a state out until the next one; everything about time lives here (how long "done" lasts, when
|
|
7
|
+
// to sleep, the ask trill repeats, the way back after an error, quiet hours). Times are in seconds.
|
|
8
|
+
|
|
9
|
+
// the colours Desky is printed in; the app and the face on his screen follow the one chosen (ui/app.html, PALETTE)
|
|
10
|
+
const COLORS = ['orange', 'white', 'mint', 'blue', 'graphite'];
|
|
11
|
+
|
|
12
|
+
const DEFAULTS = {
|
|
13
|
+
color: 'orange', // which Desky this is: his body colour
|
|
14
|
+
quiet_hours: [23, 8], // no sound from 23:00 to 08:00; [0, 0] = never quiet
|
|
15
|
+
done_secs: 120, // "done" looks at you this long, then idle
|
|
16
|
+
sleep_secs: 600, // no events this long: sleep
|
|
17
|
+
ask_repeat_secs: 120, // the ask trill again after this long ...
|
|
18
|
+
ask_times: 3, // ... at most this many times in all
|
|
19
|
+
session_ttl_secs: 1800, // a done or idle session silent this long stops counting
|
|
20
|
+
// A session killed mid-task (PC or app restarted, terminal closed) never sends Stop or SessionEnd and would keep
|
|
21
|
+
// Desky "working". The longest tool call is a 10 min Bash, so a working session silent for 11 min is gone.
|
|
22
|
+
busy_ttl_secs: 660,
|
|
23
|
+
ask_ttl_secs: 3600, // nobody answered for an hour: that question is not coming back
|
|
24
|
+
listen_secs: 1.5, // the nod after your message, then work
|
|
25
|
+
error_secs: 1.2,
|
|
26
|
+
wake_secs: 2.5,
|
|
27
|
+
read_tools: ['Read', 'Grep', 'Glob', 'WebFetch', 'WebSearch', 'LS', 'NotebookRead', 'ToolSearch'],
|
|
28
|
+
ask_tools: ['AskUserQuestion', 'request_user_input'],
|
|
29
|
+
// Codex reads with shell commands (tool "Bash"): a command made only of these reads, anything else works.
|
|
30
|
+
// Matched at the start of each part of a command line split at && || ; |, ignoring case.
|
|
31
|
+
read_commands: ['rg', 'grep', 'egrep', 'cat', 'head', 'tail', 'less', 'more', 'ls', 'dir', 'find', 'fd', 'tree',
|
|
32
|
+
'wc', 'pwd', 'stat', 'file', 'which', 'where', 'type', 'findstr', 'nl', 'sort', 'uniq', 'cut', 'jq', 'sed -n',
|
|
33
|
+
'cd', 'git status', 'git log', 'git diff', 'git show', 'git blame', 'git grep', 'git ls-files', 'git branch',
|
|
34
|
+
'git rev-parse', 'get-content', 'gc', 'get-childitem', 'gci', 'select-string', 'sls', 'get-item', 'test-path',
|
|
35
|
+
'resolve-path', 'select-object', 'sort-object', 'measure-object', 'where-object', 'format-table', 'format-list',
|
|
36
|
+
'out-string'],
|
|
37
|
+
port: 47811,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// what wins when sessions disagree
|
|
41
|
+
const RANK = { ask: 5, work: 4, read: 3, done: 2, idle: 1 };
|
|
42
|
+
const SOUND_ON_ENTER = { wake: 'wake', listen: 'tick', error: 'error', done: 'done', sleep: 'sleep', ask: 'ask' };
|
|
43
|
+
|
|
44
|
+
const now = () => Date.now() / 1000;
|
|
45
|
+
const localHour = t => new Date(t * 1000).getHours();
|
|
46
|
+
|
|
47
|
+
class Core {
|
|
48
|
+
constructor(send, { clock = now, config = {}, hour = localHour } = {}) {
|
|
49
|
+
this.send = send;
|
|
50
|
+
this.clock = clock;
|
|
51
|
+
this.hour = hour;
|
|
52
|
+
this.cfg = { ...DEFAULTS, ...config };
|
|
53
|
+
this.sessions = new Map(); // id -> { state, t, doneT }
|
|
54
|
+
this.overlay = null; // [state, until]: wake / listen / error play over the computed state
|
|
55
|
+
this.lastEvent = clock();
|
|
56
|
+
this.shown = null; // the last state sent
|
|
57
|
+
this.asksPlayed = 0;
|
|
58
|
+
this.nextAsk = null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// ------------------------------------------------------------ events
|
|
62
|
+
event(ev) {
|
|
63
|
+
const t = this.clock();
|
|
64
|
+
const name = ev.hook_event_name || '';
|
|
65
|
+
const sid = ev.session_id || '?';
|
|
66
|
+
const tool = ev.tool_name || '';
|
|
67
|
+
const before = this.display(t);
|
|
68
|
+
this.lastEvent = t;
|
|
69
|
+
if (name === 'SessionEnd') {
|
|
70
|
+
this.sessions.delete(sid);
|
|
71
|
+
this.tick();
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
let s = this.sessions.get(sid);
|
|
75
|
+
if (!s) this.sessions.set(sid, (s = { state: 'idle', t, doneT: null }));
|
|
76
|
+
s.t = t;
|
|
77
|
+
const c = this.cfg;
|
|
78
|
+
if (name === 'SessionStart') {
|
|
79
|
+
set(s, 'idle'); // resumed after a restart: whatever it was doing then is over
|
|
80
|
+
if (before === 'idle' || before === 'sleep') this.overlay = ['wake', t + c.wake_secs];
|
|
81
|
+
} else if (name === 'UserPromptSubmit') {
|
|
82
|
+
set(s, 'work');
|
|
83
|
+
this.overlay = ['listen', t + c.listen_secs];
|
|
84
|
+
} else if (name === 'PreToolUse') {
|
|
85
|
+
if (c.ask_tools.includes(tool)) set(s, 'ask');
|
|
86
|
+
else if (c.read_tools.includes(tool)) set(s, 'read');
|
|
87
|
+
else if (ev.agent === 'codex' && tool === 'Bash' && readsOnly(ev.command, c.read_commands)) set(s, 'read');
|
|
88
|
+
else set(s, 'work');
|
|
89
|
+
} else if (name === 'PermissionRequest') {
|
|
90
|
+
set(s, 'ask');
|
|
91
|
+
} else if (name === 'Notification') {
|
|
92
|
+
// idle_prompt comes a minute after Stop ("waiting for your input"): that is "done", not a call for you
|
|
93
|
+
if (ev.notification_type === 'permission_prompt' || ev.notification_type === 'elicitation_dialog') set(s, 'ask');
|
|
94
|
+
} else if (name === 'PostToolUse') {
|
|
95
|
+
if (['ask', 'done', 'idle'].includes(s.state)) set(s, 'work');
|
|
96
|
+
} else if (name === 'PostToolUseFailure') {
|
|
97
|
+
if (['ask', 'done', 'idle'].includes(s.state)) set(s, 'work');
|
|
98
|
+
this.overlay = ['error', t + c.error_secs];
|
|
99
|
+
} else if (['SubagentStop', 'SubagentStart', 'PreCompact'].includes(name)) {
|
|
100
|
+
if (s.state !== 'ask') set(s, 'work');
|
|
101
|
+
} else if (name === 'Stop') {
|
|
102
|
+
set(s, 'done');
|
|
103
|
+
s.doneT = t;
|
|
104
|
+
} else if (name === 'Interrupt') {
|
|
105
|
+
set(s, 'idle'); // you stopped it yourself: no "done" fanfare
|
|
106
|
+
}
|
|
107
|
+
this.tick();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// ------------------------------------------------------------ time
|
|
111
|
+
computed(t) {
|
|
112
|
+
const c = this.cfg;
|
|
113
|
+
let best = null;
|
|
114
|
+
for (const [sid, s] of this.sessions) {
|
|
115
|
+
const ttl = s.state === 'ask' ? c.ask_ttl_secs
|
|
116
|
+
: s.state === 'work' || s.state === 'read' ? c.busy_ttl_secs : c.session_ttl_secs;
|
|
117
|
+
if (t - s.t >= ttl) {
|
|
118
|
+
this.sessions.delete(sid);
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
if (s.state === 'done' && s.doneT !== null && t - s.doneT >= c.done_secs) set(s, 'idle');
|
|
122
|
+
if (best === null || RANK[s.state] > RANK[best]) best = s.state;
|
|
123
|
+
}
|
|
124
|
+
if ((best === null || best === 'idle') && t - this.lastEvent >= c.sleep_secs) return 'sleep';
|
|
125
|
+
return best || 'idle';
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
display(t) {
|
|
129
|
+
const base = this.computed(t);
|
|
130
|
+
if (this.overlay && t >= this.overlay[1]) this.overlay = null;
|
|
131
|
+
if (this.overlay && base !== 'ask') return this.overlay[0]; // nothing hides a call for you
|
|
132
|
+
return base;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
tick() {
|
|
136
|
+
const t = this.clock();
|
|
137
|
+
const st = this.display(t);
|
|
138
|
+
if (st !== this.shown) {
|
|
139
|
+
this.shown = st;
|
|
140
|
+
this.send('state ' + st);
|
|
141
|
+
if (st === 'ask') {
|
|
142
|
+
this.asksPlayed = 0;
|
|
143
|
+
this.nextAsk = t;
|
|
144
|
+
}
|
|
145
|
+
if (SOUND_ON_ENTER[st] && st !== 'ask') this.sound(SOUND_ON_ENTER[st], t);
|
|
146
|
+
}
|
|
147
|
+
if (st === 'ask' && this.nextAsk !== null && t >= this.nextAsk) {
|
|
148
|
+
this.sound('ask', t);
|
|
149
|
+
this.asksPlayed += 1;
|
|
150
|
+
this.nextAsk = this.asksPlayed < this.cfg.ask_times ? t + this.cfg.ask_repeat_secs : null;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
sound(name, t) {
|
|
155
|
+
if (!this.quiet(t)) this.send('sound ' + name);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
quiet(t) {
|
|
159
|
+
const [a, b] = this.cfg.quiet_hours;
|
|
160
|
+
const h = this.hour(t);
|
|
161
|
+
if (a === b) return false;
|
|
162
|
+
return a > b ? a <= h || h < b : a <= h && h < b;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// ------------------------------------------------------------ port
|
|
166
|
+
/** After a (re)connect: the C3 may have restarted, so say the current state again. */
|
|
167
|
+
resend() {
|
|
168
|
+
if (this.shown) this.send('state ' + this.shown);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
status() {
|
|
172
|
+
const t = this.clock();
|
|
173
|
+
const bySession = {};
|
|
174
|
+
const state = this.display(t);
|
|
175
|
+
for (const [k, s] of this.sessions) bySession[k.slice(0, 8)] = s.state;
|
|
176
|
+
return { state, sessions: this.sessions.size, by_session: bySession };
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** True when every part of a shell command line only reads (see read_commands). */
|
|
181
|
+
function readsOnly(command, words) {
|
|
182
|
+
if (typeof command !== 'string' || !command.trim()) return false;
|
|
183
|
+
if (/(^|[^0-9])>/.test(command)) return false; // "> file" writes; "2>/dev/null" does not
|
|
184
|
+
const parts = command.split(/&&|\|\||;|\|/).map(p => p.trim().toLowerCase()).filter(Boolean);
|
|
185
|
+
return parts.length > 0 && parts.every(p => words.some(w => p === w || p.startsWith(w + ' ')));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function set(s, state) {
|
|
189
|
+
s.state = state;
|
|
190
|
+
if (state !== 'done') s.doneT = null;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
module.exports = { Core, DEFAULTS, COLORS, readsOnly };
|