pty-manager 1.2.8 → 1.2.9

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.
@@ -305,6 +305,7 @@ var PTYSession = class extends import_events.EventEmitter {
305
305
  messageCounter = 0;
306
306
  logger;
307
307
  sessionRules = [];
308
+ _lastBlockingPromptHash = null;
308
309
  id;
309
310
  config;
310
311
  get status() {
@@ -444,25 +445,28 @@ var PTYSession = class extends import_events.EventEmitter {
444
445
  this._lastActivityAt = /* @__PURE__ */ new Date();
445
446
  this.outputBuffer += data;
446
447
  this.emit("output", data);
447
- const blockingPrompt = this.detectAndHandleBlockingPrompt();
448
- if (blockingPrompt) {
449
- return;
450
- }
451
- const loginDetection = this.adapter.detectLogin(this.outputBuffer);
452
- if (loginDetection.required && this._status !== "authenticating") {
453
- this._status = "authenticating";
454
- this.emit("login_required", loginDetection.instructions, loginDetection.url);
455
- this.logger.warn(
456
- { sessionId: this.id, loginType: loginDetection.type },
457
- "Login required"
458
- );
459
- return;
460
- }
461
- if (this._status === "starting" && this.adapter.detectReady(this.outputBuffer)) {
448
+ if ((this._status === "starting" || this._status === "authenticating") && this.adapter.detectReady(this.outputBuffer)) {
462
449
  this._status = "ready";
450
+ this._lastBlockingPromptHash = null;
463
451
  this.emit("ready");
464
452
  this.logger.info({ sessionId: this.id }, "Session ready");
465
453
  }
454
+ if (this._status !== "ready") {
455
+ const blockingPrompt = this.detectAndHandleBlockingPrompt();
456
+ if (blockingPrompt) {
457
+ return;
458
+ }
459
+ const loginDetection = this.adapter.detectLogin(this.outputBuffer);
460
+ if (loginDetection.required && this._status !== "authenticating") {
461
+ this._status = "authenticating";
462
+ this.emit("login_required", loginDetection.instructions, loginDetection.url);
463
+ this.logger.warn(
464
+ { sessionId: this.id, loginType: loginDetection.type },
465
+ "Login required"
466
+ );
467
+ return;
468
+ }
469
+ }
466
470
  const exitDetection = this.adapter.detectExit(this.outputBuffer);
467
471
  if (exitDetection.exited) {
468
472
  this._status = "stopped";
@@ -482,7 +486,8 @@ var PTYSession = class extends import_events.EventEmitter {
482
486
  });
483
487
  }
484
488
  /**
485
- * Detect blocking prompts and handle them with auto-responses or user notification
489
+ * Detect blocking prompts and handle them with auto-responses or user notification.
490
+ * Deduplicates emissions - won't re-emit the same blocking prompt repeatedly.
486
491
  */
487
492
  detectAndHandleBlockingPrompt() {
488
493
  const autoHandled = this.tryAutoResponse();
@@ -492,6 +497,11 @@ var PTYSession = class extends import_events.EventEmitter {
492
497
  if (this.adapter.detectBlockingPrompt) {
493
498
  const detection = this.adapter.detectBlockingPrompt(this.outputBuffer);
494
499
  if (detection.detected) {
500
+ const promptHash = `${detection.type}:${detection.prompt || ""}`;
501
+ if (promptHash === this._lastBlockingPromptHash) {
502
+ return true;
503
+ }
504
+ this._lastBlockingPromptHash = promptHash;
495
505
  const promptInfo = {
496
506
  type: detection.type || "unknown",
497
507
  prompt: detection.prompt,
@@ -510,6 +520,7 @@ var PTYSession = class extends import_events.EventEmitter {
510
520
  "Auto-responding to blocking prompt"
511
521
  );
512
522
  this.writeRaw(detection.suggestedResponse + "\r");
523
+ this._lastBlockingPromptHash = null;
513
524
  this.emit("blocking_prompt", promptInfo, true);
514
525
  return true;
515
526
  }
@@ -526,6 +537,8 @@ var PTYSession = class extends import_events.EventEmitter {
526
537
  );
527
538
  this.emit("blocking_prompt", promptInfo, false);
528
539
  return true;
540
+ } else {
541
+ this._lastBlockingPromptHash = null;
529
542
  }
530
543
  }
531
544
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pty-manager",
3
- "version": "1.2.8",
3
+ "version": "1.2.9",
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",