@dmsdc-ai/aigentry-telepty 0.0.14 → 0.0.15
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/cli.js +20 -8
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -27,7 +27,27 @@ const fetchWithAuth = (url, options = {}) => {
|
|
|
27
27
|
return fetch(url, { ...options, headers });
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
+
async function ensureDaemonRunning() {
|
|
31
|
+
if (REMOTE_HOST !== '127.0.0.1') return; // Only auto-start local daemon
|
|
32
|
+
try {
|
|
33
|
+
const res = await fetchWithAuth(`${DAEMON_URL}/api/sessions`);
|
|
34
|
+
if (res.ok) return; // Already running
|
|
35
|
+
} catch (e) {
|
|
36
|
+
// Not running, let's start it
|
|
37
|
+
process.stdout.write('\x1b[33m⚙️ Auto-starting local telepty daemon...\x1b[0m\n');
|
|
38
|
+
const cp = spawn(process.argv[0], [process.argv[1], 'daemon'], {
|
|
39
|
+
detached: true,
|
|
40
|
+
stdio: 'ignore'
|
|
41
|
+
});
|
|
42
|
+
cp.unref();
|
|
43
|
+
|
|
44
|
+
// Wait a brief moment for the daemon to boot up
|
|
45
|
+
await new Promise(r => setTimeout(r, 1000));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
30
49
|
async function discoverSessions() {
|
|
50
|
+
await ensureDaemonRunning();
|
|
31
51
|
const hosts = ['127.0.0.1'];
|
|
32
52
|
try {
|
|
33
53
|
const tsStatus = execSync('tailscale status --json', { encoding: 'utf8', stdio: ['pipe', 'pipe', 'ignore'] });
|
|
@@ -157,8 +177,6 @@ async function manageInteractive() {
|
|
|
157
177
|
{ type: 'text', name: 'command', message: 'Enter command to run (e.g. bash, zsh, python):', initial: 'bash' }
|
|
158
178
|
]);
|
|
159
179
|
if (!id || !command) continue;
|
|
160
|
-
|
|
161
|
-
await ensureDaemonRunning();
|
|
162
180
|
|
|
163
181
|
const cols = process.stdout.columns || 80;
|
|
164
182
|
const rows = process.stdout.rows || 30;
|
|
@@ -280,7 +298,6 @@ async function main() {
|
|
|
280
298
|
}
|
|
281
299
|
|
|
282
300
|
if (cmd === 'list') {
|
|
283
|
-
await ensureDaemonRunning();
|
|
284
301
|
try {
|
|
285
302
|
const res = await fetchWithAuth(`${DAEMON_URL}/api/sessions`);
|
|
286
303
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
@@ -302,7 +319,6 @@ async function main() {
|
|
|
302
319
|
}
|
|
303
320
|
|
|
304
321
|
if (cmd === 'spawn') {
|
|
305
|
-
await ensureDaemonRunning();
|
|
306
322
|
const idIndex = args.indexOf('--id');
|
|
307
323
|
if (idIndex === -1 || !args[idIndex + 1]) { console.error('❌ Usage: telepty spawn --id <session_id> <command> [args...]'); process.exit(1); }
|
|
308
324
|
const sessionId = args[idIndex + 1];
|
|
@@ -326,7 +342,6 @@ async function main() {
|
|
|
326
342
|
}
|
|
327
343
|
|
|
328
344
|
if (cmd === 'attach') {
|
|
329
|
-
await ensureDaemonRunning();
|
|
330
345
|
let sessionId = args[1];
|
|
331
346
|
let targetHost = REMOTE_HOST;
|
|
332
347
|
|
|
@@ -407,7 +422,6 @@ async function main() {
|
|
|
407
422
|
}
|
|
408
423
|
|
|
409
424
|
if (cmd === 'inject') {
|
|
410
|
-
await ensureDaemonRunning();
|
|
411
425
|
const sessionId = args[1]; const prompt = args.slice(2).join(' ');
|
|
412
426
|
if (!sessionId || !prompt) { console.error('❌ Usage: telepty inject <session_id> "<prompt text>"'); process.exit(1); }
|
|
413
427
|
try {
|
|
@@ -422,7 +436,6 @@ async function main() {
|
|
|
422
436
|
}
|
|
423
437
|
|
|
424
438
|
if (cmd === 'multicast') {
|
|
425
|
-
await ensureDaemonRunning();
|
|
426
439
|
const sessionIdsRaw = args[1]; const prompt = args.slice(2).join(' ');
|
|
427
440
|
if (!sessionIdsRaw || !prompt) { console.error('❌ Usage: telepty multicast <id1,id2,...> "<prompt text>"'); process.exit(1); }
|
|
428
441
|
const sessionIds = sessionIdsRaw.split(',').map(s => s.trim()).filter(s => s);
|
|
@@ -441,7 +454,6 @@ async function main() {
|
|
|
441
454
|
}
|
|
442
455
|
|
|
443
456
|
if (cmd === 'broadcast') {
|
|
444
|
-
await ensureDaemonRunning();
|
|
445
457
|
const prompt = args.slice(1).join(' ');
|
|
446
458
|
if (!prompt) { console.error('❌ Usage: telepty broadcast "<prompt text>"'); process.exit(1); }
|
|
447
459
|
try {
|