pty-manager 1.10.2 → 1.11.1

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
@@ -312,6 +312,21 @@ declare class BunCompatiblePTYManager extends EventEmitter {
312
312
  * Check if a session exists
313
313
  */
314
314
  has(id: string): boolean;
315
+ /**
316
+ * Whether the adapter currently classifies the session as actively
317
+ * processing work.
318
+ *
319
+ * This round-trips to the worker since the adapter lives in the
320
+ * worker process. Orchestrators (like milady's swarm idle watchdog)
321
+ * should consult this before assuming a session is idle based on
322
+ * output byte diffs — TUIs that redraw their status row in place
323
+ * (Codex's "Working… esc to interrupt") can fool a raw text diff
324
+ * even while the model is actively reasoning.
325
+ *
326
+ * Returns `false` for unknown sessions, adapters that don't
327
+ * implement `detectLoading`, or on IPC errors.
328
+ */
329
+ isSessionLoading(id: string): Promise<boolean>;
315
330
  /**
316
331
  * Subscribe to output from a specific session
317
332
  */
@@ -536,6 +551,18 @@ declare class PTYSession extends EventEmitter {
536
551
  * signal before transitioning, so stale triggers are safe.
537
552
  */
538
553
  private scheduleTaskComplete;
554
+ /**
555
+ * Whether the adapter's `detectLoading()` currently classifies the
556
+ * session as actively processing work.
557
+ *
558
+ * This wraps `adapter.detectLoading(outputBuffer)` for consumers outside
559
+ * the PTY layer (e.g. milady's swarm idle watchdog) that need a
560
+ * reliable "is the agent busy right now?" signal without reimplementing
561
+ * heuristics over raw terminal output.
562
+ *
563
+ * Returns `false` if the adapter does not implement `detectLoading`.
564
+ */
565
+ isLoading(): boolean;
539
566
  /**
540
567
  * Adapter-level task completion check with compatibility fallback.
541
568
  * Prefer detectTaskComplete() because detectReady() may be broad for TUIs.
@@ -780,6 +807,18 @@ declare class PTYManager extends EventEmitter {
780
807
  * Get the underlying PTYSession (for advanced use)
781
808
  */
782
809
  getSession(sessionId: string): PTYSession | undefined;
810
+ /**
811
+ * Whether the adapter currently classifies the session as actively
812
+ * processing work (e.g. Codex's "esc to interrupt" status row).
813
+ *
814
+ * Orchestrators (like milady's swarm idle watchdog) should consult
815
+ * this before assuming a session is idle based on output byte diffs,
816
+ * which are fooled by TUIs that redraw the same status row in place.
817
+ *
818
+ * Returns `false` for unknown sessions or adapters that don't
819
+ * implement `detectLoading`.
820
+ */
821
+ isSessionLoading(sessionId: string): boolean;
783
822
  /**
784
823
  * Configure stall detection at runtime.
785
824
  * Affects newly spawned sessions only — existing sessions keep their config.
package/dist/index.d.ts CHANGED
@@ -312,6 +312,21 @@ declare class BunCompatiblePTYManager extends EventEmitter {
312
312
  * Check if a session exists
313
313
  */
314
314
  has(id: string): boolean;
315
+ /**
316
+ * Whether the adapter currently classifies the session as actively
317
+ * processing work.
318
+ *
319
+ * This round-trips to the worker since the adapter lives in the
320
+ * worker process. Orchestrators (like milady's swarm idle watchdog)
321
+ * should consult this before assuming a session is idle based on
322
+ * output byte diffs — TUIs that redraw their status row in place
323
+ * (Codex's "Working… esc to interrupt") can fool a raw text diff
324
+ * even while the model is actively reasoning.
325
+ *
326
+ * Returns `false` for unknown sessions, adapters that don't
327
+ * implement `detectLoading`, or on IPC errors.
328
+ */
329
+ isSessionLoading(id: string): Promise<boolean>;
315
330
  /**
316
331
  * Subscribe to output from a specific session
317
332
  */
@@ -536,6 +551,18 @@ declare class PTYSession extends EventEmitter {
536
551
  * signal before transitioning, so stale triggers are safe.
537
552
  */
538
553
  private scheduleTaskComplete;
554
+ /**
555
+ * Whether the adapter's `detectLoading()` currently classifies the
556
+ * session as actively processing work.
557
+ *
558
+ * This wraps `adapter.detectLoading(outputBuffer)` for consumers outside
559
+ * the PTY layer (e.g. milady's swarm idle watchdog) that need a
560
+ * reliable "is the agent busy right now?" signal without reimplementing
561
+ * heuristics over raw terminal output.
562
+ *
563
+ * Returns `false` if the adapter does not implement `detectLoading`.
564
+ */
565
+ isLoading(): boolean;
539
566
  /**
540
567
  * Adapter-level task completion check with compatibility fallback.
541
568
  * Prefer detectTaskComplete() because detectReady() may be broad for TUIs.
@@ -780,6 +807,18 @@ declare class PTYManager extends EventEmitter {
780
807
  * Get the underlying PTYSession (for advanced use)
781
808
  */
782
809
  getSession(sessionId: string): PTYSession | undefined;
810
+ /**
811
+ * Whether the adapter currently classifies the session as actively
812
+ * processing work (e.g. Codex's "esc to interrupt" status row).
813
+ *
814
+ * Orchestrators (like milady's swarm idle watchdog) should consult
815
+ * this before assuming a session is idle based on output byte diffs,
816
+ * which are fooled by TUIs that redraw the same status row in place.
817
+ *
818
+ * Returns `false` for unknown sessions or adapters that don't
819
+ * implement `detectLoading`.
820
+ */
821
+ isSessionLoading(sessionId: string): boolean;
783
822
  /**
784
823
  * Configure stall detection at runtime.
785
824
  * Affects newly spawned sessions only — existing sessions keep their config.
package/dist/index.js CHANGED
@@ -405,6 +405,13 @@ var BunCompatiblePTYManager = class extends import_node_events.EventEmitter {
405
405
  this.resolvePending("list", sessions);
406
406
  break;
407
407
  }
408
+ case "isSessionLoading": {
409
+ this.resolvePending(
410
+ `isSessionLoading:${id}`,
411
+ Boolean(event.loading)
412
+ );
413
+ break;
414
+ }
408
415
  case "rules": {
409
416
  const serializedRules = event.rules;
410
417
  const rules = serializedRules.map((r) => ({
@@ -566,6 +573,33 @@ var BunCompatiblePTYManager = class extends import_node_events.EventEmitter {
566
573
  has(id) {
567
574
  return this.sessions.has(id);
568
575
  }
576
+ /**
577
+ * Whether the adapter currently classifies the session as actively
578
+ * processing work.
579
+ *
580
+ * This round-trips to the worker since the adapter lives in the
581
+ * worker process. Orchestrators (like milady's swarm idle watchdog)
582
+ * should consult this before assuming a session is idle based on
583
+ * output byte diffs — TUIs that redraw their status row in place
584
+ * (Codex's "Working… esc to interrupt") can fool a raw text diff
585
+ * even while the model is actively reasoning.
586
+ *
587
+ * Returns `false` for unknown sessions, adapters that don't
588
+ * implement `detectLoading`, or on IPC errors.
589
+ */
590
+ async isSessionLoading(id) {
591
+ if (!this.sessions.has(id)) return false;
592
+ await this.waitForReady();
593
+ this.sendCommand({ cmd: "isSessionLoading", id });
594
+ try {
595
+ const result = await this.createPending(
596
+ `isSessionLoading:${id}`
597
+ );
598
+ return Boolean(result);
599
+ } catch {
600
+ return false;
601
+ }
602
+ }
569
603
  /**
570
604
  * Subscribe to output from a specific session
571
605
  */
@@ -1040,6 +1074,7 @@ var PTYSession = class _PTYSession extends import_node_events2.EventEmitter {
1040
1074
  }
1041
1075
  }
1042
1076
  }
1077
+ adapter;
1043
1078
  ptyProcess = null;
1044
1079
  outputBuffer = "";
1045
1080
  _status = "pending";
@@ -1540,6 +1575,20 @@ var PTYSession = class _PTYSession extends import_node_events2.EventEmitter {
1540
1575
  );
1541
1576
  }, _PTYSession.TASK_COMPLETE_DEBOUNCE_MS);
1542
1577
  }
1578
+ /**
1579
+ * Whether the adapter's `detectLoading()` currently classifies the
1580
+ * session as actively processing work.
1581
+ *
1582
+ * This wraps `adapter.detectLoading(outputBuffer)` for consumers outside
1583
+ * the PTY layer (e.g. milady's swarm idle watchdog) that need a
1584
+ * reliable "is the agent busy right now?" signal without reimplementing
1585
+ * heuristics over raw terminal output.
1586
+ *
1587
+ * Returns `false` if the adapter does not implement `detectLoading`.
1588
+ */
1589
+ isLoading() {
1590
+ return this.adapter.detectLoading?.(this.outputBuffer) ?? false;
1591
+ }
1543
1592
  /**
1544
1593
  * Adapter-level task completion check with compatibility fallback.
1545
1594
  * Prefer detectTaskComplete() because detectReady() may be broad for TUIs.
@@ -2556,6 +2605,20 @@ var PTYManager = class extends import_node_events3.EventEmitter {
2556
2605
  getSession(sessionId) {
2557
2606
  return this.sessions.get(sessionId);
2558
2607
  }
2608
+ /**
2609
+ * Whether the adapter currently classifies the session as actively
2610
+ * processing work (e.g. Codex's "esc to interrupt" status row).
2611
+ *
2612
+ * Orchestrators (like milady's swarm idle watchdog) should consult
2613
+ * this before assuming a session is idle based on output byte diffs,
2614
+ * which are fooled by TUIs that redraw the same status row in place.
2615
+ *
2616
+ * Returns `false` for unknown sessions or adapters that don't
2617
+ * implement `detectLoading`.
2618
+ */
2619
+ isSessionLoading(sessionId) {
2620
+ return this.sessions.get(sessionId)?.isLoading() ?? false;
2621
+ }
2559
2622
  // ─────────────────────────────────────────────────────────────────────────────
2560
2623
  // Stall Detection Configuration
2561
2624
  // ─────────────────────────────────────────────────────────────────────────────