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.
package/dist/index.mjs CHANGED
@@ -284,6 +284,7 @@ var PTYSession = class extends EventEmitter {
284
284
  messageCounter = 0;
285
285
  logger;
286
286
  sessionRules = [];
287
+ _lastBlockingPromptHash = null;
287
288
  id;
288
289
  config;
289
290
  get status() {
@@ -423,25 +424,28 @@ var PTYSession = class extends EventEmitter {
423
424
  this._lastActivityAt = /* @__PURE__ */ new Date();
424
425
  this.outputBuffer += data;
425
426
  this.emit("output", data);
426
- const blockingPrompt = this.detectAndHandleBlockingPrompt();
427
- if (blockingPrompt) {
428
- return;
429
- }
430
- const loginDetection = this.adapter.detectLogin(this.outputBuffer);
431
- if (loginDetection.required && this._status !== "authenticating") {
432
- this._status = "authenticating";
433
- this.emit("login_required", loginDetection.instructions, loginDetection.url);
434
- this.logger.warn(
435
- { sessionId: this.id, loginType: loginDetection.type },
436
- "Login required"
437
- );
438
- return;
439
- }
440
- if (this._status === "starting" && this.adapter.detectReady(this.outputBuffer)) {
427
+ if ((this._status === "starting" || this._status === "authenticating") && this.adapter.detectReady(this.outputBuffer)) {
441
428
  this._status = "ready";
429
+ this._lastBlockingPromptHash = null;
442
430
  this.emit("ready");
443
431
  this.logger.info({ sessionId: this.id }, "Session ready");
444
432
  }
433
+ if (this._status !== "ready") {
434
+ const blockingPrompt = this.detectAndHandleBlockingPrompt();
435
+ if (blockingPrompt) {
436
+ return;
437
+ }
438
+ const loginDetection = this.adapter.detectLogin(this.outputBuffer);
439
+ if (loginDetection.required && this._status !== "authenticating") {
440
+ this._status = "authenticating";
441
+ this.emit("login_required", loginDetection.instructions, loginDetection.url);
442
+ this.logger.warn(
443
+ { sessionId: this.id, loginType: loginDetection.type },
444
+ "Login required"
445
+ );
446
+ return;
447
+ }
448
+ }
445
449
  const exitDetection = this.adapter.detectExit(this.outputBuffer);
446
450
  if (exitDetection.exited) {
447
451
  this._status = "stopped";
@@ -461,7 +465,8 @@ var PTYSession = class extends EventEmitter {
461
465
  });
462
466
  }
463
467
  /**
464
- * Detect blocking prompts and handle them with auto-responses or user notification
468
+ * Detect blocking prompts and handle them with auto-responses or user notification.
469
+ * Deduplicates emissions - won't re-emit the same blocking prompt repeatedly.
465
470
  */
466
471
  detectAndHandleBlockingPrompt() {
467
472
  const autoHandled = this.tryAutoResponse();
@@ -471,6 +476,11 @@ var PTYSession = class extends EventEmitter {
471
476
  if (this.adapter.detectBlockingPrompt) {
472
477
  const detection = this.adapter.detectBlockingPrompt(this.outputBuffer);
473
478
  if (detection.detected) {
479
+ const promptHash = `${detection.type}:${detection.prompt || ""}`;
480
+ if (promptHash === this._lastBlockingPromptHash) {
481
+ return true;
482
+ }
483
+ this._lastBlockingPromptHash = promptHash;
474
484
  const promptInfo = {
475
485
  type: detection.type || "unknown",
476
486
  prompt: detection.prompt,
@@ -489,6 +499,7 @@ var PTYSession = class extends EventEmitter {
489
499
  "Auto-responding to blocking prompt"
490
500
  );
491
501
  this.writeRaw(detection.suggestedResponse + "\r");
502
+ this._lastBlockingPromptHash = null;
492
503
  this.emit("blocking_prompt", promptInfo, true);
493
504
  return true;
494
505
  }
@@ -505,6 +516,8 @@ var PTYSession = class extends EventEmitter {
505
516
  );
506
517
  this.emit("blocking_prompt", promptInfo, false);
507
518
  return true;
519
+ } else {
520
+ this._lastBlockingPromptHash = null;
508
521
  }
509
522
  }
510
523
  return false;