@dmsdc-ai/aigentry-telepty 0.1.94 → 0.1.96

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 +38 -19
  2. package/package.json +1 -1
package/daemon.js CHANGED
@@ -561,11 +561,9 @@ async function deliverInjectionToSession(id, session, prompt, options = {}) {
561
561
  return { success: false, ...injectFailure };
562
562
  }
563
563
 
564
- // Build the payload: text + CR for non-aterm sessions (aterm handles Enter internally)
565
- const payload = (!options.noEnter && session.type !== 'aterm')
566
- ? prompt + '\r'
567
- : prompt;
568
-
564
+ // Mailbox payload is TEXT ONLY — CR is sent separately after a delay.
565
+ // Reason: combining text+CR in one write triggers bracketed paste mode in modern
566
+ // terminals. CLIs ignore \r inside paste brackets, so Enter never fires.
569
567
  const from = options.from || 'daemon';
570
568
  const msgId = `${from}:${Date.now()}:${crypto.randomUUID().slice(0, 8)}`;
571
569
 
@@ -574,7 +572,7 @@ async function deliverInjectionToSession(id, session, prompt, options = {}) {
574
572
  msg_id: msgId,
575
573
  from,
576
574
  to: id,
577
- payload,
575
+ payload: prompt,
578
576
  created_at: Math.floor(now / 1000),
579
577
  attempt: 0,
580
578
  });
@@ -584,13 +582,25 @@ async function deliverInjectionToSession(id, session, prompt, options = {}) {
584
582
  mailboxNotifier.notify(id);
585
583
  }
586
584
 
587
- // Deliver synchronously — ensures text is written before inject returns success.
588
- // Mailbox gives us persistence/retry, but the initial delivery must complete
589
- // before the HTTP response so --submit timing and CR delivery are reliable.
585
+ // Deliver text synchronously — ensures text is written before inject returns success.
590
586
  try {
591
587
  await mailboxDelivery.tick();
592
588
  } catch {}
593
589
 
590
+ // Send CR separately after delay (outside paste brackets)
591
+ if (!options.noEnter && session.type !== 'aterm') {
592
+ const submitDelay = session.type === 'wrapped' ? 500 : 300;
593
+ setTimeout(async () => {
594
+ const submitResult = await writeDataToSession(id, session, '\r');
595
+ if (!submitResult.success) {
596
+ emitInjectFailureEvent(id, submitResult.code, submitResult.error, {
597
+ phase: 'submit',
598
+ source: options.source || 'inject'
599
+ }, session);
600
+ }
601
+ }, submitDelay);
602
+ }
603
+
594
604
  session.lastActivityAt = new Date(now).toISOString();
595
605
  return {
596
606
  success: true,
@@ -598,7 +608,7 @@ async function deliverInjectionToSession(id, session, prompt, options = {}) {
598
608
  queued: ack.queued,
599
609
  pending: ack.pending,
600
610
  strategy: 'mailbox',
601
- submit: options.noEnter ? 'skipped' : 'included'
611
+ submit: options.noEnter ? 'skipped' : 'deferred'
602
612
  };
603
613
  } catch (err) {
604
614
  console.error(`[MAILBOX] Enqueue failed for ${id}: ${err.message}`);
@@ -1567,15 +1577,24 @@ app.get('/api/sessions/:id/screen', (req, res) => {
1567
1577
  // Strip ANSI escape sequences for clean text
1568
1578
  function stripAnsi(str) {
1569
1579
  return str
1570
- .replace(/[[0-9;]*[a-zA-Z]/g, '') // CSI sequences
1571
- .replace(/][^]*/g, '') // OSC sequences (BEL terminated)
1572
- .replace(/][^]*\\/g, '') // OSC sequences (ST terminated)
1573
- .replace(/[()][AB012]/g, '') // Character set selection
1574
- .replace(/[>=<]/g, '') // Keypad mode
1575
- .replace(/[[?]?[0-9;]*[hlsurm]/g, '') // Mode set/reset
1576
- .replace(/[[0-9;]*[ABCDHJ]/g, '') // Cursor movement
1577
- .replace(/[[0-9;]*[KG]/g, '') // Line clearing
1578
- .replace(/\r/g, ''); // Carriage returns
1580
+ // Replace cursor-forward (ESC[NC, ESC[C) with N spaces to preserve whitespace
1581
+ .replace(/\[(\d*)C/g, (_, n) => ' '.repeat(Number(n) || 1))
1582
+ // CSI sequences: ESC [ ? (optional) params final_byte
1583
+ .replace(/\[\??[0-9;]*[a-zA-Z@`]/g, '')
1584
+ // OSC sequences: ESC ] ... BEL
1585
+ .replace(/\][^]*/g, '')
1586
+ // OSC sequences: ESC ] ... ST (ESC \)
1587
+ .replace(/\][^]*\\/g, '')
1588
+ // Character set selection: ESC ( / ) + charset
1589
+ .replace(/[()][AB012]/g, '')
1590
+ // Keypad and other 2-char ESC sequences
1591
+ .replace(/[>=<78DMEHcNOZ~}|]/g, '')
1592
+ // DCS / PM / APC sequences
1593
+ .replace(/^_][^]*\\/g, '')
1594
+ // Any remaining bare ESC + single char
1595
+ .replace(/./g, '')
1596
+ // Carriage returns
1597
+ .replace(/\r/g, '');
1579
1598
  }
1580
1599
 
1581
1600
  const cleaned = raw ? fullOutput : stripAnsi(fullOutput);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dmsdc-ai/aigentry-telepty",
3
- "version": "0.1.94",
3
+ "version": "0.1.96",
4
4
  "main": "daemon.js",
5
5
  "bin": {
6
6
  "aigentry-telepty": "install.js",