indieclaw-agent 1.1.4 → 1.1.6
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/index.js +47 -0
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -135,6 +135,10 @@ async function handleMessage(ws, msg) {
|
|
|
135
135
|
return handleDockerAction(ws, msg, 'stop');
|
|
136
136
|
case 'docker.restart':
|
|
137
137
|
return handleDockerAction(ws, msg, 'restart');
|
|
138
|
+
case 'system.version':
|
|
139
|
+
return handleSystemVersion(ws, msg);
|
|
140
|
+
case 'system.update':
|
|
141
|
+
return handleSystemUpdate(ws, msg);
|
|
138
142
|
case 'cron.list':
|
|
139
143
|
return handleCronList(ws, msg);
|
|
140
144
|
case 'terminal.start':
|
|
@@ -486,6 +490,49 @@ function handleDockerAction(ws, { id, containerId }, action) {
|
|
|
486
490
|
});
|
|
487
491
|
}
|
|
488
492
|
|
|
493
|
+
// --- Agent Version & Update ---
|
|
494
|
+
function handleSystemVersion(ws, { id }) {
|
|
495
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf-8'));
|
|
496
|
+
exec('npm view indieclaw-agent version', { timeout: 10000 }, (err, stdout) => {
|
|
497
|
+
const latest = err ? null : stdout.trim();
|
|
498
|
+
reply(ws, id, { current: pkg.version, latest });
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
function handleSystemUpdate(ws, { id }) {
|
|
503
|
+
const { spawn } = require('child_process');
|
|
504
|
+
const platform = os.platform();
|
|
505
|
+
|
|
506
|
+
// Build an update script that runs after the agent exits
|
|
507
|
+
const script = platform === 'win32'
|
|
508
|
+
? `@echo off
|
|
509
|
+
timeout /t 2 /nobreak >nul
|
|
510
|
+
npm install -g indieclaw-agent@latest
|
|
511
|
+
start "" indieclaw-agent`
|
|
512
|
+
: `#!/bin/bash
|
|
513
|
+
sleep 2
|
|
514
|
+
npm install -g indieclaw-agent@latest
|
|
515
|
+
nohup indieclaw-agent > /tmp/indieclaw-agent.log 2>&1 &`;
|
|
516
|
+
|
|
517
|
+
const ext = platform === 'win32' ? '.bat' : '.sh';
|
|
518
|
+
const scriptPath = path.join(os.tmpdir(), `indieclaw-update${ext}`);
|
|
519
|
+
fs.writeFileSync(scriptPath, script, { mode: 0o755 });
|
|
520
|
+
|
|
521
|
+
const child = platform === 'win32'
|
|
522
|
+
? spawn('cmd', ['/c', scriptPath], { detached: true, stdio: 'ignore', windowsHide: true })
|
|
523
|
+
: spawn('bash', [scriptPath], { detached: true, stdio: 'ignore' });
|
|
524
|
+
child.unref();
|
|
525
|
+
|
|
526
|
+
reply(ws, id, { updating: true });
|
|
527
|
+
|
|
528
|
+
// Give time for the reply to reach the client, then exit
|
|
529
|
+
setTimeout(() => {
|
|
530
|
+
for (const [, term] of terminals) term.kill();
|
|
531
|
+
wss.close();
|
|
532
|
+
process.exit(0);
|
|
533
|
+
}, 500);
|
|
534
|
+
}
|
|
535
|
+
|
|
489
536
|
// --- Cron ---
|
|
490
537
|
function handleCronList(ws, { id }) {
|
|
491
538
|
exec('crontab -l', { timeout: 5000 }, (err, stdout) => {
|