pty-manager 1.10.2 → 1.11.0

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
  */
@@ -1499,6 +1533,20 @@ var PTYSession = class _PTYSession extends EventEmitter2 {
1499
1533
  );
1500
1534
  }, _PTYSession.TASK_COMPLETE_DEBOUNCE_MS);
1501
1535
  }
1536
+ /**
1537
+ * Whether the adapter's `detectLoading()` currently classifies the
1538
+ * session as actively processing work.
1539
+ *
1540
+ * This wraps `adapter.detectLoading(outputBuffer)` for consumers outside
1541
+ * the PTY layer (e.g. milady's swarm idle watchdog) that need a
1542
+ * reliable "is the agent busy right now?" signal without reimplementing
1543
+ * heuristics over raw terminal output.
1544
+ *
1545
+ * Returns `false` if the adapter does not implement `detectLoading`.
1546
+ */
1547
+ isLoading() {
1548
+ return this.adapter.detectLoading?.(this.outputBuffer) ?? false;
1549
+ }
1502
1550
  /**
1503
1551
  * Adapter-level task completion check with compatibility fallback.
1504
1552
  * Prefer detectTaskComplete() because detectReady() may be broad for TUIs.
@@ -2515,6 +2563,20 @@ var PTYManager = class extends EventEmitter3 {
2515
2563
  getSession(sessionId) {
2516
2564
  return this.sessions.get(sessionId);
2517
2565
  }
2566
+ /**
2567
+ * Whether the adapter currently classifies the session as actively
2568
+ * processing work (e.g. Codex's "esc to interrupt" status row).
2569
+ *
2570
+ * Orchestrators (like milady's swarm idle watchdog) should consult
2571
+ * this before assuming a session is idle based on output byte diffs,
2572
+ * which are fooled by TUIs that redraw the same status row in place.
2573
+ *
2574
+ * Returns `false` for unknown sessions or adapters that don't
2575
+ * implement `detectLoading`.
2576
+ */
2577
+ isSessionLoading(sessionId) {
2578
+ return this.sessions.get(sessionId)?.isLoading() ?? false;
2579
+ }
2518
2580
  // ─────────────────────────────────────────────────────────────────────────────
2519
2581
  // Stall Detection Configuration
2520
2582
  // ─────────────────────────────────────────────────────────────────────────────