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.mjs CHANGED
@@ -364,6 +364,13 @@ var BunCompatiblePTYManager = class extends EventEmitter {
364
364
  this.resolvePending("list", sessions);
365
365
  break;
366
366
  }
367
+ case "isSessionLoading": {
368
+ this.resolvePending(
369
+ `isSessionLoading:${id}`,
370
+ Boolean(event.loading)
371
+ );
372
+ break;
373
+ }
367
374
  case "rules": {
368
375
  const serializedRules = event.rules;
369
376
  const rules = serializedRules.map((r) => ({
@@ -525,6 +532,33 @@ var BunCompatiblePTYManager = class extends EventEmitter {
525
532
  has(id) {
526
533
  return this.sessions.has(id);
527
534
  }
535
+ /**
536
+ * Whether the adapter currently classifies the session as actively
537
+ * processing work.
538
+ *
539
+ * This round-trips to the worker since the adapter lives in the
540
+ * worker process. Orchestrators (like milady's swarm idle watchdog)
541
+ * should consult this before assuming a session is idle based on
542
+ * output byte diffs — TUIs that redraw their status row in place
543
+ * (Codex's "Working… esc to interrupt") can fool a raw text diff
544
+ * even while the model is actively reasoning.
545
+ *
546
+ * Returns `false` for unknown sessions, adapters that don't
547
+ * implement `detectLoading`, or on IPC errors.
548
+ */
549
+ async isSessionLoading(id) {
550
+ if (!this.sessions.has(id)) return false;
551
+ await this.waitForReady();
552
+ this.sendCommand({ cmd: "isSessionLoading", id });
553
+ try {
554
+ const result = await this.createPending(
555
+ `isSessionLoading:${id}`
556
+ );
557
+ return Boolean(result);
558
+ } catch {
559
+ return false;
560
+ }
561
+ }
528
562
  /**
529
563
  * Subscribe to output from a specific session
530
564
  */
@@ -999,6 +1033,7 @@ var PTYSession = class _PTYSession extends EventEmitter2 {
999
1033
  }
1000
1034
  }
1001
1035
  }
1036
+ adapter;
1002
1037
  ptyProcess = null;
1003
1038
  outputBuffer = "";
1004
1039
  _status = "pending";
@@ -1499,6 +1534,20 @@ var PTYSession = class _PTYSession extends EventEmitter2 {
1499
1534
  );
1500
1535
  }, _PTYSession.TASK_COMPLETE_DEBOUNCE_MS);
1501
1536
  }
1537
+ /**
1538
+ * Whether the adapter's `detectLoading()` currently classifies the
1539
+ * session as actively processing work.
1540
+ *
1541
+ * This wraps `adapter.detectLoading(outputBuffer)` for consumers outside
1542
+ * the PTY layer (e.g. milady's swarm idle watchdog) that need a
1543
+ * reliable "is the agent busy right now?" signal without reimplementing
1544
+ * heuristics over raw terminal output.
1545
+ *
1546
+ * Returns `false` if the adapter does not implement `detectLoading`.
1547
+ */
1548
+ isLoading() {
1549
+ return this.adapter.detectLoading?.(this.outputBuffer) ?? false;
1550
+ }
1502
1551
  /**
1503
1552
  * Adapter-level task completion check with compatibility fallback.
1504
1553
  * Prefer detectTaskComplete() because detectReady() may be broad for TUIs.
@@ -2515,6 +2564,20 @@ var PTYManager = class extends EventEmitter3 {
2515
2564
  getSession(sessionId) {
2516
2565
  return this.sessions.get(sessionId);
2517
2566
  }
2567
+ /**
2568
+ * Whether the adapter currently classifies the session as actively
2569
+ * processing work (e.g. Codex's "esc to interrupt" status row).
2570
+ *
2571
+ * Orchestrators (like milady's swarm idle watchdog) should consult
2572
+ * this before assuming a session is idle based on output byte diffs,
2573
+ * which are fooled by TUIs that redraw the same status row in place.
2574
+ *
2575
+ * Returns `false` for unknown sessions or adapters that don't
2576
+ * implement `detectLoading`.
2577
+ */
2578
+ isSessionLoading(sessionId) {
2579
+ return this.sessions.get(sessionId)?.isLoading() ?? false;
2580
+ }
2518
2581
  // ─────────────────────────────────────────────────────────────────────────────
2519
2582
  // Stall Detection Configuration
2520
2583
  // ─────────────────────────────────────────────────────────────────────────────