litepaseo 0.13.0 → 0.13.2

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.
Files changed (128) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/server/cli.mjs +2 -2
  3. package/dist/server/{worker-Bwnvw5NC.mjs → worker-C-KgOZ4j.mjs} +329 -404
  4. package/dist/web/assets/{AddProjectDialog-_MWmro5G.js → AddProjectDialog-DqnbtCX_.js} +1 -1
  5. package/dist/web/assets/AddProjectDialog-DqnbtCX_.js.br +0 -0
  6. package/dist/web/assets/AddProjectDialog-DqnbtCX_.js.gz +0 -0
  7. package/dist/web/assets/{ArchivedWorkspaces-iLHY4HvX.js → ArchivedWorkspaces-BVNADrnb.js} +1 -1
  8. package/dist/web/assets/ArchivedWorkspaces-BVNADrnb.js.br +0 -0
  9. package/dist/web/assets/ArchivedWorkspaces-BVNADrnb.js.gz +0 -0
  10. package/dist/web/assets/{ChangesPanel-Douq7TDh.js → ChangesPanel-B_aMHOy0.js} +1 -1
  11. package/dist/web/assets/ChangesPanel-B_aMHOy0.js.br +0 -0
  12. package/dist/web/assets/ChangesPanel-B_aMHOy0.js.gz +0 -0
  13. package/dist/web/assets/{CodeBlockNode-D_GijZCc.js → CodeBlockNode-BHpMMKG-.js} +1 -1
  14. package/dist/web/assets/CodeBlockNode-BHpMMKG-.js.br +0 -0
  15. package/dist/web/assets/CodeBlockNode-BHpMMKG-.js.gz +0 -0
  16. package/dist/web/assets/{CommandCenter-Dgn6iwAc.js → CommandCenter-CLxqHc3O.js} +1 -1
  17. package/dist/web/assets/CommandCenter-CLxqHc3O.js.br +0 -0
  18. package/dist/web/assets/CommandCenter-CLxqHc3O.js.gz +0 -0
  19. package/dist/web/assets/{ConversationSearch-CQIdwDbS.js → ConversationSearch-FTWEWSUu.js} +1 -1
  20. package/dist/web/assets/ConversationSearch-FTWEWSUu.js.br +0 -0
  21. package/dist/web/assets/ConversationSearch-FTWEWSUu.js.gz +0 -0
  22. package/dist/web/assets/{FileViewer-u1LswFaI.js → FileViewer-C5O-KMUx.js} +1 -1
  23. package/dist/web/assets/FileViewer-C5O-KMUx.js.br +0 -0
  24. package/dist/web/assets/FileViewer-C5O-KMUx.js.gz +0 -0
  25. package/dist/web/assets/{FilesPanel-C3Ky-94i.js → FilesPanel-Dg9lqGBo.js} +1 -1
  26. package/dist/web/assets/FilesPanel-Dg9lqGBo.js.br +0 -0
  27. package/dist/web/assets/FilesPanel-Dg9lqGBo.js.gz +0 -0
  28. package/dist/web/assets/{HostSettings-0Sp94lI7.js → HostSettings-DsUCWEUL.js} +1 -1
  29. package/dist/web/assets/HostSettings-DsUCWEUL.js.br +0 -0
  30. package/dist/web/assets/HostSettings-DsUCWEUL.js.gz +0 -0
  31. package/dist/web/assets/{KanbanPage-C_NN-7Xn.js → KanbanPage-CSWy9O3h.js} +1 -1
  32. package/dist/web/assets/KanbanPage-CSWy9O3h.js.br +0 -0
  33. package/dist/web/assets/KanbanPage-CSWy9O3h.js.gz +0 -0
  34. package/dist/web/assets/{LabelsDialog-Fwipy97S.js → LabelsDialog-CITuVVJW.js} +1 -1
  35. package/dist/web/assets/LabelsDialog-CITuVVJW.js.br +0 -0
  36. package/dist/web/assets/LabelsDialog-CITuVVJW.js.gz +0 -0
  37. package/dist/web/assets/{MarkdownMessage-CAU8c5nI.js → MarkdownMessage-BSPsJz2u.js} +5 -5
  38. package/dist/web/assets/MarkdownMessage-BSPsJz2u.js.br +0 -0
  39. package/dist/web/assets/MarkdownMessage-BSPsJz2u.js.gz +0 -0
  40. package/dist/web/assets/{PreCodeBlock-B7iKsFkO.js → PreCodeBlock-CUsnJ_0J.js} +1 -1
  41. package/dist/web/assets/{PreCodeBlock.vue_vue_type_style_index_0_lang-BrFLU1mD.js → PreCodeBlock.vue_vue_type_style_index_0_lang-B_ZZH8sz.js} +1 -1
  42. package/dist/web/assets/PreCodeBlock.vue_vue_type_style_index_0_lang-B_ZZH8sz.js.br +0 -0
  43. package/dist/web/assets/PreCodeBlock.vue_vue_type_style_index_0_lang-B_ZZH8sz.js.gz +0 -0
  44. package/dist/web/assets/{SubagentsPanel-B_SKoi3M.js → SubagentsPanel-Brk1hh5C.js} +1 -1
  45. package/dist/web/assets/SubagentsPanel-Brk1hh5C.js.br +0 -0
  46. package/dist/web/assets/SubagentsPanel-Brk1hh5C.js.gz +0 -0
  47. package/dist/web/assets/{TerminalPanel-BS8QL0PS.js → TerminalPanel-tG9J8yCX.js} +1 -1
  48. package/dist/web/assets/TerminalPanel-tG9J8yCX.js.br +0 -0
  49. package/dist/web/assets/TerminalPanel-tG9J8yCX.js.gz +0 -0
  50. package/dist/web/assets/{Tooltip-DFMY7LPt.js → Tooltip-MKPYhhV1.js} +1 -1
  51. package/dist/web/assets/Tooltip-MKPYhhV1.js.br +0 -0
  52. package/dist/web/assets/Tooltip-MKPYhhV1.js.gz +0 -0
  53. package/dist/web/assets/index-DAwT50Ss.js +39 -0
  54. package/dist/web/assets/index-DAwT50Ss.js.br +0 -0
  55. package/dist/web/assets/index-DAwT50Ss.js.gz +0 -0
  56. package/dist/web/assets/{index10-BydpUG8j.js → index10-DahGcoad.js} +1 -1
  57. package/dist/web/assets/index10-DahGcoad.js.br +0 -0
  58. package/dist/web/assets/index10-DahGcoad.js.gz +0 -0
  59. package/dist/web/assets/index3-C_-f4bxf.js +1 -0
  60. package/dist/web/assets/index4-Bv2X2ReP.js +1 -0
  61. package/dist/web/assets/{index5-DO1qcqjc.js → index5-CgcNfgxb.js} +1 -1
  62. package/dist/web/assets/index5-CgcNfgxb.js.br +0 -0
  63. package/dist/web/assets/index5-CgcNfgxb.js.gz +0 -0
  64. package/dist/web/assets/{index6-DlE-6MZ2.js → index6-CrSTK4tr.js} +1 -1
  65. package/dist/web/assets/index6-CrSTK4tr.js.br +0 -0
  66. package/dist/web/assets/index6-CrSTK4tr.js.gz +0 -0
  67. package/dist/web/assets/{index7-SvrpSO3B.js → index7-DWSIBAjx.js} +1 -1
  68. package/dist/web/assets/index7-DWSIBAjx.js.br +0 -0
  69. package/dist/web/assets/index7-DWSIBAjx.js.gz +0 -0
  70. package/dist/web/assets/{index8-DM3y0uRE.js → index8-C-KUFSiY.js} +1 -1
  71. package/dist/web/assets/index8-C-KUFSiY.js.br +0 -0
  72. package/dist/web/assets/index8-C-KUFSiY.js.gz +0 -0
  73. package/dist/web/assets/{index9-DzVtbD9A.js → index9-CHVI36Nl.js} +1 -1
  74. package/dist/web/assets/index9-CHVI36Nl.js.br +0 -0
  75. package/dist/web/assets/index9-CHVI36Nl.js.gz +0 -0
  76. package/dist/web/index.html +1 -1
  77. package/dist/web/index.html.br +0 -0
  78. package/dist/web/index.html.gz +0 -0
  79. package/package.json +1 -1
  80. package/dist/web/assets/AddProjectDialog-_MWmro5G.js.br +0 -0
  81. package/dist/web/assets/AddProjectDialog-_MWmro5G.js.gz +0 -0
  82. package/dist/web/assets/ArchivedWorkspaces-iLHY4HvX.js.br +0 -0
  83. package/dist/web/assets/ArchivedWorkspaces-iLHY4HvX.js.gz +0 -0
  84. package/dist/web/assets/ChangesPanel-Douq7TDh.js.br +0 -0
  85. package/dist/web/assets/ChangesPanel-Douq7TDh.js.gz +0 -0
  86. package/dist/web/assets/CodeBlockNode-D_GijZCc.js.br +0 -0
  87. package/dist/web/assets/CodeBlockNode-D_GijZCc.js.gz +0 -0
  88. package/dist/web/assets/CommandCenter-Dgn6iwAc.js.br +0 -0
  89. package/dist/web/assets/CommandCenter-Dgn6iwAc.js.gz +0 -0
  90. package/dist/web/assets/ConversationSearch-CQIdwDbS.js.br +0 -0
  91. package/dist/web/assets/ConversationSearch-CQIdwDbS.js.gz +0 -0
  92. package/dist/web/assets/FileViewer-u1LswFaI.js.br +0 -0
  93. package/dist/web/assets/FileViewer-u1LswFaI.js.gz +0 -0
  94. package/dist/web/assets/FilesPanel-C3Ky-94i.js.br +0 -0
  95. package/dist/web/assets/FilesPanel-C3Ky-94i.js.gz +0 -0
  96. package/dist/web/assets/HostSettings-0Sp94lI7.js.br +0 -0
  97. package/dist/web/assets/HostSettings-0Sp94lI7.js.gz +0 -0
  98. package/dist/web/assets/KanbanPage-C_NN-7Xn.js.br +0 -0
  99. package/dist/web/assets/KanbanPage-C_NN-7Xn.js.gz +0 -0
  100. package/dist/web/assets/LabelsDialog-Fwipy97S.js.br +0 -0
  101. package/dist/web/assets/LabelsDialog-Fwipy97S.js.gz +0 -0
  102. package/dist/web/assets/MarkdownMessage-CAU8c5nI.js.br +0 -0
  103. package/dist/web/assets/MarkdownMessage-CAU8c5nI.js.gz +0 -0
  104. package/dist/web/assets/PreCodeBlock.vue_vue_type_style_index_0_lang-BrFLU1mD.js.br +0 -0
  105. package/dist/web/assets/PreCodeBlock.vue_vue_type_style_index_0_lang-BrFLU1mD.js.gz +0 -0
  106. package/dist/web/assets/SubagentsPanel-B_SKoi3M.js.br +0 -0
  107. package/dist/web/assets/SubagentsPanel-B_SKoi3M.js.gz +0 -0
  108. package/dist/web/assets/TerminalPanel-BS8QL0PS.js.br +0 -0
  109. package/dist/web/assets/TerminalPanel-BS8QL0PS.js.gz +0 -0
  110. package/dist/web/assets/Tooltip-DFMY7LPt.js.br +0 -0
  111. package/dist/web/assets/Tooltip-DFMY7LPt.js.gz +0 -0
  112. package/dist/web/assets/index-xM_Sgnt-.js +0 -39
  113. package/dist/web/assets/index-xM_Sgnt-.js.br +0 -0
  114. package/dist/web/assets/index-xM_Sgnt-.js.gz +0 -0
  115. package/dist/web/assets/index10-BydpUG8j.js.br +0 -0
  116. package/dist/web/assets/index10-BydpUG8j.js.gz +0 -0
  117. package/dist/web/assets/index3-C48jcDT-.js +0 -1
  118. package/dist/web/assets/index4-TBM-247u.js +0 -1
  119. package/dist/web/assets/index5-DO1qcqjc.js.br +0 -0
  120. package/dist/web/assets/index5-DO1qcqjc.js.gz +0 -0
  121. package/dist/web/assets/index6-DlE-6MZ2.js.br +0 -0
  122. package/dist/web/assets/index6-DlE-6MZ2.js.gz +0 -0
  123. package/dist/web/assets/index7-SvrpSO3B.js.br +0 -0
  124. package/dist/web/assets/index7-SvrpSO3B.js.gz +0 -0
  125. package/dist/web/assets/index8-DM3y0uRE.js.br +0 -0
  126. package/dist/web/assets/index8-DM3y0uRE.js.gz +0 -0
  127. package/dist/web/assets/index9-DzVtbD9A.js.br +0 -0
  128. package/dist/web/assets/index9-DzVtbD9A.js.gz +0 -0
@@ -9,7 +9,6 @@ import { createHostClient, parseHostTarget } from "@getpaseo/client/node";
9
9
  import { createPaseoApi } from "@getpaseo/client";
10
10
  import { deriveAgentStateBucket } from "@getpaseo/protocol/agent-state-bucket";
11
11
  import { getParentAgentIdFromLabels } from "@getpaseo/protocol/agent-labels";
12
- import { timelineItemIdentity } from "@getpaseo/protocol/timeline-identity";
13
12
  import { lstat, readFile, realpath } from "node:fs/promises";
14
13
  import { Hono } from "hono";
15
14
  import { bodyLimit } from "hono/body-limit";
@@ -733,462 +732,388 @@ var HostWorkspaces = class extends HostMirror {
733
732
  };
734
733
  // src/server/timeline-view.ts
735
734
  const TAIL_LIMIT = 60;
736
- const CATCH_UP_PAGE = 200;
737
- /** Catch-up pages read in one go; further behind than this, reloading the tail is cheaper. */
738
- const MAX_CATCH_UP_PAGES = 25;
739
- /** Viewers that joined a loading view tracked for its load report. */
740
- const MAX_JOINERS = 64;
741
- /** Rows kept per view; older rows are dropped and stay reachable through history pages. */
735
+ /** Rows kept per view; older rows stay reachable through on-demand history pages. */
742
736
  const MAX_ROWS = 600;
743
737
  const KEEP_ROWS = 500;
744
738
  /** Rows sent to a client that (re)joins; older ones load on demand. */
745
739
  const RESET_ROWS = 200;
746
- const MAX_BUFFER = 5e3;
747
- const FLUSH_MS$2 = 500;
740
+ const MAX_JOINERS = 64;
741
+ /** Low-frequency pull interval while an agent is actively running and watched. */
742
+ const DEFAULT_POLL_MS = 1500;
743
+ /** Retry delay when the initial load fails. */
748
744
  const RETRY_MS = 2e3;
745
+ /** One-shot follow-up delay after a turn ends if turnMetrics have not landed yet. */
746
+ const METRICS_SETTLE_MS = 700;
747
+ /** Per-pull RPC timeout so a wedged remote host can never lock `inFlight` forever. */
748
+ const PULL_TIMEOUT_MS = 2e4;
749
+ /** If a browser reconnects/resumes after this much silence, verify once against the daemon. */
750
+ const RESUME_VERIFY_MS = 5e3;
749
751
  const now = () => performance.now();
750
- /** Same fold the daemon's TimelineProjection applies when a tool call reports again. */
751
- function mergeToolCallItems(existing, incoming) {
752
- const a = existing.detail, b = incoming.detail;
753
- const detail = a?.type === "unknown" && b?.type !== "unknown" ? b : b?.type === "unknown" && a?.type !== "unknown" ? a : b;
754
- const metadata = existing.metadata || incoming.metadata ? {
755
- ...existing.metadata,
756
- ...incoming.metadata
757
- } : void 0;
758
- const merged = {
759
- ...existing,
760
- ...incoming,
761
- detail,
762
- metadata
752
+ function toRow(entry) {
753
+ return {
754
+ seqStart: entry.seqStart,
755
+ seqEnd: entry.seqEnd,
756
+ timestamp: entry.timestamp,
757
+ provider: entry.provider,
758
+ ...entry.turnId ? { turnId: entry.turnId } : {},
759
+ item: entry.item,
760
+ ...entry.turnMetrics?.length ? { turnMetrics: entry.turnMetrics } : {}
763
761
  };
764
- if (incoming.status === "failed") merged.error = incoming.error;
765
- else if (incoming.status === "completed" || incoming.status === "canceled") merged.error = null;
766
- else if (incoming.error !== void 0) merged.error = incoming.error;
767
- return merged;
768
762
  }
769
- function textMergeable(previous, entry) {
770
- const a = previous.item, b = entry.item;
771
- if (a.type !== b.type || previous.seqEnd + 1 !== entry.seqStart || previous.turnId !== entry.turnId) return false;
772
- if (a.type === "reasoning") return true;
773
- return a.type === "assistant_message" && (b.messageId === void 0 || a.messageId === b.messageId);
763
+ function rowFingerprint(row) {
764
+ return JSON.stringify([
765
+ row.seqEnd,
766
+ row.timestamp,
767
+ row.provider,
768
+ row.turnId ?? null,
769
+ row.item,
770
+ row.turnMetrics ?? null
771
+ ]);
774
772
  }
775
773
  /**
776
- * Live projection of one agent's timeline, shared by every browser viewing it. Daemon stream
777
- * events are folded with the daemon's own projection rules, so each event costs O(1) work and
778
- * reaches browsers as a small upsert/append op. Gaps, unknown identities and reconnects fall
779
- * back to an incremental `after` fetch, which returns only rows touched since the cursor.
774
+ * Single-source-of-truth projected timeline view (Wake + Pull).
775
+ *
776
+ * Every row comes directly from the daemon's `fetchAgentTimeline(..., projection: "projected")`:
777
+ * - Idle conversations do zero polling and use zero timers.
778
+ * - Active (running) conversations pull at a low cadence (1.5 s) while watched and broadcast only
779
+ * rows whose fingerprint actually changed.
780
+ * - Turning idle triggers a final pull (with one short follow-up if turnMetrics haven't landed),
781
+ * and every changed row advances a monotonic `revision` so returning tabs resume cleanly with
782
+ * all updates including `turnMetrics`.
780
783
  */
781
784
  var TimelineView = class {
782
785
  rows = [];
783
786
  bySeqStart = /* @__PURE__ */ new Map();
784
- identities = /* @__PURE__ */ new Map();
787
+ fingerprints = /* @__PURE__ */ new Map();
788
+ rowRev = /* @__PURE__ */ new Map();
785
789
  epoch = "";
786
- lastSeq = -1;
790
+ revision = 0;
791
+ resumeFloor = 0;
787
792
  hasOlder = false;
788
793
  startCursor = null;
789
- /**
790
- * The view knows every row changed after this seq, so a browser holding everything up to it
791
- * can resume with just those rows. Set by each load; raised when rows are trimmed.
792
- */
793
- resumeFloor = Number.POSITIVE_INFINITY;
794
- /** True while rows reach back to the first projected row, so unseen identities are new. */
795
- complete = false;
796
- state = "loading";
797
- buffer = [];
798
- overflowed = false;
794
+ state = "idle";
795
+ active = false;
799
796
  watchers = /* @__PURE__ */ new Set();
800
- /** seqStart → pending change since the last flush; full means send the whole row. */
801
- pending = /* @__PURE__ */ new Map();
802
- pendingReset = false;
803
- flushTimer;
797
+ pollTimer;
804
798
  retryTimer;
805
- subscription = null;
799
+ settleTimer;
800
+ followUpTimer;
801
+ inFlight = false;
802
+ pendingPull = false;
803
+ pendingSettle = false;
804
+ consecutiveFailures = 0;
805
+ lastPullAt = 0;
806
806
  token = 0;
807
- loads = 0;
808
- /** Timings of the load in progress, until the first rows go out. */
809
807
  timing = null;
810
- /** Viewers that joined while the view was loading, waiting for its first rows. */
811
808
  joiners = [];
812
809
  driver;
813
810
  agentId;
814
811
  report;
815
- constructor(driver, agentId, report) {
812
+ pollMs;
813
+ constructor(driver, agentId, report, pollMs = DEFAULT_POLL_MS) {
816
814
  this.driver = driver;
817
815
  this.agentId = agentId;
818
816
  this.report = report;
817
+ this.pollMs = pollMs;
819
818
  }
820
819
  get watcherCount() {
821
820
  return this.watchers.size;
822
821
  }
823
- /** Where the view stands, for diagnosing a viewer that waits. */
824
822
  get status() {
825
823
  return this.state;
826
824
  }
827
825
  start() {
828
- const token = ++this.token;
826
+ if (this.state === "disposed" || this.state === "loading" || this.state === "live") return;
829
827
  this.state = "loading";
830
- this.buffer = [];
831
- this.overflowed = false;
832
- const attemptAt = now();
833
- if (this.timing) {
834
- this.timing.attempts++;
835
- this.timing.attemptAt = attemptAt;
836
- } else this.timing = {
837
- startedAt: attemptAt,
838
- attemptAt,
839
- subscribeMs: null,
828
+ this.token++;
829
+ this.timing ??= {
830
+ startedAt: now(),
840
831
  fetchMs: null,
841
- attempts: 1,
832
+ attempts: 0,
842
833
  failures: 0
843
834
  };
844
- const subscription = this.driver.subscribeAgentTimeline(this.agentId, (message) => {
845
- if (token === this.token) this.onMessage(message);
846
- });
847
- this.subscription = subscription;
848
- subscription.ready.then(() => {
849
- if (token !== this.token) return;
850
- if (this.timing) this.timing.subscribeMs = Math.round(now() - this.timing.attemptAt);
851
- return this.reload();
852
- }, () => this.fail(token));
853
- }
854
- dispose() {
855
- this.token++;
856
- this.state = "disposed";
857
- clearTimeout(this.flushTimer);
858
- clearTimeout(this.retryTimer);
859
- this.watchers.clear();
860
- const released = this.subscription?.release().catch(() => {}) ?? Promise.resolve();
861
- this.subscription = null;
862
- return released;
835
+ this.timing.attempts++;
836
+ this.pull(true);
837
+ }
838
+ /** Updates whether this conversation is actively running; drives low-frequency pulling. */
839
+ setActive(running) {
840
+ if (this.state === "disposed") return;
841
+ const wasActive = this.active;
842
+ this.active = running;
843
+ clearTimeout(this.settleTimer);
844
+ this.settleTimer = void 0;
845
+ if (running) {
846
+ if (this.state === "live") {
847
+ this.pull(false);
848
+ this.schedulePoll();
849
+ }
850
+ } else {
851
+ clearTimeout(this.pollTimer);
852
+ this.pollTimer = void 0;
853
+ if (wasActive && this.state === "live") this.pull(false, true);
854
+ }
863
855
  }
864
856
  /**
865
- * Adds a browser. A live view answers at once: with the rows changed since `since` when the
866
- * browser holds this conversation up to a point the view can resume from (nothing when none
867
- * changed), else with a reset. A loading view sends its reset once loaded.
857
+ * Requests an immediate pull (e.g. after a message send, rewind, reconnect, or state update).
858
+ * With `followUp = true`, schedules one short 500ms follow-up pull if idle so instant commands
859
+ * or newly written prompts are never missed without starting an unbounded polling loop.
868
860
  */
861
+ wake(followUp = false) {
862
+ if (this.state === "disposed") return;
863
+ if (this.state === "idle" || this.state === "failed") return this.start();
864
+ if (this.state === "live") this.pull(false);
865
+ else this.pendingPull = true;
866
+ if (followUp) {
867
+ clearTimeout(this.followUpTimer);
868
+ this.followUpTimer = setTimeout(() => {
869
+ this.followUpTimer = void 0;
870
+ if (this.state === "live" && !this.active) this.pull(false);
871
+ }, 500);
872
+ this.followUpTimer.unref?.();
873
+ }
874
+ }
875
+ /** Backwards-compatible alias for one-shot tail refresh. */
876
+ refreshTailMetrics() {
877
+ this.wake();
878
+ }
869
879
  watch(watcher, since) {
870
- if (this.state === "live" || this.state === "catching-up") {
871
- this.flush();
872
- const resumed = since ? this.resumeOps(since) : null;
873
- if (!resumed) watcher([this.resetOp()]);
874
- else if (resumed.length) watcher(resumed);
875
- } else if (this.watchers.size && this.joiners.length < MAX_JOINERS) this.joiners.push(now());
876
880
  this.watchers.add(watcher);
877
- return () => this.watchers.delete(watcher);
878
- }
879
- onMessage(message) {
880
- switch (message.type) {
881
- case "agent_stream": {
882
- const payload = message.payload;
883
- if (payload.event.type !== "timeline" || payload.seq === void 0) return;
884
- if (this.state !== "live") return this.bufferEvent(payload);
885
- return this.process(payload);
881
+ if (this.state === "live") {
882
+ const ops = since ? this.resumeOps(since) : null;
883
+ if (ops) {
884
+ if (ops.length) watcher(ops);
885
+ } else watcher([this.resetOp()]);
886
+ if (this.active) this.schedulePoll();
887
+ else if (since && now() - this.lastPullAt >= RESUME_VERIFY_MS) this.wake();
888
+ } else if (this.state === "loading" && this.joiners.length < MAX_JOINERS) this.joiners.push(now());
889
+ return () => {
890
+ this.watchers.delete(watcher);
891
+ if (!this.watchers.size) {
892
+ clearTimeout(this.pollTimer);
893
+ this.pollTimer = void 0;
886
894
  }
887
- case "agent.timeline.replacement":
888
- this.reload();
889
- return;
890
- case "agent.timeline.subscription_restored":
891
- this.state === "live" && this.catchUp();
892
- return;
893
- case "agent.timeline.error": return this.fail(this.token);
894
- }
895
- }
896
- bufferEvent(payload) {
897
- if (this.overflowed) return;
898
- if (this.buffer.length >= MAX_BUFFER) {
899
- this.buffer = [];
900
- this.overflowed = true;
901
- return;
902
- }
903
- this.buffer.push(payload);
895
+ };
904
896
  }
905
- process(payload) {
906
- const seq = payload.seq;
907
- if (payload.epoch !== void 0 && payload.epoch !== this.epoch) return void this.reload();
908
- if (seq <= this.lastSeq) return;
909
- if (seq > this.lastSeq + 1) {
910
- this.bufferEvent(payload);
911
- this.catchUp();
897
+ dispose() {
898
+ this.state = "disposed";
899
+ this.token++;
900
+ clearTimeout(this.pollTimer);
901
+ clearTimeout(this.retryTimer);
902
+ clearTimeout(this.settleTimer);
903
+ clearTimeout(this.followUpTimer);
904
+ this.pollTimer = this.retryTimer = this.settleTimer = this.followUpTimer = void 0;
905
+ this.watchers.clear();
906
+ return Promise.resolve();
907
+ }
908
+ schedulePoll() {
909
+ if (this.state !== "live" || !this.active || !this.watchers.size || this.pollTimer) return;
910
+ this.pollTimer = setTimeout(() => {
911
+ this.pollTimer = void 0;
912
+ if (this.state !== "live" || !this.active || !this.watchers.size) return;
913
+ this.pull(false);
914
+ }, this.pollMs);
915
+ this.pollTimer.unref?.();
916
+ }
917
+ async pull(initial, checkMetricsSettle = false) {
918
+ if (this.state === "disposed") return;
919
+ if (this.inFlight) {
920
+ this.pendingPull = true;
921
+ if (checkMetricsSettle) this.pendingSettle = true;
912
922
  return;
913
923
  }
914
- if (!this.applyLive(payload)) return void this.catchUp();
915
- this.lastSeq = seq;
916
- }
917
- /** Folds one source event; false when the view cannot decide locally. */
918
- applyLive(payload) {
919
- const entry = {
920
- seqStart: payload.seq,
921
- seqEnd: payload.seq,
922
- timestamp: payload.timestamp,
923
- provider: payload.event.provider ?? "",
924
- ...payload.event.turnId ? { turnId: payload.event.turnId } : {},
925
- item: payload.event.item
926
- };
927
- const identity = timelineItemIdentity(entry.item);
928
- if (identity !== null) {
929
- const existing = this.identities.get(identity);
930
- if (existing) {
931
- if (entry.item.type === "tool_call") {
932
- if (existing.item.type === "tool_call" && existing.turnId === entry.turnId) {
933
- existing.item = mergeToolCallItems(existing.item, entry.item);
934
- existing.timestamp = entry.timestamp;
935
- existing.seqEnd = Math.max(existing.seqEnd, entry.seqEnd);
936
- this.mark(existing.seqStart, true);
937
- return true;
938
- }
939
- } else if (entry.item.type === "plugin" && existing.item.type === "plugin") {
940
- Object.assign(existing, {
941
- ...entry,
942
- seqStart: existing.seqStart
943
- });
944
- this.mark(existing.seqStart, true);
945
- return true;
946
- }
947
- } else if (!this.complete) return false;
948
- }
949
- const previous = this.rows.at(-1);
950
- if (previous && textMergeable(previous, entry)) {
951
- const text = entry.item.text ?? "";
952
- previous.item = {
953
- type: previous.item.type,
954
- text: (previous.item.text ?? "") + text,
955
- ...previous.item.type === "assistant_message" && previous.item.messageId ? { messageId: previous.item.messageId } : {}
956
- };
957
- previous.timestamp = entry.timestamp;
958
- previous.seqEnd = entry.seqEnd;
959
- this.mark(previous.seqStart, false, text);
960
- return true;
961
- }
962
- this.insert(entry);
963
- return true;
964
- }
965
- async reload() {
924
+ this.inFlight = true;
966
925
  const token = this.token;
967
- const load = ++this.loads;
968
- this.state = "loading";
969
926
  const fetchAt = now();
927
+ let timeoutHandle;
970
928
  try {
971
- const page = await this.driver.fetchAgentTimeline(this.agentId, {
929
+ const fetchPromise = this.driver.fetchAgentTimeline(this.agentId, {
972
930
  direction: "tail",
973
931
  limit: TAIL_LIMIT,
974
932
  projection: "projected",
975
- wholeTurns: false
933
+ wholeTurns: false,
934
+ timeout: 15e3
976
935
  });
977
- if (token !== this.token || load !== this.loads) return;
978
- if (this.timing) this.timing.fetchMs = Math.round(now() - fetchAt);
979
- this.replaceWith(page);
980
- this.flush();
981
- this.settle();
982
- } catch {
983
- this.fail(token);
984
- }
985
- }
986
- async catchUp() {
987
- if (this.state === "catching-up" || this.state === "loading") return;
988
- const token = this.token;
989
- this.state = "catching-up";
990
- try {
991
- for (let pages = 1;; pages++) {
992
- const before = this.lastSeq;
993
- const page = await this.driver.fetchAgentTimeline(this.agentId, {
994
- direction: "after",
995
- cursor: {
996
- epoch: this.epoch,
997
- seq: Math.max(0, this.lastSeq)
998
- },
999
- limit: CATCH_UP_PAGE,
1000
- projection: "projected"
1001
- });
1002
- if (token !== this.token) return;
1003
- if (page.reset || page.epoch !== this.epoch) {
1004
- this.replaceWith(page);
1005
- break;
936
+ const timeoutPromise = new Promise((_, reject) => {
937
+ timeoutHandle = setTimeout(() => reject(/* @__PURE__ */ new Error("Timeline fetch timed out")), PULL_TIMEOUT_MS);
938
+ timeoutHandle.unref?.();
939
+ });
940
+ const page = await Promise.race([fetchPromise, timeoutPromise]);
941
+ if (token !== this.token) return;
942
+ this.lastPullAt = now();
943
+ if (this.timing) this.timing.fetchMs = Math.round(this.lastPullAt - fetchAt);
944
+ this.consecutiveFailures = 0;
945
+ if (initial || this.state !== "live" || page.reset || page.epoch !== this.epoch) {
946
+ this.replaceWith(page);
947
+ this.state = "live";
948
+ this.loaded();
949
+ this.broadcast([this.resetOp()]);
950
+ } else {
951
+ const ops = this.mergeTail(page);
952
+ if (ops.length) this.broadcast(ops);
953
+ }
954
+ if (checkMetricsSettle && !this.active) {
955
+ const latest = [...page.entries].reverse().find((e) => e.item.type === "assistant_message" || e.item.type === "tool_call");
956
+ if (latest && !latest.turnMetrics?.length) {
957
+ clearTimeout(this.settleTimer);
958
+ this.settleTimer = setTimeout(() => {
959
+ this.settleTimer = void 0;
960
+ if (this.state === "live" && !this.active) this.pull(false, false);
961
+ }, METRICS_SETTLE_MS);
962
+ this.settleTimer.unref?.();
1006
963
  }
1007
- for (const entry of page.entries) this.upsertFetched(entry);
1008
- const end = page.endCursor?.seq ?? (page.hasNewer ? null : page.window.maxSeq);
1009
- if (end === null) break;
1010
- this.lastSeq = Math.max(this.lastSeq, end);
1011
- if (!page.hasNewer) break;
1012
- if (end <= before || pages >= MAX_CATCH_UP_PAGES) return void this.reload();
1013
964
  }
1014
- this.settle();
1015
965
  } catch {
1016
- this.fail(token);
1017
- }
1018
- }
1019
- /** Back to live: replay what arrived meanwhile, or reload if the buffer overflowed. */
1020
- settle() {
1021
- if (this.overflowed) {
1022
- this.overflowed = false;
1023
- this.buffer = [];
1024
- this.reload();
1025
- return;
1026
- }
1027
- this.state = "live";
1028
- const events = this.buffer;
1029
- this.buffer = [];
1030
- for (let i = 0; i < events.length; i++) {
1031
- this.process(events[i]);
1032
- if (this.state !== "live") {
1033
- this.buffer = this.buffer.concat(events.slice(i + 1));
1034
- return;
966
+ if (token !== this.token) return;
967
+ this.consecutiveFailures++;
968
+ if (this.timing) this.timing.failures++;
969
+ if (initial || this.state !== "live") {
970
+ this.state = "failed";
971
+ this.broadcast([{
972
+ type: "error",
973
+ message: "Timeline sync interrupted; retrying"
974
+ }]);
975
+ clearTimeout(this.retryTimer);
976
+ this.retryTimer = setTimeout(() => {
977
+ this.retryTimer = void 0;
978
+ if (this.state === "failed" && token === this.token) this.start();
979
+ }, RETRY_MS);
980
+ this.retryTimer.unref?.();
981
+ } else if (this.consecutiveFailures >= 3) this.broadcast([{
982
+ type: "error",
983
+ message: "Timeline sync interrupted; retrying"
984
+ }]);
985
+ } finally {
986
+ clearTimeout(timeoutHandle);
987
+ this.inFlight = false;
988
+ if (this.state === "live") {
989
+ if (this.pendingPull) {
990
+ const settle = this.pendingSettle;
991
+ this.pendingPull = false;
992
+ this.pendingSettle = false;
993
+ this.pull(false, settle);
994
+ } else if (this.active && this.watchers.size) this.schedulePoll();
1035
995
  }
1036
996
  }
1037
997
  }
1038
- fail(token) {
1039
- if (token !== this.token || this.state === "disposed") return;
1040
- this.state = "failed";
1041
- if (this.timing) this.timing.failures++;
1042
- this.broadcast([{
1043
- type: "error",
1044
- message: "Timeline sync interrupted; retrying"
1045
- }]);
1046
- clearTimeout(this.retryTimer);
1047
- this.retryTimer = setTimeout(() => {
1048
- if (this.state !== "failed" || token !== this.token) return;
1049
- this.subscription?.release().catch(() => {});
1050
- this.start();
1051
- }, RETRY_MS);
1052
- this.retryTimer.unref?.();
1053
- }
1054
998
  replaceWith(page) {
1055
999
  this.rows = [];
1056
1000
  this.bySeqStart.clear();
1057
- this.identities.clear();
1058
- this.pending.clear();
1001
+ this.fingerprints.clear();
1002
+ this.rowRev.clear();
1059
1003
  this.epoch = page.epoch;
1060
- this.lastSeq = page.window.maxSeq;
1061
- this.resumeFloor = this.lastSeq;
1004
+ this.revision++;
1005
+ this.resumeFloor = this.revision;
1062
1006
  this.hasOlder = page.hasOlder;
1063
1007
  this.startCursor = page.startCursor;
1064
- this.complete = !page.hasOlder;
1065
- for (const entry of page.entries) this.upsertFetched(entry, false);
1066
- this.buffer = this.buffer.filter((e) => (e.epoch === void 0 || e.epoch === this.epoch) && e.seq > this.lastSeq);
1067
- this.pending.clear();
1068
- this.pendingReset = true;
1069
- this.scheduleFlush();
1070
- }
1071
- upsertFetched(entry, notify = true) {
1072
- const row = {
1073
- seqStart: entry.seqStart,
1074
- seqEnd: entry.seqEnd,
1075
- timestamp: entry.timestamp,
1076
- provider: entry.provider,
1077
- ...entry.turnId ? { turnId: entry.turnId } : {},
1078
- item: entry.item,
1079
- ...entry.turnMetrics?.length ? { turnMetrics: entry.turnMetrics } : {}
1080
- };
1081
- const existing = this.bySeqStart.get(row.seqStart);
1082
- if (existing) {
1083
- Object.assign(existing, row);
1084
- if (!row.turnId) delete existing.turnId;
1085
- if (!row.turnMetrics?.length) delete existing.turnMetrics;
1086
- this.noteIdentity(existing);
1087
- if (notify) this.mark(existing.seqStart, true);
1088
- return;
1008
+ for (const entry of page.entries) {
1009
+ const row = toRow(entry);
1010
+ this.insertRow(row, this.revision);
1089
1011
  }
1090
- if (this.hasOlder && this.startCursor && row.seqStart < this.startCursor.seq) return;
1091
- this.insert(row, notify);
1012
+ this.trimIfNeeded();
1092
1013
  }
1093
- insert(row, notify = true) {
1014
+ mergeTail(page) {
1015
+ if (this.rows.length > 0) {
1016
+ if (page.entries.length === 0) {
1017
+ this.replaceWith(page);
1018
+ return [this.resetOp()];
1019
+ }
1020
+ const tailFirst = page.entries[0].seqStart;
1021
+ const ourLast = this.rows.at(-1);
1022
+ if (page.hasOlder && tailFirst > ourLast.seqEnd + 1) {
1023
+ this.replaceWith(page);
1024
+ return [this.resetOp()];
1025
+ }
1026
+ const incomingStarts = new Set(page.entries.map((e) => e.seqStart));
1027
+ for (let i = this.rows.length - 1; i >= 0; i--) {
1028
+ const r = this.rows[i];
1029
+ if (r.seqStart < tailFirst) break;
1030
+ if (!incomingStarts.has(r.seqStart)) {
1031
+ this.replaceWith(page);
1032
+ return [this.resetOp()];
1033
+ }
1034
+ }
1035
+ }
1036
+ const ops = [];
1037
+ let touched = false;
1038
+ for (const entry of page.entries) {
1039
+ const row = toRow(entry);
1040
+ const fp = rowFingerprint(row);
1041
+ const existing = this.bySeqStart.get(row.seqStart);
1042
+ if (existing) {
1043
+ if (this.fingerprints.get(row.seqStart) === fp) continue;
1044
+ if (!touched) {
1045
+ this.revision++;
1046
+ touched = true;
1047
+ }
1048
+ Object.assign(existing, row);
1049
+ if (!row.turnId) delete existing.turnId;
1050
+ if (!row.turnMetrics?.length) delete existing.turnMetrics;
1051
+ this.fingerprints.set(row.seqStart, fp);
1052
+ this.rowRev.set(row.seqStart, this.revision);
1053
+ ops.push({
1054
+ type: "upsert",
1055
+ row: { ...existing },
1056
+ seq: this.revision
1057
+ });
1058
+ continue;
1059
+ }
1060
+ if (this.hasOlder && this.startCursor && row.seqStart < this.startCursor.seq) continue;
1061
+ if (!touched) {
1062
+ this.revision++;
1063
+ touched = true;
1064
+ }
1065
+ this.insertRow(row, this.revision);
1066
+ ops.push({
1067
+ type: "upsert",
1068
+ row: { ...row },
1069
+ seq: this.revision
1070
+ });
1071
+ }
1072
+ this.trimIfNeeded();
1073
+ return ops;
1074
+ }
1075
+ insertRow(row, rev) {
1076
+ const fp = rowFingerprint(row);
1094
1077
  let index = this.rows.length;
1095
1078
  if (index && this.rows[index - 1].seqStart > row.seqStart) {
1096
- let low = 0, high = index;
1079
+ let low = 0;
1080
+ let high = index;
1097
1081
  while (low < high) {
1098
- const middle = low + high >>> 1;
1099
- if (this.rows[middle].seqStart < row.seqStart) low = middle + 1;
1100
- else high = middle;
1082
+ const mid = low + high >>> 1;
1083
+ if (this.rows[mid].seqStart < row.seqStart) low = mid + 1;
1084
+ else high = mid;
1101
1085
  }
1102
1086
  index = low;
1103
1087
  }
1104
- if (index === this.rows.length) this.rows.push(row);
1105
- else this.rows.splice(index, 0, row);
1088
+ this.rows.splice(index, 0, row);
1106
1089
  this.bySeqStart.set(row.seqStart, row);
1107
- this.noteIdentity(row);
1108
- if (notify) this.mark(row.seqStart, true);
1109
- if (this.rows.length > MAX_ROWS) this.trim();
1110
- }
1111
- /** Like the daemon, an identity resolves to its most recent row. */
1112
- noteIdentity(row) {
1113
- const identity = timelineItemIdentity(row.item);
1114
- if (identity === null) return;
1115
- const current = this.identities.get(identity);
1116
- if (!current || current.seqStart <= row.seqStart) this.identities.set(identity, row);
1117
- }
1118
- trim() {
1119
- const removed = this.rows.splice(0, this.rows.length - KEEP_ROWS);
1120
- for (const row of removed) {
1121
- this.resumeFloor = Math.max(this.resumeFloor, row.seqEnd);
1090
+ this.fingerprints.set(row.seqStart, fp);
1091
+ this.rowRev.set(row.seqStart, rev);
1092
+ }
1093
+ trimIfNeeded() {
1094
+ if (this.rows.length <= MAX_ROWS) return;
1095
+ const dropped = this.rows.slice(0, this.rows.length - KEEP_ROWS);
1096
+ this.rows = this.rows.slice(this.rows.length - KEEP_ROWS);
1097
+ for (const row of dropped) {
1122
1098
  this.bySeqStart.delete(row.seqStart);
1123
- this.pending.delete(row.seqStart);
1124
- const identity = timelineItemIdentity(row.item);
1125
- if (identity !== null && this.identities.get(identity) === row) this.identities.delete(identity);
1099
+ this.fingerprints.delete(row.seqStart);
1100
+ this.rowRev.delete(row.seqStart);
1126
1101
  }
1127
- this.complete = false;
1128
1102
  this.hasOlder = true;
1129
- this.startCursor = {
1103
+ this.startCursor = this.rows[0] ? {
1130
1104
  epoch: this.epoch,
1131
1105
  seq: this.rows[0].seqStart
1132
- };
1106
+ } : this.startCursor;
1107
+ this.resumeFloor = this.revision;
1133
1108
  }
1134
- mark(seqStart, full, text = "") {
1135
- if (this.pendingReset || !this.watchers.size) return;
1136
- const pending = this.pending.get(seqStart);
1137
- if (!pending) this.pending.set(seqStart, {
1138
- full,
1139
- text: full ? "" : text
1140
- });
1141
- else if (full) {
1142
- pending.full = true;
1143
- pending.text = "";
1144
- } else if (!pending.full) pending.text += text;
1145
- this.scheduleFlush();
1146
- }
1147
- scheduleFlush() {
1148
- if (this.flushTimer || !this.watchers.size) return;
1149
- this.flushTimer = setTimeout(() => this.flush(), FLUSH_MS$2);
1150
- this.flushTimer.unref?.();
1151
- }
1152
- flush() {
1153
- clearTimeout(this.flushTimer);
1154
- this.flushTimer = void 0;
1155
- if (this.pendingReset) {
1156
- this.pendingReset = false;
1157
- this.pending.clear();
1158
- this.broadcast([this.resetOp()]);
1159
- return this.loaded();
1160
- }
1161
- if (!this.pending.size) return;
1162
- const ops = [];
1163
- for (const [seqStart, change] of this.pending) {
1164
- const row = this.bySeqStart.get(seqStart);
1165
- if (!row) continue;
1166
- ops.push(change.full ? {
1167
- type: "upsert",
1168
- row: { ...row }
1169
- } : {
1170
- type: "append",
1171
- seqStart,
1172
- seqEnd: row.seqEnd,
1173
- timestamp: row.timestamp,
1174
- text: change.text
1175
- });
1176
- }
1177
- this.pending.clear();
1178
- if (ops.length) this.broadcast(ops);
1179
- }
1180
- /**
1181
- * The rows a returning browser lacks: those from its window on that changed after `since.seq`,
1182
- * as upserts. Null when the view cannot tell (another epoch, history it no longer holds) or
1183
- * when so much changed that a reset is the smaller answer.
1184
- */
1185
1109
  resumeOps(since) {
1186
- if (since.epoch !== this.epoch || since.seq < this.resumeFloor || since.seq > this.lastSeq) return null;
1187
- const changed = this.rows.filter((row) => row.seqEnd > since.seq && row.seqStart >= since.from);
1110
+ if (since.epoch !== this.epoch || since.seq < this.resumeFloor || since.seq > this.revision) return null;
1111
+ const changed = this.rows.filter((row) => row.seqStart >= since.from && (this.rowRev.get(row.seqStart) ?? 0) > since.seq);
1188
1112
  if (changed.length > RESET_ROWS) return null;
1189
1113
  return changed.map((row) => ({
1190
1114
  type: "upsert",
1191
- row: { ...row }
1115
+ row: { ...row },
1116
+ seq: this.revision
1192
1117
  }));
1193
1118
  }
1194
1119
  resetOp() {
@@ -1203,10 +1128,9 @@ var TimelineView = class {
1203
1128
  epoch: this.epoch,
1204
1129
  seq: rows[0].seqStart
1205
1130
  } : this.startCursor,
1206
- seq: this.lastSeq
1131
+ seq: this.revision
1207
1132
  };
1208
1133
  }
1209
- /** The first rows went out: report how long the view, and anyone who joined it, waited. */
1210
1134
  loaded() {
1211
1135
  const timing = this.timing;
1212
1136
  const joiners = this.joiners;
@@ -1215,7 +1139,7 @@ var TimelineView = class {
1215
1139
  if (!timing || !this.watchers.size) return;
1216
1140
  const done = now();
1217
1141
  const base = {
1218
- subscribeMs: timing.subscribeMs,
1142
+ subscribeMs: null,
1219
1143
  fetchMs: timing.fetchMs,
1220
1144
  attempts: timing.attempts,
1221
1145
  failures: timing.failures
@@ -1231,34 +1155,6 @@ var TimelineView = class {
1231
1155
  kind: "join"
1232
1156
  });
1233
1157
  }
1234
- /**
1235
- * Pulls the last few projected entries after a turn finishes so daemon-computed turnMetrics
1236
- * (speed, tokens, cache, cost) attach to live rows without reloading the whole timeline.
1237
- */
1238
- async refreshTailMetrics() {
1239
- if (this.state !== "live" || !this.watchers.size) return;
1240
- const token = this.token;
1241
- try {
1242
- const page = await this.driver.fetchAgentTimeline(this.agentId, {
1243
- direction: "tail",
1244
- limit: 8,
1245
- projection: "projected",
1246
- wholeTurns: false
1247
- });
1248
- if (token !== this.token || this.state !== "live" || page.epoch !== this.epoch) return;
1249
- let updated = false;
1250
- for (const entry of page.entries) {
1251
- if (!entry.turnMetrics?.length) continue;
1252
- const existing = this.bySeqStart.get(entry.seqStart);
1253
- if (!existing) continue;
1254
- if (JSON.stringify(existing.turnMetrics ?? null) === JSON.stringify(entry.turnMetrics)) continue;
1255
- existing.turnMetrics = entry.turnMetrics;
1256
- this.mark(existing.seqStart, true);
1257
- updated = true;
1258
- }
1259
- if (updated) this.flush();
1260
- } catch {}
1261
- }
1262
1158
  broadcast(ops) {
1263
1159
  notifyListeners(this.watchers, ops);
1264
1160
  }
@@ -1331,6 +1227,10 @@ var HostSubagents = class {
1331
1227
  this.releaseUse();
1332
1228
  };
1333
1229
  }
1230
+ /** Current status of a provider subagent, if known. */
1231
+ statusOf(parentAgentId, subagentId) {
1232
+ return this.parents.get(parentAgentId)?.subagents.get(subagentId)?.status;
1233
+ }
1334
1234
  /** A TimelineView driver for one subagent conversation. */
1335
1235
  timelineDriver(parentAgentId, subagentId) {
1336
1236
  const key = `${parentAgentId}\0${subagentId}`;
@@ -1777,7 +1677,14 @@ var Hosts = class {
1777
1677
  attach(hostId, driver, api) {
1778
1678
  this.assertDetached(hostId);
1779
1679
  const directory = new HostDirectory(hostId, driver, this.agents, () => this.emit(this.agentListeners), (previous, next) => {
1780
- if (previous && next && (previous.turnActive || previous.state === "running") && !next.turnActive && next.state !== "running") this.timelines.get(next.key)?.view.refreshTailMetrics();
1680
+ if (next) {
1681
+ const view = this.timelines.get(next.key)?.view;
1682
+ if (view) {
1683
+ const running = next.turnActive === true || next.state === "running" || next.status === "running" || next.status === "initializing";
1684
+ view.setActive(running);
1685
+ if (!running && previous && (previous.activityAt !== next.activityAt || previous.state !== next.state)) view.wake();
1686
+ }
1687
+ }
1781
1688
  notifyListeners(this.transitionListeners, previous, next);
1782
1689
  });
1783
1690
  const workspaces = new HostWorkspaces(hostId, driver, this.workspaces, () => this.emit(this.agentListeners), this.emptyProjects);
@@ -1790,6 +1697,7 @@ var Hosts = class {
1790
1697
  });
1791
1698
  this.diagnostics.set(hostId, { lastConnectedAt: (/* @__PURE__ */ new Date()).toISOString() });
1792
1699
  this.clients.get(hostId)?.backgroundWork.reconnect();
1700
+ for (const entry of this.timelines.values()) if (entry.hostId === hostId && entry.view.watcherCount > 0) entry.view.wake();
1793
1701
  } else if (state.status === "connecting") this.diagnostics.set(hostId, {
1794
1702
  ...previous,
1795
1703
  nextRetryAt: void 0,
@@ -1917,9 +1825,21 @@ var Hosts = class {
1917
1825
  this.hostListeners.add(listener);
1918
1826
  return () => this.hostListeners.delete(listener);
1919
1827
  }
1828
+ /** Wakes a watched timeline view immediately (e.g. after sending a message or rewinding). */
1829
+ wakeTimeline(hostId, agentId, followUp = false) {
1830
+ const view = this.timelines.get(`${hostId}:${agentId}`)?.view;
1831
+ if (!view) return;
1832
+ view.wake(followUp);
1833
+ }
1920
1834
  /** The provider subagents of one agent, as they change. */
1921
1835
  watchSubagents(hostId, agentId, listener) {
1922
- return this.get(hostId).subagents.watch(agentId, listener);
1836
+ return this.get(hostId).subagents.watch(agentId, (subagents) => {
1837
+ for (const s of subagents) {
1838
+ const subView = this.timelines.get(`${hostId}:${agentId}:subagent:${s.id}`)?.view;
1839
+ if (subView) subView.setActive(s.status === "running");
1840
+ }
1841
+ listener(subagents);
1842
+ });
1923
1843
  }
1924
1844
  /** Background tasks and heartbeats of one agent, as they change. */
1925
1845
  watchBackgroundWork(hostId, agentId, listener) {
@@ -1949,6 +1869,9 @@ var Hosts = class {
1949
1869
  ...report
1950
1870
  });
1951
1871
  });
1872
+ const agent = subagentId ? void 0 : this.agents.get(key);
1873
+ const running = subagentId ? client.subagents.statusOf(agentId, subagentId) === "running" : !!(agent && (agent.turnActive === true || agent.state === "running" || agent.status === "running" || agent.status === "initializing"));
1874
+ view.setActive(running);
1952
1875
  entry = {
1953
1876
  view,
1954
1877
  hostId,
@@ -1991,7 +1914,7 @@ var Hosts = class {
1991
1914
  if (waiting && ops.some((op) => op.type === "reset")) finishWait(false);
1992
1915
  watcher(ops);
1993
1916
  }, since);
1994
- if (joined.state === "live" || joined.state === "catching-up") finishWait(false);
1917
+ if (joined.state === "live") finishWait(false);
1995
1918
  const current = entry;
1996
1919
  return () => {
1997
1920
  finishWait(true);
@@ -5443,6 +5366,7 @@ function registerTimelineRoutes(app, { store, hosts, streamValidity, encodingOf
5443
5366
  if (!rewindModes(facts.capabilities).includes(mode)) return c.json({ error: "This agent cannot rewind that way." }, 400);
5444
5367
  try {
5445
5368
  await client.driver.rewindAgent(c.req.param("agent"), messageId, mode);
5369
+ hosts.wakeTimeline(c.req.param("host"), c.req.param("agent"), true);
5446
5370
  return c.json({ ok: true });
5447
5371
  } catch (error) {
5448
5372
  return c.json({ error: errorMessage(error, "Rewind failed") }, 502);
@@ -5644,6 +5568,7 @@ function registerMessageRoutes(app, { store, hosts, attachments, sendQueue, stre
5644
5568
  ...prepared.attachments.length ? { attachments: prepared.attachments } : {}
5645
5569
  });
5646
5570
  attachments.consumed(input.attachmentIds);
5571
+ hosts.wakeTimeline(host, agent, true);
5647
5572
  return c.json({
5648
5573
  status: "acknowledged",
5649
5574
  messageId: input.messageId