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.d.mts CHANGED
@@ -380,6 +380,7 @@ declare class PTYSession extends EventEmitter {
380
380
  private messageCounter;
381
381
  private logger;
382
382
  private sessionRules;
383
+ private _lastBlockingPromptHash;
383
384
  readonly id: string;
384
385
  readonly config: SpawnConfig;
385
386
  constructor(adapter: CLIAdapter, config: SpawnConfig, logger?: Logger);
@@ -418,7 +419,8 @@ declare class PTYSession extends EventEmitter {
418
419
  */
419
420
  private setupEventHandlers;
420
421
  /**
421
- * Detect blocking prompts and handle them with auto-responses or user notification
422
+ * Detect blocking prompts and handle them with auto-responses or user notification.
423
+ * Deduplicates emissions - won't re-emit the same blocking prompt repeatedly.
422
424
  */
423
425
  private detectAndHandleBlockingPrompt;
424
426
  /**
package/dist/index.d.ts CHANGED
@@ -380,6 +380,7 @@ declare class PTYSession extends EventEmitter {
380
380
  private messageCounter;
381
381
  private logger;
382
382
  private sessionRules;
383
+ private _lastBlockingPromptHash;
383
384
  readonly id: string;
384
385
  readonly config: SpawnConfig;
385
386
  constructor(adapter: CLIAdapter, config: SpawnConfig, logger?: Logger);
@@ -418,7 +419,8 @@ declare class PTYSession extends EventEmitter {
418
419
  */
419
420
  private setupEventHandlers;
420
421
  /**
421
- * Detect blocking prompts and handle them with auto-responses or user notification
422
+ * Detect blocking prompts and handle them with auto-responses or user notification.
423
+ * Deduplicates emissions - won't re-emit the same blocking prompt repeatedly.
422
424
  */
423
425
  private detectAndHandleBlockingPrompt;
424
426
  /**
package/dist/index.js CHANGED
@@ -322,6 +322,7 @@ var PTYSession = class extends import_events.EventEmitter {
322
322
  messageCounter = 0;
323
323
  logger;
324
324
  sessionRules = [];
325
+ _lastBlockingPromptHash = null;
325
326
  id;
326
327
  config;
327
328
  get status() {
@@ -461,25 +462,28 @@ var PTYSession = class extends import_events.EventEmitter {
461
462
  this._lastActivityAt = /* @__PURE__ */ new Date();
462
463
  this.outputBuffer += data;
463
464
  this.emit("output", data);
464
- const blockingPrompt = this.detectAndHandleBlockingPrompt();
465
- if (blockingPrompt) {
466
- return;
467
- }
468
- const loginDetection = this.adapter.detectLogin(this.outputBuffer);
469
- if (loginDetection.required && this._status !== "authenticating") {
470
- this._status = "authenticating";
471
- this.emit("login_required", loginDetection.instructions, loginDetection.url);
472
- this.logger.warn(
473
- { sessionId: this.id, loginType: loginDetection.type },
474
- "Login required"
475
- );
476
- return;
477
- }
478
- if (this._status === "starting" && this.adapter.detectReady(this.outputBuffer)) {
465
+ if ((this._status === "starting" || this._status === "authenticating") && this.adapter.detectReady(this.outputBuffer)) {
479
466
  this._status = "ready";
467
+ this._lastBlockingPromptHash = null;
480
468
  this.emit("ready");
481
469
  this.logger.info({ sessionId: this.id }, "Session ready");
482
470
  }
471
+ if (this._status !== "ready") {
472
+ const blockingPrompt = this.detectAndHandleBlockingPrompt();
473
+ if (blockingPrompt) {
474
+ return;
475
+ }
476
+ const loginDetection = this.adapter.detectLogin(this.outputBuffer);
477
+ if (loginDetection.required && this._status !== "authenticating") {
478
+ this._status = "authenticating";
479
+ this.emit("login_required", loginDetection.instructions, loginDetection.url);
480
+ this.logger.warn(
481
+ { sessionId: this.id, loginType: loginDetection.type },
482
+ "Login required"
483
+ );
484
+ return;
485
+ }
486
+ }
483
487
  const exitDetection = this.adapter.detectExit(this.outputBuffer);
484
488
  if (exitDetection.exited) {
485
489
  this._status = "stopped";
@@ -499,7 +503,8 @@ var PTYSession = class extends import_events.EventEmitter {
499
503
  });
500
504
  }
501
505
  /**
502
- * Detect blocking prompts and handle them with auto-responses or user notification
506
+ * Detect blocking prompts and handle them with auto-responses or user notification.
507
+ * Deduplicates emissions - won't re-emit the same blocking prompt repeatedly.
503
508
  */
504
509
  detectAndHandleBlockingPrompt() {
505
510
  const autoHandled = this.tryAutoResponse();
@@ -509,6 +514,11 @@ var PTYSession = class extends import_events.EventEmitter {
509
514
  if (this.adapter.detectBlockingPrompt) {
510
515
  const detection = this.adapter.detectBlockingPrompt(this.outputBuffer);
511
516
  if (detection.detected) {
517
+ const promptHash = `${detection.type}:${detection.prompt || ""}`;
518
+ if (promptHash === this._lastBlockingPromptHash) {
519
+ return true;
520
+ }
521
+ this._lastBlockingPromptHash = promptHash;
512
522
  const promptInfo = {
513
523
  type: detection.type || "unknown",
514
524
  prompt: detection.prompt,
@@ -527,6 +537,7 @@ var PTYSession = class extends import_events.EventEmitter {
527
537
  "Auto-responding to blocking prompt"
528
538
  );
529
539
  this.writeRaw(detection.suggestedResponse + "\r");
540
+ this._lastBlockingPromptHash = null;
530
541
  this.emit("blocking_prompt", promptInfo, true);
531
542
  return true;
532
543
  }
@@ -543,6 +554,8 @@ var PTYSession = class extends import_events.EventEmitter {
543
554
  );
544
555
  this.emit("blocking_prompt", promptInfo, false);
545
556
  return true;
557
+ } else {
558
+ this._lastBlockingPromptHash = null;
546
559
  }
547
560
  }
548
561
  return false;