pty-manager 1.2.17 → 1.2.18

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.
@@ -307,6 +307,7 @@ var PTYSession = class extends import_events.EventEmitter {
307
307
  messageCounter = 0;
308
308
  logger;
309
309
  sessionRules = [];
310
+ _firedOnceRules = /* @__PURE__ */ new Set();
310
311
  _lastBlockingPromptHash = null;
311
312
  // Stall detection
312
313
  _stallTimer = null;
@@ -413,7 +414,7 @@ var PTYSession = class extends import_events.EventEmitter {
413
414
  return;
414
415
  }
415
416
  const tail = this.outputBuffer.slice(-500);
416
- const stripped = this.stripAnsiForStall(tail);
417
+ const stripped = this.stripAnsiForStall(tail).trim();
417
418
  const hash = this.simpleHash(stripped);
418
419
  if (hash === this._lastContentHash) {
419
420
  return;
@@ -483,12 +484,19 @@ var PTYSession = class extends import_events.EventEmitter {
483
484
  return hash.toString(36);
484
485
  }
485
486
  /**
486
- * Strip ANSI codes for stall detection output.
487
- * Replaces cursor-forward sequences with spaces first.
487
+ * Strip ANSI codes, cursor movement, box-drawing, and spinner characters.
488
+ * Used for stall detection hashing and auto-response pattern matching.
489
+ *
490
+ * Cursor movement codes are replaced with spaces (not removed) to preserve
491
+ * word boundaries — e.g. "Do\x1b[5Cyou" becomes "Do you", not "Doyou".
488
492
  */
489
493
  stripAnsiForStall(str) {
490
- const withSpaces = str.replace(/\x1b\[\d*C/g, " ");
491
- return withSpaces.replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "");
494
+ let result = str.replace(/\x1b\[\d*[CDABG]/g, " ");
495
+ result = result.replace(/\x1b\[\d*(?:;\d+)?[Hf]/g, " ");
496
+ result = result.replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "");
497
+ result = result.replace(/[│╭╰╮╯─═╌║╔╗╚╝╠╣╦╩╬┌┐└┘├┤┬┴┼●○❯❮▶◀⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏⣾⣽⣻⢿⡿⣟⣯⣷✻✶✳✢⏺←→↑↓]/g, " ");
498
+ result = result.replace(/ {2,}/g, " ");
499
+ return result;
492
500
  }
493
501
  /**
494
502
  * Handle external stall classification result.
@@ -724,10 +732,14 @@ var PTYSession = class extends import_events.EventEmitter {
724
732
  if (allRules.length === 0) {
725
733
  return false;
726
734
  }
727
- let stripped = this.stripAnsiForStall(this.outputBuffer);
728
- stripped = stripped.replace(/[│╭╰╮╯─═╌║╔╗╚╝╠╣╦╩╬┌┐└┘├┤┬┴┼●○❯❮▶◀⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏⏺←→↑↓]/g, " ");
729
- stripped = stripped.replace(/ {2,}/g, " ");
735
+ const stripped = this.stripAnsiForStall(this.outputBuffer);
730
736
  for (const rule of allRules) {
737
+ if (rule.once) {
738
+ const ruleKey = `${rule.pattern.source}:${rule.pattern.flags}`;
739
+ if (this._firedOnceRules.has(ruleKey)) {
740
+ continue;
741
+ }
742
+ }
731
743
  if (rule.pattern.test(stripped)) {
732
744
  const safe = rule.safe !== false;
733
745
  const isSessionRule = this.sessionRules.includes(rule);
@@ -751,6 +763,10 @@ var PTYSession = class extends import_events.EventEmitter {
751
763
  } else {
752
764
  this.writeRaw(rule.response + "\r");
753
765
  }
766
+ if (rule.once) {
767
+ const ruleKey = `${rule.pattern.source}:${rule.pattern.flags}`;
768
+ this._firedOnceRules.add(ruleKey);
769
+ }
754
770
  this.outputBuffer = this.outputBuffer.replace(rule.pattern, "");
755
771
  const promptInfo = {
756
772
  type: rule.type,
@@ -1620,7 +1636,8 @@ function deserializeRule(serialized) {
1620
1636
  responseType: serialized.responseType,
1621
1637
  keys: serialized.keys,
1622
1638
  description: serialized.description,
1623
- safe: serialized.safe
1639
+ safe: serialized.safe,
1640
+ once: serialized.once
1624
1641
  };
1625
1642
  }
1626
1643
  function serializeRule(rule) {
@@ -1632,7 +1649,8 @@ function serializeRule(rule) {
1632
1649
  responseType: rule.responseType,
1633
1650
  keys: rule.keys,
1634
1651
  description: rule.description,
1635
- safe: rule.safe
1652
+ safe: rule.safe,
1653
+ once: rule.once
1636
1654
  };
1637
1655
  }
1638
1656
  function handleAddRule(id, serializedRule) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pty-manager",
3
- "version": "1.2.17",
3
+ "version": "1.2.18",
4
4
  "description": "PTY session manager with lifecycle management, pluggable adapters, and blocking prompt detection",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",