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/src/hook.js
CHANGED
|
@@ -1,86 +1,95 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
'use strict';
|
|
3
|
-
// Claude Code hook: hand the event to Desky and get out of the way.
|
|
4
|
-
//
|
|
5
|
-
// Wired for every event by the installer. Reads the hook's JSON from stdin and POSTs it
|
|
6
|
-
// If the app does not answer, starts it in the tray (no window) and tries again for 3 s.
|
|
7
|
-
// nothing: a hook that fails or talks would get in the way of the session it decorates.
|
|
8
|
-
//
|
|
9
|
-
// After "desky-agent stop" or "Выйти" in the tray a marker file says so and the hook does not start the app;
|
|
10
|
-
// opening Desky or the next login clears it. CLAWD_PORT overrides the port, CLAWD_NO_SPAWN=1 skips starting (tests).
|
|
11
|
-
|
|
12
|
-
const fs = require('fs');
|
|
13
|
-
const http = require('http');
|
|
14
|
-
const { spawn } = require('child_process');
|
|
15
|
-
const paths = require('./paths');
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
res
|
|
22
|
-
res.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
req.on('
|
|
26
|
-
req.
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
child.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
process.stdin.on('
|
|
46
|
-
process.stdin.on('
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
// Claude Code and Codex hook: hand the event to Desky and get out of the way.
|
|
4
|
+
//
|
|
5
|
+
// Wired for every event by the installer ("hook.js codex" in Codex). Reads the hook's JSON from stdin and POSTs it
|
|
6
|
+
// to the app on localhost. If the app does not answer, starts it in the tray (no window) and tries again for 3 s.
|
|
7
|
+
// Always exits 0 and prints nothing: a hook that fails or talks would get in the way of the session it decorates.
|
|
8
|
+
//
|
|
9
|
+
// After "desky-agent stop" or "Выйти" in the tray a marker file says so and the hook does not start the app;
|
|
10
|
+
// opening Desky or the next login clears it. CLAWD_PORT overrides the port, CLAWD_NO_SPAWN=1 skips starting (tests).
|
|
11
|
+
|
|
12
|
+
const fs = require('fs');
|
|
13
|
+
const http = require('http');
|
|
14
|
+
const { spawn } = require('child_process');
|
|
15
|
+
const paths = require('./paths');
|
|
16
|
+
const { waitingOn } = require('./core');
|
|
17
|
+
|
|
18
|
+
function post(body, timeout = 500) {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
const req = http.request({ host: '127.0.0.1', port: paths.port(), path: '/event', method: 'POST', timeout,
|
|
21
|
+
headers: { 'Content-Type': 'application/json', 'Content-Length': body.length } }, res => {
|
|
22
|
+
res.resume();
|
|
23
|
+
res.on('end', () => (res.statusCode === 200 ? resolve() : reject(new Error(String(res.statusCode)))));
|
|
24
|
+
});
|
|
25
|
+
req.on('timeout', () => req.destroy(new Error('timeout')));
|
|
26
|
+
req.on('error', reject);
|
|
27
|
+
req.end(body);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Start the app detached, in the tray, so it outlives the hook and the session that ran it. */
|
|
32
|
+
function launch(extra = ['--background']) {
|
|
33
|
+
const how = JSON.parse(fs.readFileSync(paths.LAUNCH, 'utf8'));
|
|
34
|
+
const env = { ...process.env };
|
|
35
|
+
delete env.ELECTRON_RUN_AS_NODE; // set when this runs inside an Electron app such as an editor
|
|
36
|
+
// no windowsHide: Desky is a GUI program with no console, and SW_HIDE would hide its first window for good
|
|
37
|
+
const child = spawn(how.command, [...(how.args || []), ...extra], { detached: true, stdio: 'ignore', env });
|
|
38
|
+
child.unref();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function readStdin() {
|
|
42
|
+
return new Promise(resolve => {
|
|
43
|
+
if (process.stdin.isTTY) return resolve(Buffer.from('{}'));
|
|
44
|
+
const chunks = [];
|
|
45
|
+
process.stdin.on('data', c => chunks.push(c));
|
|
46
|
+
process.stdin.on('end', () => resolve(chunks.length ? Buffer.concat(chunks) : Buffer.from('{}')));
|
|
47
|
+
process.stdin.on('error', () => resolve(Buffer.from('{}')));
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// what the Core reads; a PostToolUse can carry megabytes of tool output that Desky never looks at
|
|
52
|
+
const KEEP = ['hook_event_name', 'session_id', 'tool_name', 'notification_type', 'source', 'error'];
|
|
53
|
+
|
|
54
|
+
/** agent: "codex" when Codex ran us (its hooks.json passes the word), else Claude Code. Codex reads files with
|
|
55
|
+
* shell commands, so for it the start of the command goes along: the Core tells reading from working by it. */
|
|
56
|
+
function slim(raw, agent = null) {
|
|
57
|
+
try {
|
|
58
|
+
const ev = JSON.parse(raw.toString('utf8').replace(/^/, ''));
|
|
59
|
+
const out = {};
|
|
60
|
+
for (const k of KEEP) if (ev[k] !== undefined) out[k] = ev[k];
|
|
61
|
+
if (agent) out.agent = agent;
|
|
62
|
+
// the start of a shell command: Codex reads files with commands, and "sleep 30" in either agent is waiting
|
|
63
|
+
if (ev.tool_input && typeof ev.tool_input.command === 'string') out.command = ev.tool_input.command.slice(0, 500);
|
|
64
|
+
// Stop lists the background work still in flight; only its kinds go along (see waitingOn in core.js)
|
|
65
|
+
const waits = waitingOn(ev);
|
|
66
|
+
if (waits.length) out.waiting_on = waits;
|
|
67
|
+
return Buffer.from(JSON.stringify(out));
|
|
68
|
+
} catch (e) {
|
|
69
|
+
return raw.length <= 1 << 20 ? raw : Buffer.from('{}');
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async function main() {
|
|
74
|
+
const body = slim(await readStdin(), process.argv[2] === 'codex' ? 'codex' : null);
|
|
75
|
+
try {
|
|
76
|
+
await post(body);
|
|
77
|
+
return;
|
|
78
|
+
} catch (e) { /* not running */ }
|
|
79
|
+
if (process.env.CLAWD_NO_SPAWN || fs.existsSync(paths.STOPPED)) return;
|
|
80
|
+
launch();
|
|
81
|
+
const end = Date.now() + 3000;
|
|
82
|
+
while (Date.now() < end) {
|
|
83
|
+
await new Promise(r => setTimeout(r, 300));
|
|
84
|
+
try {
|
|
85
|
+
await post(body);
|
|
86
|
+
return;
|
|
87
|
+
} catch (e) { /* still starting */ }
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (require.main === module) {
|
|
92
|
+
main().catch(() => {}).finally(() => process.exit(0));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
module.exports = { launch, post, slim };
|