@phren/cli 0.3.10 → 0.3.12

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 (184) hide show
  1. package/dist/bridge/agent-hook-stores.d.ts +3 -0
  2. package/dist/bridge/agent-hook-stores.js +5 -0
  3. package/dist/bridge/agent-hooks.d.ts +159 -5
  4. package/dist/bridge/agent-hooks.js +663 -49
  5. package/dist/bridge/approval-summary.d.ts +16 -0
  6. package/dist/bridge/approval-summary.js +133 -0
  7. package/dist/bridge/authority-command.d.ts +20 -0
  8. package/dist/bridge/authority-command.js +120 -0
  9. package/dist/bridge/authority.d.ts +223 -0
  10. package/dist/bridge/authority.js +231 -0
  11. package/dist/bridge/claude-account-setup.d.ts +14 -0
  12. package/dist/bridge/claude-account-setup.js +69 -0
  13. package/dist/bridge/claude-accounts.d.ts +49 -0
  14. package/dist/bridge/claude-accounts.js +195 -0
  15. package/dist/bridge/code-routes.js +2 -2
  16. package/dist/bridge/codex-app-server.d.ts +144 -0
  17. package/dist/bridge/codex-app-server.js +319 -0
  18. package/dist/bridge/codex-auth-refresh.d.ts +33 -0
  19. package/dist/bridge/codex-auth-refresh.js +71 -0
  20. package/dist/bridge/codex-question-reply.d.ts +16 -0
  21. package/dist/bridge/codex-question-reply.js +57 -0
  22. package/dist/bridge/codex-review-mode.d.ts +10 -0
  23. package/dist/bridge/codex-review-mode.js +74 -0
  24. package/dist/bridge/codex-servers.d.ts +217 -0
  25. package/dist/bridge/codex-servers.js +636 -0
  26. package/dist/bridge/command.js +94 -4
  27. package/dist/bridge/computer-identity.d.ts +75 -0
  28. package/dist/bridge/computer-identity.js +166 -0
  29. package/dist/bridge/conductor-group.d.ts +91 -8
  30. package/dist/bridge/conductor-group.js +105 -9
  31. package/dist/bridge/conductor-role.d.ts +94 -0
  32. package/dist/bridge/conductor-role.js +176 -0
  33. package/dist/bridge/conductor-sets.d.ts +20 -0
  34. package/dist/bridge/conductor-sets.js +59 -0
  35. package/dist/bridge/dispatch-command.d.ts +3 -0
  36. package/dist/bridge/dispatch-command.js +75 -11
  37. package/dist/bridge/dispatch-returns.d.ts +123 -19
  38. package/dist/bridge/dispatch-returns.js +357 -50
  39. package/dist/bridge/dispatch.d.ts +103 -2
  40. package/dist/bridge/dispatch.js +272 -40
  41. package/dist/bridge/fanout-messages.js +2 -2
  42. package/dist/bridge/fanouts.d.ts +7 -1
  43. package/dist/bridge/fanouts.js +40 -5
  44. package/dist/bridge/folder-trust.d.ts +56 -0
  45. package/dist/bridge/folder-trust.js +195 -0
  46. package/dist/bridge/grants.d.ts +22 -1
  47. package/dist/bridge/grants.js +57 -9
  48. package/dist/bridge/hand-off.d.ts +21 -9
  49. package/dist/bridge/hand-off.js +58 -45
  50. package/dist/bridge/harness-status.d.ts +11 -0
  51. package/dist/bridge/harness-status.js +32 -0
  52. package/dist/bridge/harnesses.d.ts +39 -0
  53. package/dist/bridge/harnesses.js +65 -0
  54. package/dist/bridge/health.d.ts +2 -0
  55. package/dist/bridge/health.js +1 -1
  56. package/dist/bridge/herdr.d.ts +11 -2
  57. package/dist/bridge/herdr.js +98 -23
  58. package/dist/bridge/hook-fast.d.ts +4 -0
  59. package/dist/bridge/hook-fast.js +68 -0
  60. package/dist/bridge/install.d.ts +16 -1
  61. package/dist/bridge/install.js +88 -21
  62. package/dist/bridge/launch-brief.d.ts +96 -0
  63. package/dist/bridge/launch-brief.js +164 -0
  64. package/dist/bridge/model-switch.d.ts +3 -0
  65. package/dist/bridge/model-switch.js +17 -1
  66. package/dist/bridge/models.d.ts +8 -4
  67. package/dist/bridge/models.js +24 -8
  68. package/dist/bridge/mux-wire.d.ts +9 -0
  69. package/dist/bridge/mux-wire.js +19 -0
  70. package/dist/bridge/opencode-pane-server.d.ts +113 -0
  71. package/dist/bridge/opencode-pane-server.js +332 -0
  72. package/dist/bridge/opencode-panes.d.ts +111 -0
  73. package/dist/bridge/opencode-panes.js +295 -0
  74. package/dist/bridge/pane-accounts.d.ts +8 -0
  75. package/dist/bridge/pane-accounts.js +46 -0
  76. package/dist/bridge/prompt-startup.d.ts +5 -0
  77. package/dist/bridge/prompt-startup.js +24 -0
  78. package/dist/bridge/protocol.d.ts +5 -0
  79. package/dist/bridge/protocol.js +4 -0
  80. package/dist/bridge/push.d.ts +5 -4
  81. package/dist/bridge/push.js +6 -4
  82. package/dist/bridge/questions.d.ts +37 -2
  83. package/dist/bridge/questions.js +158 -15
  84. package/dist/bridge/resources.d.ts +125 -0
  85. package/dist/bridge/resources.js +314 -0
  86. package/dist/bridge/schedule-format.d.ts +2 -0
  87. package/dist/bridge/schedule-format.js +3 -0
  88. package/dist/bridge/schedule-launch.d.ts +2 -1
  89. package/dist/bridge/schedule-launch.js +23 -53
  90. package/dist/bridge/schedule-watch.d.ts +10 -1
  91. package/dist/bridge/schedule-watch.js +54 -2
  92. package/dist/bridge/server-launch.d.ts +22 -5
  93. package/dist/bridge/server-launch.js +225 -29
  94. package/dist/bridge/server-overview.d.ts +8 -2
  95. package/dist/bridge/server-overview.js +26 -5
  96. package/dist/bridge/server-pane-routes.d.ts +2 -0
  97. package/dist/bridge/server-pane-routes.js +145 -15
  98. package/dist/bridge/server-routes.d.ts +11 -1
  99. package/dist/bridge/server-routes.js +195 -36
  100. package/dist/bridge/server-stream.d.ts +2 -0
  101. package/dist/bridge/server-stream.js +22 -8
  102. package/dist/bridge/server.d.ts +6 -1
  103. package/dist/bridge/server.js +47 -12
  104. package/dist/bridge/session-activity.d.ts +81 -0
  105. package/dist/bridge/session-activity.js +117 -0
  106. package/dist/bridge/session-rename.d.ts +48 -0
  107. package/dist/bridge/session-rename.js +190 -0
  108. package/dist/bridge/session-servers.js +2 -2
  109. package/dist/bridge/settings-switch.d.ts +60 -0
  110. package/dist/bridge/settings-switch.js +287 -0
  111. package/dist/bridge/speech-voice.d.ts +55 -0
  112. package/dist/bridge/speech-voice.js +132 -0
  113. package/dist/bridge/speech.d.ts +70 -11
  114. package/dist/bridge/speech.js +169 -41
  115. package/dist/bridge/terminal-herdr.js +9 -3
  116. package/dist/bridge/terminal-tmux.d.ts +3 -3
  117. package/dist/bridge/terminal-tmux.js +24 -9
  118. package/dist/bridge/terminal.d.ts +27 -4
  119. package/dist/bridge/terminal.js +8 -1
  120. package/dist/bridge/transcript-claude.js +62 -12
  121. package/dist/bridge/transcript-codex.d.ts +0 -2
  122. package/dist/bridge/transcript-codex.js +29 -4
  123. package/dist/bridge/transcript-preview.d.ts +1 -0
  124. package/dist/bridge/transcript-preview.js +24 -4
  125. package/dist/bridge/transcripts.d.ts +15 -2
  126. package/dist/bridge/transcripts.js +47 -16
  127. package/dist/bridge/turn-records.d.ts +85 -0
  128. package/dist/bridge/turn-records.js +143 -0
  129. package/dist/bridge/uploads.d.ts +3 -0
  130. package/dist/bridge/uploads.js +14 -0
  131. package/dist/bridge/usage.d.ts +73 -28
  132. package/dist/bridge/usage.js +313 -340
  133. package/dist/bridge-hook.mjs +24624 -18450
  134. package/dist/cli/claude-unmanaged.d.ts +12 -0
  135. package/dist/cli/claude-unmanaged.js +105 -0
  136. package/dist/cli/schedules.js +2 -1
  137. package/dist/cli/session-start.js +10 -1
  138. package/dist/cli/session-stop.js +9 -1
  139. package/dist/cli-registry.d.ts +2 -0
  140. package/dist/cli-registry.js +37 -5
  141. package/dist/computers/command.d.ts +6 -0
  142. package/dist/computers/command.js +152 -0
  143. package/dist/computers/mcp.d.ts +1 -0
  144. package/dist/computers/mcp.js +97 -0
  145. package/dist/computers/read.d.ts +85 -0
  146. package/dist/computers/read.js +177 -0
  147. package/dist/data/task-receipts.d.ts +19 -0
  148. package/dist/data/task-receipts.js +68 -0
  149. package/dist/data/tasks.js +4 -1
  150. package/dist/entrypoint.js +10 -0
  151. package/dist/fanout/adapters/claude.js +15 -2
  152. package/dist/fanout/adapters/types.d.ts +6 -0
  153. package/dist/fanout/launcher.d.ts +5 -1
  154. package/dist/fanout/launcher.js +34 -3
  155. package/dist/fanout/picker.js +3 -2
  156. package/dist/fanout/usage.js +1 -1
  157. package/dist/generated/memory-ui-graph.browser.js +63 -63
  158. package/dist/graph-core/model.js +24 -3
  159. package/dist/graph-core/types.d.ts +4 -1
  160. package/dist/graph-core/types.js +1 -0
  161. package/dist/init/init-preset.js +7 -3
  162. package/dist/init/init-uninstall.js +2 -11
  163. package/dist/init/teardown.d.ts +3 -0
  164. package/dist/init/teardown.js +47 -0
  165. package/dist/link/context.js +21 -9
  166. package/dist/mcp/plugin-mode.js +1 -1
  167. package/dist/memory-ui-graph.runtime.js +63 -63
  168. package/dist/modules/code-package.d.ts +1 -0
  169. package/dist/modules/code-package.js +36 -7
  170. package/dist/modules/registry.js +14 -13
  171. package/dist/profile-store.d.ts +6 -0
  172. package/dist/profile-store.js +25 -1
  173. package/dist/shell/graph/glyphs.js +4 -0
  174. package/dist/shell/graph/graph-view.js +2 -0
  175. package/dist/status.js +7 -1
  176. package/dist/sync/task-claim.js +3 -2
  177. package/dist/task/lifecycle.js +25 -4
  178. package/dist/test-global-setup.js +5 -0
  179. package/dist/tools/dispatch.js +35 -2
  180. package/dist/tools/tasks.js +10 -1
  181. package/package.json +1 -1
  182. package/plugins/opencode/phren-transcript.js +87 -4
  183. package/starter/global/skills/conductor/SKILL.md +17 -2
  184. package/starter/global/skills/fanout/SKILL.md +3 -0
@@ -17,7 +17,7 @@ import { startChangeRetention } from "./changes.js";
17
17
  import { CodeReindexer, CodeRoutes } from "./code-routes.js";
18
18
  import { WorkspaceContextUsage } from "./context.js";
19
19
  import { DispatchService } from "./dispatch.js";
20
- import { DispatchReturns } from "./dispatch-returns.js";
20
+ import { DispatchReturns, hookWorkers } from "./dispatch-returns.js";
21
21
  import { findPane, paneChatState, recentServers, sharedSnapshot, snapshot, validateTarget } from "./herdr.js";
22
22
  import { LaunchLimiter } from "./limits.js";
23
23
  import { locateProject } from "./locate.js";
@@ -27,20 +27,25 @@ import { TabActivityStore } from "./tab-activity.js";
27
27
  import { childAgentTree } from "./transcripts.js";
28
28
  import { ModelCatalog } from "./models.js";
29
29
  import { ModelSwitcher } from "./model-switch.js";
30
+ import { SettingsSwitcher } from "./settings-switch.js";
30
31
  import { SideQuestions } from "./side-questions.js";
31
32
  import { AccountUsageReader } from "./usage.js";
33
+ import { ResourceMonitor } from "./resources.js";
32
34
  import { createScheduleLauncher, Scheduler, scheduleRunsFile } from "./schedules.js";
33
35
  import { dailyCanaryDue, runCanary } from "./canary.js";
34
36
  import { defaultPhrenPath } from "../shared.js";
35
37
  import { capabilitiesForModules, createRouteHandler, requireRoute, selectedServer, workspacesReader } from "./server-routes.js";
38
+ import { typedMuxRequest } from "./mux-wire.js";
36
39
  import { overviewStream } from "./server-overview.js";
37
40
  import { transcriptStreams } from "./server-stream.js";
38
41
  import { launchSession } from "./server-launch.js";
42
+ import { codexAppServerEnabled, codexServers } from "./codex-servers.js";
43
+ import { CodexAuthKeeper, codexAuthRefreshEnabled } from "./codex-auth-refresh.js";
39
44
  import { localNames } from "./computer-names.js";
40
45
  export { capabilities, capabilitiesForModules, requireRoute } from "./server-routes.js";
41
46
  export { streamCloseReason } from "./server-stream.js";
42
47
  export { herdrAgentName, launchSession } from "./server-launch.js";
43
- export async function serve(version) {
48
+ export async function serve(version, options = {}) {
44
49
  process.umask(0o077);
45
50
  const modules = moduleSnapshot(defaultPhrenPath(), undefined, true);
46
51
  if (!modules.has("hook"))
@@ -67,25 +72,39 @@ export async function serve(version) {
67
72
  return agent.success && typeof pane?.terminal_id === "string" ? { agent: agent.data, terminal: pane.terminal_id } : undefined;
68
73
  } })
69
74
  : undefined;
70
- // Follows what dispatched workers do and tells the dispatching agent.
71
- const returns = dispatches ? new DispatchReturns() : undefined;
72
75
  const locatedDirectories = new Set();
73
76
  const journal = new ActivityJournal();
74
77
  const agentHooks = new AgentHooks(undefined, modules);
78
+ // Follows what dispatched workers do and tells the dispatching agent.
79
+ const returns = dispatches ? new DispatchReturns({
80
+ localWorkers: hookWorkers(agentHooks),
81
+ localAnswer: (target, actionId, decision) => agentHooks.answer(target, actionId, decision),
82
+ // A worker's request the worker's own Hook did not push reaches this Hook's phone.
83
+ onApproval: (receipt, approval) => {
84
+ if (approval.pushed || !agentHooks.push.available)
85
+ return;
86
+ agentHooks.pushForwarded({ provider: receipt.harness, computer: receipt.computer, project: receipt.project,
87
+ request: approval.request ?? approval.title ?? approval.tool, ...(approval.requestKind ? { requestKind: approval.requestKind } : {}) }, decision => returns.answerApproval(receipt.id, decision, approval.actionId));
88
+ return true;
89
+ },
90
+ }) : undefined;
75
91
  // Push is offered only once an APNs sender loaded; phones may still register.
76
92
  if ("approvalPush" in activeCapabilities) {
77
93
  Object.defineProperty(activeCapabilities, "approvalPush", { enumerable: true, get: () => approvalPushCapability(agentHooks.push.status) });
78
94
  }
79
- const modelCatalog = new ModelCatalog();
95
+ const modelCatalog = options.modelCatalog ?? new ModelCatalog();
80
96
  const modelSwitcher = new ModelSwitcher(agentHooks, modelCatalog);
97
+ const settingsSwitcher = new SettingsSwitcher(agentHooks);
81
98
  const sideQuestions = new SideQuestions();
82
99
  const contextUsage = new WorkspaceContextUsage();
83
- const accountUsage = new AccountUsageReader();
100
+ const accountUsage = options.accountUsage ?? new AccountUsageReader();
101
+ const resources = new ResourceMonitor();
84
102
  const tabActivity = new TabActivityStore();
85
- const codexQuestions = new CodexQuestions();
103
+ const codexQuestions = new CodexQuestions(undefined, codexServers);
86
104
  const scheduleStore = defaultPhrenPath();
87
105
  const scheduler = modules.has("schedules") ? new Scheduler({ now: () => new Date(), store: scheduleStore, runsFile: scheduleRunsFile(),
88
- launch: createScheduleLauncher((server, data) => launchSession(server, data), scheduleStore),
106
+ // A schedule starts in its project's folder, which the Hook resolved itself.
107
+ launch: createScheduleLauncher((server, data) => launchSession(server, data, { trustFolder: true }), scheduleStore),
89
108
  push: { notify: value => agentHooks.push.notifySchedule(value) },
90
109
  locateProject: async (project) => (await locateProject(project, await journal.recent()))[0]?.directory }) : undefined;
91
110
  const fanoutMessages = new FanoutMessages({ ...process.env, PHREN_PATH: scheduleStore }, {
@@ -132,16 +151,17 @@ export async function serve(version) {
132
151
  const stopRetention = modules.has("git") ? await startChangeRetention() : () => { };
133
152
  if (modules.has("git"))
134
153
  await rm(path.join(root, "changes-scratch"), { recursive: true, force: true });
135
- const streams = transcriptStreams({ modules, agentHooks, codexQuestions, sideQuestions, info, activeCapabilities });
154
+ const streams = transcriptStreams({ modules, agentHooks, codexQuestions, sideQuestions, settingsSwitcher, info, activeCapabilities });
136
155
  const { stream } = streams;
137
156
  // The phone's overview, pushed over a WebSocket when it changes.
138
157
  const overview = overviewStream({
139
158
  read: workspacesReader({ modules, info, agentHooks, journal, tabActivity, contextUsage }),
140
159
  info: () => ({ ...info, capabilities: info.capabilities }),
141
160
  renew: server => agentHooks.overview.renew(server),
161
+ resources: () => resources.read(),
142
162
  });
143
163
  const http = createServer(createRouteHandler({ version, modules, info, computerID, scheduleStore, scheduler, dispatches, agentHooks,
144
- journal, tabActivity, contextUsage, modelCatalog, modelSwitcher, sideQuestions, accountUsage, codexQuestions, launches, locatedDirectories,
164
+ journal, tabActivity, contextUsage, modelCatalog, modelSwitcher, settingsSwitcher, sideQuestions, accountUsage, resources, codexQuestions, launches, locatedDirectories,
145
165
  fanoutMessages, canary, streams, returns }));
146
166
  http.requestTimeout = 20_000;
147
167
  http.headersTimeout = 10_000;
@@ -165,7 +185,7 @@ export async function serve(version) {
165
185
  ws.clients.delete(oldest);
166
186
  }
167
187
  if (overviewServer !== undefined) {
168
- overview(client, overviewServer, url.searchParams.get("watchApprovals") === "1");
188
+ overview(client, overviewServer, url.searchParams.get("watchApprovals") === "1", url.searchParams.get("resources") === "1", typedMuxRequest(url));
169
189
  return;
170
190
  }
171
191
  if (url.pathname === "/v1/speech/transcribe") {
@@ -182,13 +202,25 @@ export async function serve(version) {
182
202
  await new Promise((resolve, reject) => { http.once("error", reject); http.listen(socketPath(), () => resolve()); });
183
203
  await chmod(socketPath(), 0o600);
184
204
  await agentHooks.start();
205
+ // Codex panes on the Hook's own app-servers: their requests become
206
+ // approval cards, and servers a previous Hook started are rejoined.
207
+ codexServers.setSink({ request: (target, request, answer) => agentHooks.codexRequest(target, request, answer),
208
+ resolved: (target, requestId) => agentHooks.codexResolved(target, requestId) });
209
+ await codexServers.adopt().catch(() => { });
185
210
  void scheduler?.tick().catch(() => { });
186
211
  const scheduleTimer = scheduler ? setInterval(() => { countTick("schedules"); void scheduler.tick().catch(() => { }); }, 30_000) : undefined;
187
212
  // Off unless PHREN_CANARY_DAILY=1 or `phren canary --daily on`.
213
+ // Refresh the shared Codex sign-in before its workers each try to at once.
214
+ const codexAuth = codexAppServerEnabled() && codexAuthRefreshEnabled() ? new CodexAuthKeeper(codexServers) : undefined;
215
+ const codexAuthTimer = codexAuth ? setInterval(() => { void codexAuth.tick().catch(() => { }); }, 60 * 60_000) : undefined;
216
+ if (codexAuth)
217
+ setTimeout(() => { void codexAuth.tick().catch(() => { }); }, 60_000).unref();
188
218
  const canaryTimer = setInterval(() => { countTick("canary"); void dailyCanaryDue().then(due => due ? canary("daily") : undefined).catch(() => { }); }, 10 * 60_000);
189
219
  let recording = false;
190
220
  const activityTimer = setInterval(() => {
191
221
  countTick("activity");
222
+ // Served OpenCode panes: follow new ones, drop those whose process is gone.
223
+ agentHooks.paneServers.tick();
192
224
  if (recording)
193
225
  return;
194
226
  recording = true;
@@ -204,6 +236,8 @@ export async function serve(version) {
204
236
  const name = String(server.session), current = await sharedSnapshot(name, 4000);
205
237
  await tabActivity.observe(name, current);
206
238
  await journal.record(name, objects(current.panes));
239
+ // A Codex app-server whose pane closed is stopped; a dead one forgotten.
240
+ await codexServers.reap(name, current).catch(() => { });
207
241
  // Approvals drawn in a terminal reach a phone with phren closed.
208
242
  await agentHooks.observeWaitingPanes(name, objects(current.panes), async (pane) => {
209
243
  const state = await paneChatState(name, pane, { tokenWhenIdentified: false });
@@ -214,13 +248,14 @@ export async function serve(version) {
214
248
  }
215
249
  catch { /* A disconnected computer keeps its previous local activity. */ }
216
250
  }
251
+ await codexServers.sweep(live.map(server => String(server.session))).catch(() => { });
217
252
  // Dispatch returns ride this tick and its shared snapshots. The returns
218
253
  // loop throttles its own peer polls and never holds up activity.
219
254
  void returns?.tick();
220
255
  })().finally(() => { recording = false; }).catch(() => { });
221
256
  }, 5000);
222
257
  await new Promise(resolve => {
223
- const stop = () => { fanoutMessages.close(); stopRetention(); clearInterval(scheduleTimer); clearInterval(canaryTimer); clearInterval(activityTimer); scheduler?.close(); codeReindexer?.close(); agentHooks.close(); ws.clients.forEach(c => c.terminate()); ws.close(); http.close(() => resolve()); http.closeAllConnections(); };
258
+ const stop = () => { fanoutMessages.close(); stopRetention(); clearInterval(scheduleTimer); clearInterval(canaryTimer); clearInterval(codexAuthTimer); clearInterval(activityTimer); scheduler?.close(); codeReindexer?.close(); codexServers.close(); agentHooks.close(); ws.clients.forEach(c => c.terminate()); ws.close(); http.close(() => resolve()); http.closeAllConnections(); };
224
259
  process.once("SIGTERM", stop);
225
260
  process.once("SIGINT", stop);
226
261
  });
@@ -0,0 +1,81 @@
1
+ import { type Json } from "./protocol.js";
2
+ import type { FinalTurn } from "./schedule-watch.js";
3
+ import { type TurnRecord } from "./turn-records.js";
4
+ /**
5
+ * What a live session's row says about itself beyond Herdr's own status and
6
+ * title, from the pane's turn record (turn-records.ts) and the dispatch label
7
+ * (launch-brief.ts):
8
+ *
9
+ * - A Claude turn that ended while background shells or subagents still run
10
+ * (its Stop's `background` count, less the tasks its transcript shows
11
+ * finishing since, for at most BACKGROUND_STALE_MS), or a Codex session with
12
+ * running subagents or fanout jobs, is still working. Herdr reports it idle, so the
13
+ * phone listed it under IDLE with a moon badge. The tab keeps
14
+ * `agentStatus: "working"` and gains `backgroundTasks`, the count.
15
+ * - A dispatched worker is named by its dispatch label. Claude and Codex title
16
+ * a session after its first prompt, which for a brief launch is
17
+ * "Read and follow the brief in <path>" (or "Brief d35c6189" once they
18
+ * shorten it), so those titles are never shown.
19
+ */
20
+ /** The record, only when it belongs to this pane's terminal and conversation
21
+ * (the guard dispatch returns use): a leftover record of an earlier terminal
22
+ * or session in the same pane must not speak for this one. */
23
+ export declare function ownRecord(record: TurnRecord | undefined, pane: Json, source: unknown, session: string | undefined): TurnRecord | undefined;
24
+ /** The pane's own turn record. OpenCode has no Stop hook to report background work or a dispatch id here. */
25
+ export declare function paneRecord(server: string, pane: Json, session: string | undefined): Promise<TurnRecord | undefined>;
26
+ /** How long after its Stop a background count may keep a row working. A task
27
+ * whose finish the transcript never shows (a dev server left running, a
28
+ * persistent monitor, a notification the tail no longer holds) would
29
+ * otherwise keep it working forever. Matches dispatch returns' wait. */
30
+ export declare const BACKGROUND_STALE_MS: number;
31
+ /** Background tasks the recorded turn ended with that are still running:
32
+ * the Stop's count less those `finishedTasks` (FinalTurn's) says finished
33
+ * after it. Undefined once none are left or the Stop is BACKGROUND_STALE_MS old. */
34
+ export declare function recordedBackground(record: TurnRecord | undefined, finishedTasks?: readonly string[], now?: number): number | undefined;
35
+ /** `recordedBackground` for a pane, reading the transcript (`readFinalTurn`,
36
+ * passed in: schedule-watch imports herdr, which imports this) only when the
37
+ * Stop left background work. Only Claude's Stop reports a count. */
38
+ export declare function liveBackground(record: TurnRecord | undefined, readFinal: (source: "claude", session: string) => Promise<FinalTurn | undefined>, now?: number): Promise<number | undefined>;
39
+ /**
40
+ * Marks a tab whose main turn ended but whose background work continues:
41
+ * an idle or done tab becomes `working` with `backgroundTasks: count`. Called
42
+ * again with a second source (the transcript's running children), it keeps the
43
+ * larger count, never the sum: Claude's own Stop count already includes its
44
+ * subagents. A tab that is working, blocked or waiting on its own is left
45
+ * alone, so `backgroundTasks` never sits on a tab with a live turn.
46
+ */
47
+ export declare function markBackground(tab: Json, count: number | undefined): void;
48
+ /** A tab or workspace label worth showing as a name: not empty, not Herdr's bare numbering, not an id. */
49
+ export declare function meaningfulLabel(value: unknown): string | undefined;
50
+ /** A harness title made from the brief launch's first prompt rather than the work: the prompt itself, the brief path, or "Brief <id>". */
51
+ export declare function isBriefTitle(title: string): boolean;
52
+ /**
53
+ * The name a session is shown under, first that applies:
54
+ * 1. the agent pane's own label, when meaningful (a rename from the phone or
55
+ * from Herdr or tmux itself; a pane has none until someone sets one);
56
+ * 2. the dispatch label its dispatcher gave it;
57
+ * 3. for a dispatch with no stored label (sent before labels were kept), the
58
+ * tab label, else the workspace label, when meaningful;
59
+ * 4. the harness's own title, unless it is brief boilerplate, which is
60
+ * replaced by a meaningful tab or workspace label or dropped (the phone
61
+ * then falls back to the label).
62
+ * Never leaves a row blank: when none applies and `fallbackLabel` (passed, even
63
+ * if undefined) is the label the phone shows without a title and is blank, the raw harness title stands.
64
+ */
65
+ export declare function sessionTitle(input: {
66
+ dispatched: boolean;
67
+ paneLabel?: unknown;
68
+ dispatchLabel?: string;
69
+ harnessTitle?: unknown;
70
+ tabLabel?: unknown;
71
+ workspaceLabel?: unknown;
72
+ fallbackLabel?: unknown;
73
+ }): string | undefined;
74
+ /** `sessionTitle` for a pane, given its own turn record (the guarded one from `paneRecord`). */
75
+ export declare function recordTitle(record: TurnRecord | undefined, input: {
76
+ paneLabel?: unknown;
77
+ harnessTitle?: unknown;
78
+ tabLabel?: unknown;
79
+ workspaceLabel?: unknown;
80
+ fallbackLabel?: unknown;
81
+ }): Promise<string | undefined>;
@@ -0,0 +1,117 @@
1
+ import { briefLabel } from "./launch-brief.js";
2
+ import { provider } from "./protocol.js";
3
+ import { backgroundLeft, readTurn, turnPhase } from "./turn-records.js";
4
+ /**
5
+ * What a live session's row says about itself beyond Herdr's own status and
6
+ * title, from the pane's turn record (turn-records.ts) and the dispatch label
7
+ * (launch-brief.ts):
8
+ *
9
+ * - A Claude turn that ended while background shells or subagents still run
10
+ * (its Stop's `background` count, less the tasks its transcript shows
11
+ * finishing since, for at most BACKGROUND_STALE_MS), or a Codex session with
12
+ * running subagents or fanout jobs, is still working. Herdr reports it idle, so the
13
+ * phone listed it under IDLE with a moon badge. The tab keeps
14
+ * `agentStatus: "working"` and gains `backgroundTasks`, the count.
15
+ * - A dispatched worker is named by its dispatch label. Claude and Codex title
16
+ * a session after its first prompt, which for a brief launch is
17
+ * "Read and follow the brief in <path>" (or "Brief d35c6189" once they
18
+ * shorten it), so those titles are never shown.
19
+ */
20
+ /** The record, only when it belongs to this pane's terminal and conversation
21
+ * (the guard dispatch returns use): a leftover record of an earlier terminal
22
+ * or session in the same pane must not speak for this one. */
23
+ export function ownRecord(record, pane, source, session) {
24
+ return record && session && record.terminal === pane.terminal_id && record.source === source && record.session === session ? record : undefined;
25
+ }
26
+ /** The pane's own turn record. OpenCode has no Stop hook to report background work or a dispatch id here. */
27
+ export async function paneRecord(server, pane, session) {
28
+ if (!session || pane.agent === "opencode" || !provider.safeParse(pane.agent).success)
29
+ return undefined;
30
+ return ownRecord(await readTurn(server, String(pane.pane_id)).catch(() => undefined), pane, pane.agent, session);
31
+ }
32
+ /** How long after its Stop a background count may keep a row working. A task
33
+ * whose finish the transcript never shows (a dev server left running, a
34
+ * persistent monitor, a notification the tail no longer holds) would
35
+ * otherwise keep it working forever. Matches dispatch returns' wait. */
36
+ export const BACKGROUND_STALE_MS = 2 * 60 * 60 * 1000;
37
+ /** Background tasks the recorded turn ended with that are still running:
38
+ * the Stop's count less those `finishedTasks` (FinalTurn's) says finished
39
+ * after it. Undefined once none are left or the Stop is BACKGROUND_STALE_MS old. */
40
+ export function recordedBackground(record, finishedTasks, now = Date.now()) {
41
+ if (!record)
42
+ return undefined;
43
+ const phase = turnPhase(record);
44
+ if (phase.phase !== "ended" || !(now - Date.parse(phase.at) < BACKGROUND_STALE_MS))
45
+ return undefined;
46
+ return backgroundLeft(phase.background, phase.at, finishedTasks) || undefined;
47
+ }
48
+ /** `recordedBackground` for a pane, reading the transcript (`readFinalTurn`,
49
+ * passed in: schedule-watch imports herdr, which imports this) only when the
50
+ * Stop left background work. Only Claude's Stop reports a count. */
51
+ export async function liveBackground(record, readFinal, now = Date.now()) {
52
+ if (!record || record.source !== "claude" || !recordedBackground(record, [], now))
53
+ return undefined;
54
+ const final = await readFinal("claude", record.session).catch(() => undefined);
55
+ return recordedBackground(record, final?.finishedTasks, now);
56
+ }
57
+ /**
58
+ * Marks a tab whose main turn ended but whose background work continues:
59
+ * an idle or done tab becomes `working` with `backgroundTasks: count`. Called
60
+ * again with a second source (the transcript's running children), it keeps the
61
+ * larger count, never the sum: Claude's own Stop count already includes its
62
+ * subagents. A tab that is working, blocked or waiting on its own is left
63
+ * alone, so `backgroundTasks` never sits on a tab with a live turn.
64
+ */
65
+ export function markBackground(tab, count) {
66
+ if (!count || count < 1)
67
+ return;
68
+ if (tab.agentStatus === "idle" || tab.agentStatus === "done") {
69
+ tab.agentStatus = "working";
70
+ tab.backgroundTasks = count;
71
+ }
72
+ else if (typeof tab.backgroundTasks === "number")
73
+ tab.backgroundTasks = Math.max(tab.backgroundTasks, count);
74
+ }
75
+ /** A tab or workspace label worth showing as a name: not empty, not Herdr's bare numbering, not an id. */
76
+ export function meaningfulLabel(value) {
77
+ if (typeof value !== "string")
78
+ return undefined;
79
+ const text = value.trim();
80
+ return text && !/^\d+$/.test(text) && !/^\S*:\S*$/.test(text) && !/^[A-Za-z]{1,2}[_-]?\d+[A-Za-z]?$/.test(text) ? text : undefined;
81
+ }
82
+ /** A harness title made from the brief launch's first prompt rather than the work: the prompt itself, the brief path, or "Brief <id>". */
83
+ export function isBriefTitle(title) {
84
+ return /^\s*read and follow the brief/i.test(title) || title.includes("/briefs/")
85
+ || /^\s*brief\s+[0-9a-f]{8}[0-9a-f-]*\s*(…|\.\.\.)?\s*$/i.test(title);
86
+ }
87
+ /**
88
+ * The name a session is shown under, first that applies:
89
+ * 1. the agent pane's own label, when meaningful (a rename from the phone or
90
+ * from Herdr or tmux itself; a pane has none until someone sets one);
91
+ * 2. the dispatch label its dispatcher gave it;
92
+ * 3. for a dispatch with no stored label (sent before labels were kept), the
93
+ * tab label, else the workspace label, when meaningful;
94
+ * 4. the harness's own title, unless it is brief boilerplate, which is
95
+ * replaced by a meaningful tab or workspace label or dropped (the phone
96
+ * then falls back to the label).
97
+ * Never leaves a row blank: when none applies and `fallbackLabel` (passed, even
98
+ * if undefined) is the label the phone shows without a title and is blank, the raw harness title stands.
99
+ */
100
+ export function sessionTitle(input) {
101
+ const renamed = meaningfulLabel(input.paneLabel);
102
+ if (renamed)
103
+ return renamed;
104
+ if (input.dispatchLabel)
105
+ return input.dispatchLabel;
106
+ const named = meaningfulLabel(input.tabLabel) ?? meaningfulLabel(input.workspaceLabel);
107
+ const title = typeof input.harnessTitle === "string" && input.harnessTitle.trim() ? input.harnessTitle : undefined;
108
+ const chosen = input.dispatched ? named : !title ? undefined : isBriefTitle(title) ? named : title;
109
+ const label = input.fallbackLabel;
110
+ const blank = "fallbackLabel" in input && (typeof label !== "string" || !label.trim());
111
+ return chosen ?? (blank ? title : undefined);
112
+ }
113
+ /** `sessionTitle` for a pane, given its own turn record (the guarded one from `paneRecord`). */
114
+ export async function recordTitle(record, input) {
115
+ const dispatch = record?.dispatch;
116
+ return sessionTitle({ ...input, dispatched: !!dispatch, dispatchLabel: dispatch ? await briefLabel(dispatch) : undefined });
117
+ }
@@ -0,0 +1,48 @@
1
+ import { z } from "zod";
2
+ import type { PaneClient } from "./opencode-pane-server.js";
3
+ import { type Json, type Target } from "./protocol.js";
4
+ import { type TerminalProvider } from "./terminal.js";
5
+ /** Renaming a session from the phone: the pane's and tab's terminal labels,
6
+ * then the harness's own rename where one can be driven remotely. */
7
+ /** What the phone may send as a session name: 1 to 80 characters, no control characters. */
8
+ export declare const renameLabel: z.ZodString;
9
+ export declare const renameRequest: z.ZodObject<{
10
+ workspaceId: z.ZodString;
11
+ tabId: z.ZodString;
12
+ paneId: z.ZodOptional<z.ZodString>;
13
+ label: z.ZodString;
14
+ }, z.core.$strip>;
15
+ export type NativeMechanism = "slash-command" | "app-server" | "opencode-api" | "none";
16
+ export interface NativeResult {
17
+ harness: string;
18
+ mechanism: NativeMechanism;
19
+ applied: boolean;
20
+ reason?: string;
21
+ }
22
+ /** Everything the rename touches outside this file; tests pass their own. */
23
+ export interface RenameDeps {
24
+ snapshot(server: string): Promise<Json>;
25
+ identity(server: string, pane: Json): Promise<string | undefined>;
26
+ terminal(): TerminalProvider;
27
+ codexRename(target: Target, label: string): Promise<boolean | undefined>;
28
+ opencodeClient(server: string, pane: string): PaneClient | undefined;
29
+ /** The name Claude's transcript for `target` last carries as its `custom-title`. */
30
+ claudeTitle(target: Target): Promise<string | undefined>;
31
+ /** The name Codex's `session_index.jsonl` last holds for a thread. */
32
+ codexIndexTitle(thread: string): Promise<string | undefined>;
33
+ sleep(ms: number): Promise<void>;
34
+ /** How long a typed rename may take to show in the harness's own records. */
35
+ verifyMs: number;
36
+ }
37
+ /** The last `custom-title` in the tail of a Claude transcript. */
38
+ export declare function lastCustomTitle(text: string): string | undefined;
39
+ /** The last `thread_name` written for `thread` in a Codex `session_index.jsonl`. */
40
+ export declare function lastIndexedName(text: string, thread: string): string | undefined;
41
+ export declare const defaultRenameDeps: RenameDeps;
42
+ /** The agent pane a rename addresses: the named pane, else the tab's only agent pane, else its only pane. */
43
+ export declare function renamePane(panes: Json[], paneId: string | undefined): {
44
+ pane: Json;
45
+ renameTab: boolean;
46
+ };
47
+ /** `POST /v1/sessions/rename`: terminal labels first, then the harness's own name. */
48
+ export declare function renameSession(server: string, data: Json, deps?: RenameDeps): Promise<Json>;
@@ -0,0 +1,190 @@
1
+ import { open } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { z } from "zod";
4
+ import { codexHome } from "../home-paths.js";
5
+ import { stripTerminal } from "../terminal-text.js";
6
+ import { codexServers } from "./codex-servers.js";
7
+ import { paneIdentity, snapshot } from "./herdr.js";
8
+ import { emptyComposer } from "./model-switch.js";
9
+ import { paneClient, servedPane } from "./opencode-panes.js";
10
+ import { BridgeError, id, objects } from "./protocol.js";
11
+ import { terminalProvider } from "./terminal.js";
12
+ import { visibleTerminalChoice } from "./terminal-choice.js";
13
+ import { targetTranscriptPath } from "./transcripts.js";
14
+ /** Renaming a session from the phone: the pane's and tab's terminal labels,
15
+ * then the harness's own rename where one can be driven remotely. */
16
+ /** What the phone may send as a session name: 1 to 80 characters, no control characters. */
17
+ export const renameLabel = z.string().trim().min(1).max(80).refine(t => !/[\x00-\x1f\x7f]/.test(t));
18
+ export const renameRequest = z.object({ workspaceId: id, tabId: id, paneId: id.optional(), label: renameLabel });
19
+ const TAIL_BYTES = 262_144;
20
+ /** The last `custom-title` in the tail of a Claude transcript. */
21
+ export function lastCustomTitle(text) {
22
+ for (const line of text.split("\n").reverse()) {
23
+ if (!line.includes('"custom-title"'))
24
+ continue;
25
+ try {
26
+ const row = JSON.parse(line);
27
+ if (row.type === "custom-title" && typeof row.customTitle === "string")
28
+ return row.customTitle;
29
+ }
30
+ catch { /* a line cut by the tail window */ }
31
+ }
32
+ return undefined;
33
+ }
34
+ /** The last `thread_name` written for `thread` in a Codex `session_index.jsonl`. */
35
+ export function lastIndexedName(text, thread) {
36
+ for (const line of text.split("\n").reverse()) {
37
+ if (!line.includes(thread))
38
+ continue;
39
+ try {
40
+ const row = JSON.parse(line);
41
+ if (row.id === thread && typeof row.thread_name === "string")
42
+ return row.thread_name;
43
+ }
44
+ catch { /* a line cut by the tail window */ }
45
+ }
46
+ return undefined;
47
+ }
48
+ async function tail(file) {
49
+ const handle = await open(file, "r").catch(() => undefined);
50
+ if (!handle)
51
+ return undefined;
52
+ try {
53
+ const { size } = await handle.stat();
54
+ const length = Math.min(size, TAIL_BYTES), buffer = Buffer.alloc(length);
55
+ await handle.read(buffer, 0, length, size - length);
56
+ return buffer.toString("utf8");
57
+ }
58
+ finally {
59
+ await handle.close();
60
+ }
61
+ }
62
+ export const defaultRenameDeps = {
63
+ snapshot,
64
+ identity: (server, pane) => paneIdentity(server, pane, true),
65
+ terminal: terminalProvider,
66
+ async codexRename(target, label) {
67
+ const entry = codexServers.forTarget(target);
68
+ if (!entry)
69
+ return undefined;
70
+ await codexServers.renameThread(entry, label);
71
+ return true;
72
+ },
73
+ opencodeClient(server, pane) {
74
+ const entry = servedPane(server, pane);
75
+ return entry ? paneClient(entry) : undefined;
76
+ },
77
+ async claudeTitle(target) {
78
+ const text = await tail(await targetTranscriptPath({ ...target, source: "claude" }));
79
+ return text === undefined ? undefined : lastCustomTitle(text);
80
+ },
81
+ async codexIndexTitle(thread) {
82
+ const text = await tail(path.join(codexHome(), "session_index.jsonl"));
83
+ return text === undefined ? undefined : lastIndexedName(text, thread);
84
+ },
85
+ sleep: ms => new Promise(resolve => setTimeout(resolve, ms)),
86
+ verifyMs: 4_000,
87
+ };
88
+ /** The agent pane a rename addresses: the named pane, else the tab's only agent pane, else its only pane. */
89
+ export function renamePane(panes, paneId) {
90
+ if (!panes.length)
91
+ throw new BridgeError(409, "The tab changed.");
92
+ const agents = panes.filter(p => p.agent);
93
+ if (paneId) {
94
+ const pane = panes.find(p => p.pane_id === paneId);
95
+ if (!pane)
96
+ throw new BridgeError(409, "The pane changed.");
97
+ return { pane, renameTab: agents.length ? agents.length === 1 && !!pane.agent : panes.length === 1 };
98
+ }
99
+ if (agents.length === 1)
100
+ return { pane: agents[0], renameTab: true };
101
+ if (!agents.length && panes.length === 1)
102
+ return { pane: panes[0], renameTab: true };
103
+ throw new BridgeError(400, "Choose a pane to rename.");
104
+ }
105
+ /** Types a slash command into an agent pane that is showing an empty composer. */
106
+ async function typeCommand(deps, server, pane, text) {
107
+ const terminal = deps.terminal();
108
+ const before = await terminal.readScreen(server, String(pane.pane_id), { scope: "pane", source: "visible", lines: 40, format: "ansi", timeoutMs: 2_000 }).catch(() => "");
109
+ const composer = before.split(/\r?\n/).reverse().find(line => /^\s*[›❯>]/.test(stripTerminal(line)));
110
+ if (!composer || !emptyComposer(composer) || visibleTerminalChoice(stripTerminal(before)))
111
+ return "the terminal has a draft or an open menu";
112
+ await terminal.prompt(server, String(pane.pane_id), text);
113
+ return undefined;
114
+ }
115
+ /** Polls `seen` until it holds or the deadline passes. */
116
+ async function confirmed(deps, seen) {
117
+ const deadline = Date.now() + deps.verifyMs;
118
+ do {
119
+ if (await seen().catch(() => false))
120
+ return true;
121
+ await deps.sleep(150);
122
+ } while (Date.now() < deadline);
123
+ return false;
124
+ }
125
+ /** The harness's own rename for the pane's session, never failing the request: a refusal is reported as `reason`. */
126
+ async function nativeRename(deps, server, workspace, tab, pane, label) {
127
+ const harness = typeof pane.agent === "string" && pane.agent ? pane.agent : "none";
128
+ const skip = (mechanism, reason) => ({ harness, mechanism, applied: false, reason });
129
+ if (!["claude", "codex", "opencode"].includes(harness))
130
+ return skip("none", "This harness has no remote rename.");
131
+ const paneId = String(pane.pane_id), status = String(pane.agent_status);
132
+ let session;
133
+ try {
134
+ session = await deps.identity(server, pane);
135
+ }
136
+ catch {
137
+ session = undefined;
138
+ }
139
+ if (!session && harness !== "opencode")
140
+ return skip("none", "The session is not identified yet.");
141
+ const target = { server, workspace, tab, pane: paneId, source: harness, session: session ?? "" };
142
+ let mechanism = harness === "opencode" ? "opencode-api" : "slash-command";
143
+ try {
144
+ if (harness === "opencode") {
145
+ const client = deps.opencodeClient(server, paneId);
146
+ if (!client)
147
+ return skip("none", "This OpenCode was not started by the Hook.");
148
+ const chosen = session ?? (await client.currentSession())?.id;
149
+ if (!chosen)
150
+ return skip("opencode-api", "OpenCode has no session yet.");
151
+ const title = await client.setTitle(chosen, label);
152
+ return title === label ? { harness, mechanism: "opencode-api", applied: true } : skip("opencode-api", "OpenCode did not confirm the new name.");
153
+ }
154
+ if (harness === "codex") {
155
+ mechanism = "app-server";
156
+ const served = await deps.codexRename(target, label);
157
+ if (served)
158
+ return { harness, mechanism, applied: true };
159
+ mechanism = "slash-command";
160
+ }
161
+ // A typed command runs only where the harness reads it as one: never over a dialog.
162
+ if (["blocked", "waiting", "unknown"].includes(status))
163
+ return skip("slash-command", "The agent needs input in the terminal first.");
164
+ if (harness === "codex" && status === "working")
165
+ return skip("slash-command", "The agent is working.");
166
+ const refused = await typeCommand(deps, server, pane, `/rename ${label}`);
167
+ if (refused)
168
+ return skip("slash-command", `Not typed: ${refused}.`);
169
+ const applied = await confirmed(deps, harness === "claude" ? async () => (await deps.claudeTitle(target)) === label
170
+ : async () => (await deps.codexIndexTitle(session)) === label);
171
+ return applied ? { harness, mechanism: "slash-command", applied: true } : skip("slash-command", "The harness did not confirm the new name.");
172
+ }
173
+ catch (error) {
174
+ return skip(mechanism, error instanceof Error ? error.message.slice(0, 200) : "The rename failed.");
175
+ }
176
+ }
177
+ /** `POST /v1/sessions/rename`: terminal labels first, then the harness's own name. */
178
+ export async function renameSession(server, data, deps = defaultRenameDeps) {
179
+ const { workspaceId, tabId, paneId, label } = renameRequest.parse(data);
180
+ const s = await deps.snapshot(server);
181
+ if (!objects(s.tabs).some(t => t.tab_id === tabId && t.workspace_id === workspaceId))
182
+ throw new BridgeError(409, "The tab changed.");
183
+ const { pane, renameTab } = renamePane(objects(s.panes).filter(p => p.tab_id === tabId && p.workspace_id === workspaceId), paneId);
184
+ const terminal = deps.terminal();
185
+ await terminal.renamePane(server, String(pane.pane_id), label);
186
+ if (renameTab)
187
+ await terminal.groupAction(server, "rename", { workspace: workspaceId, tab: tabId }, label);
188
+ const native = await nativeRename(deps, server, workspaceId, tabId, pane, label);
189
+ return { ok: true, label, pane: pane.pane_id, native };
190
+ }
@@ -5,7 +5,7 @@ import { objects } from "./protocol.js";
5
5
  import { snapshot } from "./herdr.js";
6
6
  import { terminalProvider } from "./terminal.js";
7
7
  import { webServers } from "./projects.js";
8
- import { transcriptPath } from "./transcripts.js";
8
+ import { targetTranscriptPath } from "./transcripts.js";
9
9
  /**
10
10
  * The web servers one agent session owns, for the chat's ••• menu. Never a
11
11
  * machine-wide list: a server belongs to a session only when
@@ -110,7 +110,7 @@ async function transcriptTail(file) {
110
110
  export async function sessionWebServers(target, pane) {
111
111
  const [servers, table, own, file] = await Promise.all([
112
112
  webServers(), processTable(target.session), paneRoots(target.server, pane.pane_id),
113
- transcriptPath(target.source, target.session).catch(() => undefined),
113
+ targetTranscriptPath(target).catch(() => undefined),
114
114
  ]);
115
115
  const parents = table.parents;
116
116
  const ownRoots = new Set([...own, ...table.runners]);