pty-manager 1.2.7 → 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,31 +424,36 @@ 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";
448
452
  this.emit("exit", exitDetection.code || 0);
449
453
  }
450
- this.tryParseOutput();
454
+ if (this._status !== "starting" && this._status !== "authenticating") {
455
+ this.tryParseOutput();
456
+ }
451
457
  });
452
458
  this.ptyProcess.onExit(({ exitCode, signal }) => {
453
459
  this._status = "stopped";
@@ -459,7 +465,8 @@ var PTYSession = class extends EventEmitter {
459
465
  });
460
466
  }
461
467
  /**
462
- * 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.
463
470
  */
464
471
  detectAndHandleBlockingPrompt() {
465
472
  const autoHandled = this.tryAutoResponse();
@@ -469,6 +476,11 @@ var PTYSession = class extends EventEmitter {
469
476
  if (this.adapter.detectBlockingPrompt) {
470
477
  const detection = this.adapter.detectBlockingPrompt(this.outputBuffer);
471
478
  if (detection.detected) {
479
+ const promptHash = `${detection.type}:${detection.prompt || ""}`;
480
+ if (promptHash === this._lastBlockingPromptHash) {
481
+ return true;
482
+ }
483
+ this._lastBlockingPromptHash = promptHash;
472
484
  const promptInfo = {
473
485
  type: detection.type || "unknown",
474
486
  prompt: detection.prompt,
@@ -487,6 +499,7 @@ var PTYSession = class extends EventEmitter {
487
499
  "Auto-responding to blocking prompt"
488
500
  );
489
501
  this.writeRaw(detection.suggestedResponse + "\r");
502
+ this._lastBlockingPromptHash = null;
490
503
  this.emit("blocking_prompt", promptInfo, true);
491
504
  return true;
492
505
  }
@@ -503,6 +516,8 @@ var PTYSession = class extends EventEmitter {
503
516
  );
504
517
  this.emit("blocking_prompt", promptInfo, false);
505
518
  return true;
519
+ } else {
520
+ this._lastBlockingPromptHash = null;
506
521
  }
507
522
  }
508
523
  return false;