@dmsdc-ai/aigentry-telepty 0.1.28 → 0.1.29
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/daemon.js +60 -17
- package/package.json +1 -1
package/daemon.js
CHANGED
|
@@ -413,6 +413,34 @@ function submitViaPty(session) {
|
|
|
413
413
|
}
|
|
414
414
|
}
|
|
415
415
|
|
|
416
|
+
// Send text directly to Kitty tab via remote control (bypasses allow bridge entirely)
|
|
417
|
+
function sendViaKitty(sessionId, text) {
|
|
418
|
+
const { execSync } = require('child_process');
|
|
419
|
+
const socketPaths = ['/tmp/kitty-sock', `/tmp/kitty-${process.getuid()}`];
|
|
420
|
+
let socket = null;
|
|
421
|
+
for (const p of socketPaths) {
|
|
422
|
+
try {
|
|
423
|
+
require('fs').accessSync(p);
|
|
424
|
+
socket = p;
|
|
425
|
+
break;
|
|
426
|
+
} catch { /* skip */ }
|
|
427
|
+
}
|
|
428
|
+
if (!socket) return false;
|
|
429
|
+
|
|
430
|
+
try {
|
|
431
|
+
// Match by tab title containing session ID
|
|
432
|
+
const escaped = text.replace(/\\/g, '\\\\').replace(/'/g, "'\\''");
|
|
433
|
+
execSync(`kitty @ --to unix:${socket} send-text --match title:${sessionId} '${escaped}'`, {
|
|
434
|
+
timeout: 3000, stdio: ['pipe', 'pipe', 'pipe']
|
|
435
|
+
});
|
|
436
|
+
console.log(`[KITTY] Sent ${text.length} chars to ${sessionId}`);
|
|
437
|
+
return true;
|
|
438
|
+
} catch (err) {
|
|
439
|
+
console.error(`[KITTY] Failed for ${sessionId}:`, err.message);
|
|
440
|
+
return false;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
416
444
|
function submitViaOsascript(sessionId, keyCombo) {
|
|
417
445
|
const { execSync } = require('child_process');
|
|
418
446
|
const session = sessions[sessionId];
|
|
@@ -562,27 +590,42 @@ app.post('/api/sessions/:id/inject', (req, res) => {
|
|
|
562
590
|
}
|
|
563
591
|
|
|
564
592
|
let submitResult = null;
|
|
565
|
-
if (!
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
593
|
+
if (session.type === 'wrapped' && !no_enter) {
|
|
594
|
+
// Wrapped sessions: try kitty remote control first (bypasses allow bridge entirely)
|
|
595
|
+
const kittyPayload = finalPrompt + '\r';
|
|
596
|
+
const kittyOk = sendViaKitty(id, kittyPayload);
|
|
597
|
+
if (kittyOk) {
|
|
598
|
+
submitResult = { strategy: 'kitty_remote' };
|
|
599
|
+
console.log(`[INJECT+SUBMIT] Kitty remote for ${id}`);
|
|
600
|
+
} else {
|
|
601
|
+
// Fallback: WS text + osascript/WS Enter
|
|
602
|
+
if (!writeToSession(finalPrompt)) {
|
|
603
|
+
return res.status(503).json({ error: 'Wrap process is not connected' });
|
|
604
|
+
}
|
|
573
605
|
setTimeout(() => {
|
|
574
|
-
// Try osascript keystroke (works regardless of allow bridge version)
|
|
575
606
|
const osascriptOk = submitViaOsascript(id, 'enter');
|
|
576
|
-
if (osascriptOk) {
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
// Fallback: send \r via WS (works if allow bridge has prompt-ready bypass)
|
|
580
|
-
const wsOk = writeToSession('\r');
|
|
581
|
-
console.log(`[INJECT+SUBMIT] WS \\r fallback for ${id}: ${wsOk ? 'success' : 'failed'}`);
|
|
607
|
+
if (!osascriptOk) {
|
|
608
|
+
writeToSession('\r');
|
|
609
|
+
console.log(`[INJECT+SUBMIT] WS \\r last-resort for ${id}`);
|
|
582
610
|
}
|
|
583
611
|
}, 500);
|
|
584
|
-
submitResult = { deferred: true, strategy: '
|
|
585
|
-
}
|
|
612
|
+
submitResult = { deferred: true, strategy: 'osascript_fallback' };
|
|
613
|
+
}
|
|
614
|
+
} else if (session.type === 'wrapped') {
|
|
615
|
+
// no_enter=true for wrapped
|
|
616
|
+
const kittyOk = sendViaKitty(id, finalPrompt);
|
|
617
|
+
if (!kittyOk) {
|
|
618
|
+
if (!writeToSession(finalPrompt)) {
|
|
619
|
+
return res.status(503).json({ error: 'Wrap process is not connected' });
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
submitResult = { strategy: kittyOk ? 'kitty_remote_no_enter' : 'ws_no_enter' };
|
|
623
|
+
} else {
|
|
624
|
+
if (!writeToSession(finalPrompt)) {
|
|
625
|
+
return res.status(503).json({ error: 'Wrap process is not connected' });
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
if (!no_enter) {
|
|
586
629
|
// Spawned sessions: send \r separately after delay (proven split_cr strategy)
|
|
587
630
|
setTimeout(() => {
|
|
588
631
|
const ok = writeToSession('\r');
|