@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.
Files changed (2) hide show
  1. package/daemon.js +60 -17
  2. 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 (!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
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
- 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'}`);
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: 'osascript_enter' };
585
- } else {
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');
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.29",
4
4
  "main": "daemon.js",
5
5
  "bin": {
6
6
  "aigentry-telepty": "install.js",