@dmsdc-ai/aigentry-telepty 0.1.31 → 0.1.33

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 +50 -13
  2. package/package.json +1 -1
package/daemon.js CHANGED
@@ -414,24 +414,61 @@ function submitViaPty(session) {
414
414
  }
415
415
 
416
416
  // Send text directly to Kitty tab via remote control (bypasses allow bridge entirely)
417
- function sendViaKitty(sessionId, text) {
417
+ function findKittySocket() {
418
+ try {
419
+ const files = require('fs').readdirSync('/tmp').filter(f => f.startsWith('kitty-sock'));
420
+ return files.length > 0 ? '/tmp/' + files[0] : null;
421
+ } catch { return null; }
422
+ }
423
+
424
+ function findKittyWindowId(socket, sessionId) {
418
425
  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
426
  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 */ }
427
+ const raw = execSync(`kitty @ --to unix:${socket} ls`, { timeout: 3000, encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] });
428
+ const data = JSON.parse(raw);
429
+ for (const osw of data) {
430
+ for (const tab of osw.tabs) {
431
+ for (const w of tab.windows) {
432
+ const cmds = (w.foreground_processes || []).map(p => (p.cmdline || []).join(' ')).join(' ');
433
+ // Check full process tree cmdline for session ID
434
+ if (cmds.includes(sessionId)) return w.id;
435
+ // Also check the window's own cmdline/title
436
+ const allCmds = JSON.stringify(w);
437
+ if (allCmds.includes(sessionId)) return w.id;
438
+ }
439
+ }
440
+ }
441
+ } catch {}
442
+ return null;
443
+ }
444
+
445
+ function sendViaKitty(sessionId, text) {
446
+ const { execSync } = require('child_process');
447
+ const socket = findKittySocket();
426
448
  if (!socket) return false;
427
449
 
450
+ const windowId = findKittyWindowId(socket, sessionId);
451
+ if (!windowId) {
452
+ console.error(`[KITTY] No window found for ${sessionId}`);
453
+ return false;
454
+ }
455
+
428
456
  try {
429
- // Match by cmdline containing session ID (works even when CLI overwrites tab title)
430
- const escaped = text.replace(/\\/g, '\\\\').replace(/'/g, "'\\''");
431
- execSync(`kitty @ --to unix:${socket} send-text --match cmdline:${sessionId} '${escaped}'`, {
432
- timeout: 3000, stdio: ['pipe', 'pipe', 'pipe']
433
- });
434
- console.log(`[KITTY] Sent ${text.length} chars to ${sessionId}`);
457
+ // Split text and CR send-text for content, send-key for Enter
458
+ const hasCr = text.endsWith('\r') || text.endsWith('\n');
459
+ const textOnly = hasCr ? text.slice(0, -1) : text;
460
+ if (textOnly.length > 0) {
461
+ const escaped = textOnly.replace(/\\/g, '\\\\').replace(/'/g, "'\\''");
462
+ execSync(`kitty @ --to unix:${socket} send-text --match id:${windowId} '${escaped}'`, {
463
+ timeout: 3000, stdio: ['pipe', 'pipe', 'pipe']
464
+ });
465
+ }
466
+ if (hasCr) {
467
+ execSync(`kitty @ --to unix:${socket} send-key --match id:${windowId} Return`, {
468
+ timeout: 3000, stdio: ['pipe', 'pipe', 'pipe']
469
+ });
470
+ }
471
+ console.log(`[KITTY] Sent ${textOnly.length} chars${hasCr ? ' + Return' : ''} to ${sessionId} (window ${windowId})`);
435
472
  return true;
436
473
  } catch (err) {
437
474
  console.error(`[KITTY] Failed for ${sessionId}:`, err.message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dmsdc-ai/aigentry-telepty",
3
- "version": "0.1.31",
3
+ "version": "0.1.33",
4
4
  "main": "daemon.js",
5
5
  "bin": {
6
6
  "aigentry-telepty": "install.js",