@dmsdc-ai/aigentry-telepty 0.1.28 → 0.1.30

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