@phren/cli 0.3.11 → 0.3.13

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 (182) hide show
  1. package/dist/bridge/account-usage.d.ts +124 -0
  2. package/dist/bridge/account-usage.js +258 -0
  3. package/dist/bridge/agent-hook-stores.d.ts +3 -0
  4. package/dist/bridge/agent-hook-stores.js +5 -0
  5. package/dist/bridge/agent-hooks.d.ts +162 -5
  6. package/dist/bridge/agent-hooks.js +682 -49
  7. package/dist/bridge/approval-summary.d.ts +16 -0
  8. package/dist/bridge/approval-summary.js +133 -0
  9. package/dist/bridge/authority-command.d.ts +20 -0
  10. package/dist/bridge/authority-command.js +120 -0
  11. package/dist/bridge/authority.d.ts +223 -0
  12. package/dist/bridge/authority.js +231 -0
  13. package/dist/bridge/claude-account-setup.d.ts +14 -0
  14. package/dist/bridge/claude-account-setup.js +69 -0
  15. package/dist/bridge/claude-accounts.d.ts +49 -0
  16. package/dist/bridge/claude-accounts.js +195 -0
  17. package/dist/bridge/code-routes.js +2 -2
  18. package/dist/bridge/codex-app-server.d.ts +144 -0
  19. package/dist/bridge/codex-app-server.js +319 -0
  20. package/dist/bridge/codex-auth-refresh.d.ts +33 -0
  21. package/dist/bridge/codex-auth-refresh.js +71 -0
  22. package/dist/bridge/codex-hook-trust.d.ts +27 -0
  23. package/dist/bridge/codex-hook-trust.js +237 -0
  24. package/dist/bridge/codex-question-reply.d.ts +16 -0
  25. package/dist/bridge/codex-question-reply.js +57 -0
  26. package/dist/bridge/codex-review-mode.d.ts +10 -0
  27. package/dist/bridge/codex-review-mode.js +74 -0
  28. package/dist/bridge/codex-servers.d.ts +217 -0
  29. package/dist/bridge/codex-servers.js +636 -0
  30. package/dist/bridge/command.js +97 -4
  31. package/dist/bridge/computer-identity.d.ts +75 -0
  32. package/dist/bridge/computer-identity.js +166 -0
  33. package/dist/bridge/conductor-group.d.ts +91 -8
  34. package/dist/bridge/conductor-group.js +105 -9
  35. package/dist/bridge/conductor-role.d.ts +94 -0
  36. package/dist/bridge/conductor-role.js +176 -0
  37. package/dist/bridge/conductor-sets.d.ts +20 -0
  38. package/dist/bridge/conductor-sets.js +59 -0
  39. package/dist/bridge/dispatch-command.d.ts +3 -0
  40. package/dist/bridge/dispatch-command.js +82 -12
  41. package/dist/bridge/dispatch-returns.d.ts +128 -19
  42. package/dist/bridge/dispatch-returns.js +371 -54
  43. package/dist/bridge/dispatch.d.ts +128 -3
  44. package/dist/bridge/dispatch.js +303 -42
  45. package/dist/bridge/fanouts.d.ts +7 -1
  46. package/dist/bridge/fanouts.js +39 -4
  47. package/dist/bridge/folder-trust.d.ts +56 -0
  48. package/dist/bridge/folder-trust.js +195 -0
  49. package/dist/bridge/grants.d.ts +22 -1
  50. package/dist/bridge/grants.js +57 -9
  51. package/dist/bridge/hand-off-queue.d.ts +74 -0
  52. package/dist/bridge/hand-off-queue.js +235 -0
  53. package/dist/bridge/hand-off.d.ts +30 -10
  54. package/dist/bridge/hand-off.js +79 -46
  55. package/dist/bridge/harness-status.d.ts +11 -0
  56. package/dist/bridge/harness-status.js +32 -0
  57. package/dist/bridge/harnesses.d.ts +39 -0
  58. package/dist/bridge/harnesses.js +65 -0
  59. package/dist/bridge/health.d.ts +2 -0
  60. package/dist/bridge/health.js +1 -1
  61. package/dist/bridge/herdr.d.ts +11 -2
  62. package/dist/bridge/herdr.js +98 -23
  63. package/dist/bridge/hook-fast.d.ts +4 -0
  64. package/dist/bridge/hook-fast.js +68 -0
  65. package/dist/bridge/install.d.ts +16 -1
  66. package/dist/bridge/install.js +102 -21
  67. package/dist/bridge/launch-brief.d.ts +96 -0
  68. package/dist/bridge/launch-brief.js +164 -0
  69. package/dist/bridge/model-switch.d.ts +3 -0
  70. package/dist/bridge/model-switch.js +17 -1
  71. package/dist/bridge/models.d.ts +8 -4
  72. package/dist/bridge/models.js +24 -8
  73. package/dist/bridge/mux-wire.d.ts +9 -0
  74. package/dist/bridge/mux-wire.js +19 -0
  75. package/dist/bridge/opencode-pane-server.d.ts +113 -0
  76. package/dist/bridge/opencode-pane-server.js +332 -0
  77. package/dist/bridge/opencode-panes.d.ts +111 -0
  78. package/dist/bridge/opencode-panes.js +295 -0
  79. package/dist/bridge/pane-accounts.d.ts +8 -0
  80. package/dist/bridge/pane-accounts.js +46 -0
  81. package/dist/bridge/pane-status.d.ts +12 -0
  82. package/dist/bridge/pane-status.js +50 -1
  83. package/dist/bridge/prompt-startup.d.ts +5 -0
  84. package/dist/bridge/prompt-startup.js +24 -0
  85. package/dist/bridge/protocol.d.ts +5 -0
  86. package/dist/bridge/protocol.js +4 -0
  87. package/dist/bridge/push.d.ts +11 -4
  88. package/dist/bridge/push.js +27 -4
  89. package/dist/bridge/questions.d.ts +37 -2
  90. package/dist/bridge/questions.js +158 -15
  91. package/dist/bridge/resources.d.ts +9 -3
  92. package/dist/bridge/resources.js +24 -8
  93. package/dist/bridge/schedule-format.d.ts +2 -0
  94. package/dist/bridge/schedule-format.js +3 -0
  95. package/dist/bridge/schedule-launch.d.ts +2 -1
  96. package/dist/bridge/schedule-launch.js +27 -53
  97. package/dist/bridge/schedule-watch.d.ts +24 -1
  98. package/dist/bridge/schedule-watch.js +89 -2
  99. package/dist/bridge/server-launch.d.ts +22 -5
  100. package/dist/bridge/server-launch.js +238 -32
  101. package/dist/bridge/server-overview.d.ts +10 -3
  102. package/dist/bridge/server-overview.js +32 -15
  103. package/dist/bridge/server-pane-routes.d.ts +3 -0
  104. package/dist/bridge/server-pane-routes.js +150 -18
  105. package/dist/bridge/server-routes.d.ts +11 -0
  106. package/dist/bridge/server-routes.js +214 -36
  107. package/dist/bridge/server-stream.d.ts +2 -0
  108. package/dist/bridge/server-stream.js +22 -8
  109. package/dist/bridge/server.d.ts +6 -1
  110. package/dist/bridge/server.js +58 -13
  111. package/dist/bridge/session-activity.d.ts +93 -0
  112. package/dist/bridge/session-activity.js +139 -0
  113. package/dist/bridge/session-rename.d.ts +48 -0
  114. package/dist/bridge/session-rename.js +190 -0
  115. package/dist/bridge/session-servers.js +2 -2
  116. package/dist/bridge/settings-switch.d.ts +60 -0
  117. package/dist/bridge/settings-switch.js +287 -0
  118. package/dist/bridge/speech-voice.d.ts +55 -0
  119. package/dist/bridge/speech-voice.js +132 -0
  120. package/dist/bridge/speech.d.ts +70 -11
  121. package/dist/bridge/speech.js +169 -41
  122. package/dist/bridge/stalls.d.ts +22 -0
  123. package/dist/bridge/stalls.js +57 -0
  124. package/dist/bridge/sudo.d.ts +209 -0
  125. package/dist/bridge/sudo.js +501 -0
  126. package/dist/bridge/terminal-herdr.js +9 -3
  127. package/dist/bridge/terminal-tmux.d.ts +15 -3
  128. package/dist/bridge/terminal-tmux.js +103 -13
  129. package/dist/bridge/terminal.d.ts +27 -4
  130. package/dist/bridge/terminal.js +8 -1
  131. package/dist/bridge/transcript-claude.d.ts +4 -0
  132. package/dist/bridge/transcript-claude.js +186 -16
  133. package/dist/bridge/transcript-codex.d.ts +0 -2
  134. package/dist/bridge/transcript-codex.js +29 -4
  135. package/dist/bridge/transcript-preview.d.ts +1 -0
  136. package/dist/bridge/transcript-preview.js +24 -4
  137. package/dist/bridge/transcripts.d.ts +15 -2
  138. package/dist/bridge/transcripts.js +47 -16
  139. package/dist/bridge/turn-records.d.ts +85 -0
  140. package/dist/bridge/turn-records.js +143 -0
  141. package/dist/bridge/uploads.d.ts +3 -0
  142. package/dist/bridge/uploads.js +14 -0
  143. package/dist/bridge/usage.d.ts +56 -10
  144. package/dist/bridge/usage.js +190 -45
  145. package/dist/bridge-hook.mjs +27975 -20636
  146. package/dist/cli/claude-unmanaged.d.ts +12 -0
  147. package/dist/cli/claude-unmanaged.js +105 -0
  148. package/dist/cli/schedules.js +2 -1
  149. package/dist/cli/session-start.js +10 -1
  150. package/dist/cli/session-stop.js +9 -1
  151. package/dist/cli-registry.js +31 -6
  152. package/dist/data/task-receipts.d.ts +19 -0
  153. package/dist/data/task-receipts.js +68 -0
  154. package/dist/data/tasks.js +4 -1
  155. package/dist/generated/memory-ui-graph.browser.js +63 -63
  156. package/dist/graph-core/model.js +24 -3
  157. package/dist/graph-core/types.d.ts +4 -1
  158. package/dist/graph-core/types.js +1 -0
  159. package/dist/init/init-preset.js +7 -3
  160. package/dist/init/init-uninstall.js +2 -11
  161. package/dist/init/teardown.d.ts +3 -0
  162. package/dist/init/teardown.js +47 -0
  163. package/dist/link/context.js +21 -9
  164. package/dist/mcp/plugin-mode.js +1 -1
  165. package/dist/memory-ui-graph.runtime.js +63 -63
  166. package/dist/modules/code-package.d.ts +1 -0
  167. package/dist/modules/code-package.js +36 -7
  168. package/dist/modules/registry.js +17 -16
  169. package/dist/profile-store.d.ts +6 -0
  170. package/dist/profile-store.js +25 -1
  171. package/dist/shell/graph/glyphs.js +4 -0
  172. package/dist/shell/graph/graph-view.js +2 -0
  173. package/dist/status.js +7 -1
  174. package/dist/sync/task-claim.js +3 -2
  175. package/dist/task/lifecycle.js +25 -4
  176. package/dist/test-global-setup.js +5 -0
  177. package/dist/tools/dispatch.js +52 -4
  178. package/dist/tools/tasks.js +10 -1
  179. package/package.json +1 -1
  180. package/plugins/opencode/phren-transcript.js +87 -4
  181. package/starter/global/AGENTS.md +4 -0
  182. package/starter/global/skills/conductor/SKILL.md +51 -4
@@ -83,10 +83,71 @@ function turnError(raw, source) {
83
83
  const error = object(object(raw.payload).error), message = typeof error.message === "string" ? error.message.replace(/\s+/g, " ").trim() : "";
84
84
  return message ? message.slice(0, 500) : undefined;
85
85
  }
86
+ /** The owner stopping a turn: Claude's interruption marker, Codex's aborted turn. */
87
+ function turnInterrupted(raw, source) {
88
+ if (source === "codex")
89
+ return raw.type === "event_msg" && object(raw.payload).type === "turn_aborted";
90
+ if (source !== "claude" || raw.type !== "user")
91
+ return false;
92
+ const content = object(raw.message).content;
93
+ const text = typeof content === "string" ? content : objects(content).filter(block => block.type === "text").map(block => String(block.text ?? "")).join("");
94
+ return text.startsWith("[Request interrupted by user");
95
+ }
96
+ /** Claude Code background work a transcript line starts or ends, by task id:
97
+ * a backgrounded Bash call, an async subagent or a Monitor start one; a
98
+ * task-notification with a final status, or a TaskStop, ends it. A
99
+ * persistent monitor runs for the whole session and is never waited on.
100
+ * `finished` keeps when each task's first final notification was written.
101
+ * A notification reaching an idle session is written as a queue-operation
102
+ * row, and may stay there with no new turn to deliver it. */
103
+ /** A backgrounded command that runs until killed rather than finishing:
104
+ * following a log, watching files, serving a dev build. Nobody waits on it. */
105
+ export const ENDLESS_COMMAND = /\btail\s+(?:-[a-zA-Z]*[fF][a-zA-Z]*\b|--follow\b)|\bjournalctl\b[^|;&]*\s(?:-[a-zA-Z]*f[a-zA-Z]*\b|--follow\b)|\blog\s+stream\b|\blogcat\b|\bwatch\s|--watch\b|\binotifywait\b[^|;&]*\s-m\b|\bfswatch\b|\b(?:npm|pnpm|yarn|bun)\s+(?:run\s+)?(?:dev|serve|preview)\b|\bhttp\.server\b|\bsleep\s+infinity\b/;
106
+ function backgroundTasks(raw, running, finished, tail) {
107
+ const result = object(raw.toolUseResult), blocks = objects(object(raw.message).content);
108
+ if (raw.type === "assistant") {
109
+ for (const block of blocks) {
110
+ const input = object(block.input);
111
+ if (block.type === "tool_use" && typeof block.id === "string" && input.run_in_background === true && typeof input.command === "string")
112
+ tail.commands.set(block.id, input.command.slice(0, 2_000));
113
+ }
114
+ }
115
+ const shell = typeof result.backgroundTaskId === "string" ? result.backgroundTaskId : undefined;
116
+ const monitor = typeof result.taskId === "string" && result.persistent !== true && typeof result.timeoutMs === "number" ? result.taskId : undefined;
117
+ const started = shell ?? (result.isAsync === true && typeof result.agentId === "string" ? result.agentId : monitor);
118
+ if (started)
119
+ running.add(started);
120
+ if (shell) {
121
+ const call = blocks.find(block => block.type === "tool_result")?.tool_use_id;
122
+ const command = typeof call === "string" ? tail.commands.get(call) : undefined;
123
+ if (!command || !ENDLESS_COMMAND.test(command))
124
+ tail.awaited.add(shell);
125
+ }
126
+ else if (monitor)
127
+ tail.awaited.add(monitor);
128
+ if (typeof result.task_id === "string" && typeof result.message === "string" && /\bstopped\b/i.test(result.message)) {
129
+ running.delete(result.task_id);
130
+ tail.awaited.delete(result.task_id);
131
+ }
132
+ const content = object(raw.message).content, attachment = object(raw.attachment);
133
+ const notices = [typeof content === "string" ? content : "", typeof attachment.prompt === "string" ? attachment.prompt : "",
134
+ raw.type === "queue-operation" && typeof raw.content === "string" ? raw.content : ""];
135
+ // A monitor's events arrive as notifications too, without a final status.
136
+ for (const block of notices.flatMap(notice => notice.split("<task-notification>").slice(1))) {
137
+ const id = /<task-id>([^<\s]{1,100})<\/task-id>/.exec(block)?.[1];
138
+ if (!id || !/<status>(?:completed|failed|killed|stopped)<\/status>/.test(block))
139
+ continue;
140
+ running.delete(id);
141
+ tail.awaited.delete(id);
142
+ if (!finished.has(id) && typeof raw.timestamp === "string" && !Number.isNaN(Date.parse(raw.timestamp)))
143
+ finished.set(id, raw.timestamp);
144
+ }
145
+ }
86
146
  /** The last assistant reply in a transcript and whether its turn finished.
87
147
  * A person's message after the reply opens a new turn, so it clears both. */
88
148
  export function finalTurnFromLines(lines, source) {
89
- let completed = false, lastAssistant, error;
149
+ let completed = false, lastAssistant, error, interrupted = false;
150
+ const running = new Set(), finished = new Map(), tail = { commands: new Map(), awaited: new Set() };
90
151
  for (const line of lines) {
91
152
  if (!line.trim())
92
153
  continue;
@@ -98,6 +159,18 @@ export function finalTurnFromLines(lines, source) {
98
159
  continue;
99
160
  }
100
161
  const payload = object(raw.payload);
162
+ if (source === "claude") {
163
+ backgroundTasks(raw, running, finished, tail);
164
+ // The owner moving on leaves what earlier turns started behind: a
165
+ // shell still running from then is a leftover, not work in flight.
166
+ if (ownerPrompt(raw))
167
+ tail.awaited.clear();
168
+ }
169
+ if (turnInterrupted(raw, source)) {
170
+ interrupted = true;
171
+ completed = false;
172
+ continue;
173
+ }
101
174
  const userTurn = source === "claude" ? raw.type === "user" && !raw.isMeta && typeof object(raw.message).content === "string"
102
175
  : source === "codex" ? raw.type === "response_item" && payload.type === "message" && payload.role === "user"
103
176
  : raw.type === "user/message";
@@ -105,19 +178,33 @@ export function finalTurnFromLines(lines, source) {
105
178
  completed = false;
106
179
  lastAssistant = undefined;
107
180
  error = undefined;
181
+ interrupted = false;
108
182
  continue;
109
183
  }
110
184
  const text = publicAssistant(raw, source);
111
185
  if (text) {
112
186
  lastAssistant = text;
113
187
  completed = false;
188
+ interrupted = false;
114
189
  }
115
190
  if (turnEnded(raw, source)) {
116
191
  completed = true;
192
+ interrupted = false;
117
193
  error = turnError(raw, source);
118
194
  }
119
195
  }
120
- return { completed, ...(lastAssistant ? { lastAssistant } : {}), ...(completed && error ? { error } : {}) };
196
+ return { completed, ...(lastAssistant ? { lastAssistant } : {}), ...(completed && error ? { error } : {}),
197
+ ...(interrupted ? { interrupted: true } : {}), ...(completed && running.size ? { background: running.size } : {}),
198
+ ...(finished.size ? { finishedTasks: [...finished.values()] } : {}), ...(tail.awaited.size ? { awaited: tail.awaited.size } : {}) };
199
+ }
200
+ /** A prompt the owner (or a dispatcher) typed, not a task's notification or
201
+ * a teammate's message waking the session. */
202
+ function ownerPrompt(raw) {
203
+ const content = object(raw.message).content;
204
+ if (raw.type !== "user" || raw.isMeta || typeof content !== "string")
205
+ return false;
206
+ const text = content.trimStart();
207
+ return !text.startsWith("<task-notification>") && !text.startsWith("<teammate-message");
121
208
  }
122
209
  /** The final turn of a conversation, read from the tail of its transcript. */
123
210
  export async function readFinalTurn(source, sessionId) {
@@ -1,6 +1,9 @@
1
+ import { type HarnessInventory } from "./harnesses.js";
1
2
  import { type Json } from "./protocol.js";
2
- /** The live conductor on this computer, on any Herdr server, as a target.
3
- * `known` reuses a snapshot the caller already took. */
3
+ /** The live conductor on this computer, as a target: the pane the Hook
4
+ * recorded (docs/conductor-sets.md), or before any record, a pane named as a
5
+ * conductor on any server, which is then recorded. `known` reuses a snapshot
6
+ * the caller already took. */
4
7
  export declare function localConductor(known?: {
5
8
  server: string;
6
9
  snapshot: Json;
@@ -8,8 +11,23 @@ export declare function localConductor(known?: {
8
11
  server: string;
9
12
  target?: Json;
10
13
  } | undefined>;
14
+ /** "Make conductor": the owner gives an agent already running in a pane on this computer the role. */
15
+ export declare function makeConductor(server: string, data: Json): Promise<Json>;
16
+ /** "Stop being conductor": the pane keeps its agent and loses the role. With
17
+ * `paneId`, only that pane's role ends. */
18
+ export declare function stopConductor(data: Json): Promise<Json>;
11
19
  /** The Herdr agent-name slug for a human label: "Conductor smoke 4" becomes "conductor-smoke-4". */
12
20
  export declare function herdrAgentName(label: string): string;
21
+ type InventoryReader = () => Promise<HarnessInventory>;
22
+ /** Only for tests: what this computer can launch. Without one, `PHREN_LAUNCH_CHECK=off` skips the early availability check. */
23
+ export declare function setLaunchInventory(reader: InventoryReader | undefined): void;
24
+ export interface LaunchOptions {
25
+ canary?: boolean;
26
+ /** `data.cwd` is a folder the Hook resolved itself (a dispatched or
27
+ * scheduled project's source folder), so it may be marked trusted for the
28
+ * harness before the launch. Never set for a folder the phone chose. */
29
+ trustFolder?: boolean;
30
+ }
13
31
  /**
14
32
  * "Open on a computer": a new Herdr workspace (or a tab in an existing one)
15
33
  * in the project's directory, with the chosen agent started in its pane.
@@ -17,7 +35,6 @@ export declare function herdrAgentName(label: string): string;
17
35
  * by diffing snapshots; `agent.start` returns once Herdr has detected the
18
36
  * agent and it is ready for input, which can take most of `timeoutMs`.
19
37
  */
20
- export declare function launchSession(server: string, data: Json, options?: {
21
- canary?: boolean;
22
- }): Promise<Json>;
38
+ export declare function launchSession(server: string, data: Json, options?: LaunchOptions): Promise<Json>;
23
39
  export declare function workspaceAction(server: string, operation: string, data: Json): Promise<Json>;
40
+ export {};
@@ -3,12 +3,27 @@ import path from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
4
  import { z } from "zod";
5
5
  import { homeDir } from "../home-paths.js";
6
- import { agentNames, findPane, isConductorName, paneAgentName, paneChatState, paneIdentity, servers, snapshot } from "./herdr.js";
7
- import { agentNotReady, terminalName, terminalProvider } from "./terminal.js";
6
+ import { agentNames, findPane, isConductorName, paneChatState, paneIdentity, servers, snapshot } from "./herdr.js";
7
+ import { agentNotReady, terminalKind, terminalName, terminalProvider } from "./terminal.js";
8
+ import { tmuxScroll } from "./terminal-tmux.js";
9
+ import { intervalFromEnv } from "./limits.js";
8
10
  import { createLaunchWorktree, launchWorktreeSchema } from "./launch-worktree.js";
11
+ import { askpassEnv } from "./sudo.js";
12
+ import { briefArgs, DISPATCH_ID_ENV, launchBriefSchema, launchesWithBrief, recordBriefArrival, writeLaunchBrief } from "./launch-brief.js";
13
+ import { prepareServedLaunch, registerServedPane, sendServedBrief } from "./opencode-panes.js";
9
14
  import { groupConductor } from "./conductor-group.js";
15
+ import { clearConductor, conductorPane, noteConductorSession, readRoleState, recordConductor, runsAgent } from "./conductor-role.js";
16
+ import { localNames } from "./computer-names.js";
17
+ import { pretrustFolder } from "./folder-trust.js";
18
+ import { claudeHome, claudeLaunchEnv, isAccountSlug, DEFAULT_ACCOUNT } from "./claude-accounts.js";
19
+ import { harnessInventoryWithin, hasUsable, launchCheckOff } from "./harnesses.js";
20
+ import { paneAccountKey, recordPaneAccount } from "./pane-accounts.js";
10
21
  import { optionalHookPeers } from "./peers.js";
11
- import { atomic, BridgeError, bridgeRoot, id, objects, provider } from "./protocol.js";
22
+ import { AppServerRpcError } from "./codex-app-server.js";
23
+ import { codexAppServerEnabled, codexServers } from "./codex-servers.js";
24
+ import { logger } from "../logger.js";
25
+ import { atomic, BridgeError, bridgeRoot, id, launchEfforts, objects, PERMISSION_MODES, provider } from "./protocol.js";
26
+ import { CLAUDE_NAMES, CODEX_MODES, codexModeFlags } from "./settings-switch.js";
12
27
  /** Starting agents in Herdr from the phone: the launch route's harness
13
28
  * arguments, the conductor brief, and workspace, tab and pane actions. */
14
29
  const launchKinds = ["codex", "claude", "copilot", "opencode"];
@@ -36,7 +51,6 @@ async function conductorBrief() {
36
51
  throw new BridgeError(503, "The shipped conductor brief is empty. Reinstall Phren Hook.");
37
52
  return brief;
38
53
  }
39
- const launchEfforts = ["minimal", "low", "medium", "high", "xhigh", "max"];
40
54
  /** How each harness takes a reasoning effort at startup. */
41
55
  function effortArgs(kind, effort) {
42
56
  if (kind === "claude")
@@ -81,24 +95,124 @@ async function targetForPane(server, pane) {
81
95
  const chat = await paneChatState(server, pane).catch(() => ({}));
82
96
  return chat.starting === true ? { ...binding, starting: true, startingToken: chat.startingToken } : undefined;
83
97
  }
84
- /** The live conductor on this computer, on any Herdr server, as a target.
85
- * `known` reuses a snapshot the caller already took. */
98
+ /** The live conductor on this computer, as a target: the pane the Hook
99
+ * recorded (docs/conductor-sets.md), or before any record, a pane named as a
100
+ * conductor on any server, which is then recorded. `known` reuses a snapshot
101
+ * the caller already took. */
86
102
  export async function localConductor(known) {
87
- const names = [...new Set([...(known ? [known.server] : []), ...(await servers()).map(item => String(item.session))])];
103
+ const state = await readRoleState();
104
+ if (state?.conductor === null)
105
+ return undefined;
106
+ const live = new Set((await servers()).map(item => String(item.session)));
107
+ if (known)
108
+ live.add(known.server);
109
+ const names = state?.conductor ? [state.conductor.server].filter(name => live.has(name)) : [...live];
88
110
  for (const name of names) {
89
- const value = known && name === known.server ? known.snapshot : await snapshot(name);
90
- const existing = objects(value.panes).find(pane => isConductorName(paneAgentName(value, pane))
91
- && provider.safeParse(pane.agent).success && !["completed", "exited", "failed", "stopped"].includes(String(pane.agent_status)));
92
- if (existing)
93
- return { server: name, target: await targetForPane(name, existing) };
111
+ const value = known && name === known.server ? known.snapshot : await snapshot(name).catch(() => undefined);
112
+ if (!value)
113
+ continue;
114
+ const pane = await conductorPane(name, value);
115
+ if (!runsAgent(pane))
116
+ continue;
117
+ const target = await targetForPane(name, pane);
118
+ // A restart or a new login in the same pane: the role stays, the session is new.
119
+ if (typeof target?.session === "string")
120
+ await noteConductorSession(name, String(pane.pane_id), target.session);
121
+ return { server: name, target };
94
122
  }
95
123
  return undefined;
96
124
  }
125
+ /** Refuses a second conductor in this computer's set: a live one here on
126
+ * another pane, or on any member. Members that could not say come back as `unchecked`. */
127
+ async function requireNoConductor(server, before, except) {
128
+ const existing = await localConductor({ server, snapshot: before });
129
+ if (existing && !(except && existing.server === server && existing.target?.pane === except)) {
130
+ throw new BridgeError(409, "A conductor is already running on this computer. Stop it first.", { target: existing.target });
131
+ }
132
+ const group = await groupConductor((await optionalHookPeers()).peers, localNames());
133
+ if (group.found)
134
+ throw new BridgeError(409, `A conductor is already running on ${group.found.computer}, which is in this computer's set. A set of linked computers shares one conductor.`, { computer: group.found.computer, target: group.found.target });
135
+ return group.unchecked;
136
+ }
137
+ /** The phone names the pane's workspace and tab too; the CLI may know only the pane. */
138
+ const paneRequest = z.object({ workspaceId: id.optional(), tabId: id.optional(), paneId: id }).strict();
139
+ /** "Make conductor": the owner gives an agent already running in a pane on this computer the role. */
140
+ export async function makeConductor(server, data) {
141
+ const place = paneRequest.parse(data);
142
+ const before = await snapshot(server);
143
+ const pane = objects(before.panes).find(p => p.pane_id === place.paneId && (place.workspaceId === undefined || p.workspace_id === place.workspaceId)
144
+ && (place.tabId === undefined || p.tab_id === place.tabId));
145
+ if (!pane)
146
+ throw new BridgeError(409, "The pane changed.");
147
+ if (!runsAgent(pane))
148
+ throw new BridgeError(409, "No agent is running in this pane.");
149
+ if (pane.agent === "copilot")
150
+ throw new BridgeError(400, "Copilot cannot run as a conductor.");
151
+ const unchecked = await requireNoConductor(server, before, place.paneId);
152
+ const target = await targetForPane(server, pane);
153
+ await recordConductor(server, pane, "owner", typeof target?.session === "string" ? target.session : undefined);
154
+ return { ok: true, conductor: { server, ...(target ? { target } : {}) }, ...(unchecked.length ? { unchecked } : {}) };
155
+ }
156
+ /** "Stop being conductor": the pane keeps its agent and loses the role. With
157
+ * `paneId`, only that pane's role ends. */
158
+ export async function stopConductor(data) {
159
+ const pane = data.paneId === undefined ? undefined : id.parse(data.paneId);
160
+ const state = await readRoleState();
161
+ if (pane !== undefined && state?.conductor === undefined) {
162
+ // Before any record a named pane may still be the conductor; settle that first.
163
+ await localConductor();
164
+ }
165
+ const held = (await readRoleState())?.conductor;
166
+ if (pane !== undefined && held && held.pane !== pane)
167
+ throw new BridgeError(409, "That pane is not this computer's conductor.");
168
+ const stopped = await clearConductor(pane);
169
+ return { ok: true, stopped: !!stopped };
170
+ }
171
+ /** How long a pane the Hook just created may take to reach its shell prompt. */
172
+ const SHELL_READY_MS = intervalFromEnv("PHREN_SHELL_READY_MS", 15_000);
173
+ /** Herdr starts an agent only at an interactive shell prompt and refuses
174
+ * with `agent_pane_busy` ("is not an available shell") before that. A pane
175
+ * created a moment ago is busy only while its login shell starts, which a
176
+ * loaded computer can stretch to seconds (three Linuxbox dispatches failed
177
+ * this way on 2026-09-27; the same pane took the agent by hand a minute
178
+ * later). Nothing is typed on a refusal, so retry until the shell is up. */
179
+ async function startWhenShellReady(server, pane, agent) {
180
+ const deadline = Date.now() + SHELL_READY_MS;
181
+ for (;;) {
182
+ try {
183
+ await terminalProvider().startAgent(server, pane, agent);
184
+ return;
185
+ }
186
+ catch (error) {
187
+ const starting = error instanceof BridgeError && error.details?.herdrCode === "agent_pane_busy";
188
+ if (!starting || Date.now() >= deadline)
189
+ throw error;
190
+ await new Promise(resolve => setTimeout(resolve, 250));
191
+ }
192
+ }
193
+ }
97
194
  /** The Herdr agent-name slug for a human label: "Conductor smoke 4" becomes "conductor-smoke-4". */
98
195
  export function herdrAgentName(label) {
99
196
  const slug = label.toLowerCase().replace(/[^a-z0-9_-]+/g, "-").replace(/^[^a-z]+/, "").replace(/-+$/, "").slice(0, 32).replace(/-+$/, "");
100
197
  return slug || "agent";
101
198
  }
199
+ let inventoryReader;
200
+ /** Only for tests: what this computer can launch. Without one, `PHREN_LAUNCH_CHECK=off` skips the early availability check. */
201
+ export function setLaunchInventory(reader) { inventoryReader = reader; }
202
+ /** Refuses a launch the computer cannot run before any pane exists: the harness is not installed
203
+ * (`harness_unavailable`), or the account is unknown, signed out, or given for a harness without accounts
204
+ * (`account_unavailable`). Only a definite answer refuses; an inventory that cannot be read lets the launch go on. */
205
+ async function requireAvailable(kind, account) {
206
+ if (!inventoryReader && launchCheckOff())
207
+ return;
208
+ // Bounded: a cold sign-in check per home can take seconds, and an unready inventory lets the launch go on.
209
+ const inventory = await (inventoryReader ?? (() => harnessInventoryWithin(2_500)))().catch(() => undefined);
210
+ if (!inventory)
211
+ return;
212
+ const availability = hasUsable(inventory, kind, account);
213
+ if (!availability.ok)
214
+ throw new BridgeError(409, availability.reason, { code: availability.code });
215
+ }
102
216
  /**
103
217
  * "Open on a computer": a new Herdr workspace (or a tab in an existing one)
104
218
  * in the project's directory, with the chosen agent started in its pane.
@@ -115,8 +229,21 @@ export async function launchSession(server, data, options = {}) {
115
229
  const label = plainText(200).parse(data.label);
116
230
  const kind = z.enum(launchKinds).parse(data.kind);
117
231
  const effort = z.enum(launchEfforts).default("medium").parse(data.effort);
232
+ const account = data.account === undefined || data.account === null ? undefined : z.string().refine(isAccountSlug, "Account must be default or a lowercase slug.").parse(data.account);
233
+ const permissionMode = z.enum(PERMISSION_MODES).optional().parse(data.permissionMode ?? undefined);
234
+ if (permissionMode && role === "conductor")
235
+ throw new BridgeError(400, "A conductor starts with its own permissions; permissionMode is for workers.");
236
+ if (permissionMode && kind === "opencode")
237
+ throw new BridgeError(400, "OpenCode takes its permissions from its own config; permissionMode is for Claude and Codex workers.");
238
+ if (permissionMode && kind === "copilot")
239
+ throw new BridgeError(400, "Copilot takes its permissions from its own settings; permissionMode is for Claude and Codex workers.");
118
240
  if (role === "conductor" && kind === "copilot")
119
241
  throw new BridgeError(400, "Copilot cannot run as a conductor.");
242
+ // A dispatched worker's or scheduled run's first prompt. It rides on the
243
+ // launch where the harness takes one; elsewhere the caller types it.
244
+ const brief = data.brief === undefined || data.brief === null ? undefined : launchBriefSchema.parse(data.brief);
245
+ if (brief && role === "conductor")
246
+ throw new BridgeError(400, "A conductor starts with its own brief.");
120
247
  // Herdr's agent name is a slug (lowercase, digits, - or _, 1 to 32 chars);
121
248
  // the label a person typed is not, so derive one from it.
122
249
  const baseName = herdrAgentName(data.name === undefined ? label : plainText(200).parse(data.name));
@@ -132,6 +259,11 @@ export async function launchSession(server, data, options = {}) {
132
259
  let workspace = data.workspaceId === undefined ? undefined : id.parse(data.workspaceId);
133
260
  // Herdr 0.9.1 refuses a start timeout of 3000 ms or less (invalid_agent_timeout).
134
261
  const timeout = Math.min(120_000, Math.max(3_001, data.timeoutMs === undefined ? 45_000 : z.number().int().parse(data.timeoutMs)));
262
+ // Checked before anything is created, so a refusal leaves no pane, worktree or brief file behind.
263
+ await requireAvailable(kind, account);
264
+ const home = kind === "claude" && account && account !== DEFAULT_ACCOUNT ? claudeHome(account) : undefined;
265
+ if (kind === "claude" && account && account !== DEFAULT_ACCOUNT && !home)
266
+ throw new BridgeError(409, `No claude account "${account}"`, { code: "account_unavailable" });
135
267
  const before = await snapshot(server);
136
268
  // Herdr agent names are unique per server; a scheduled run or a second
137
269
  // launch with the same label would otherwise collide with the first.
@@ -139,23 +271,32 @@ export async function launchSession(server, data, options = {}) {
139
271
  let name = wanted;
140
272
  for (let n = 2; taken.has(name) && n < 100; n++)
141
273
  name = `${wanted.slice(0, 32 - String(n).length - 1)}-${n}`;
142
- // One conductor per connected group: this computer and every linked peer.
143
- let unchecked = [];
144
- if (role === "conductor" && !options.canary) {
145
- const existing = await localConductor({ server, snapshot: before });
146
- if (existing)
147
- throw new BridgeError(409, "A conductor is already running on this computer.", { target: existing.target });
148
- const group = await groupConductor((await optionalHookPeers()).peers);
149
- if (group.found)
150
- throw new BridgeError(409, `A conductor is already running on ${group.found.computer}, which is linked with this computer. A connected group shares one conductor.`, { computer: group.found.computer, target: group.found.target });
151
- unchecked = group.unchecked;
152
- }
274
+ // One conductor per set of linked computers.
275
+ const unchecked = role === "conductor" && !options.canary ? await requireNoConductor(server, before) : [];
153
276
  // A worker opened in the conductor's workspace would be listed under the
154
277
  // conductor's name; it gets its own workspace instead.
155
- if (role === "agent" && workspace && objects(before.panes).some(pane => pane.workspace_id === workspace && isConductorName(paneAgentName(before, pane))))
278
+ const conductorHere = role === "agent" && workspace ? await conductorPane(server, before) : undefined;
279
+ if (conductorHere && conductorHere.workspace_id === workspace)
156
280
  workspace = undefined;
157
281
  const args = role === "conductor" ? await prepareConductor(kind, effort, model)
158
- : [...(model && modelFlag[kind] ? [modelFlag[kind], model] : []), ...(data.effort === undefined ? [] : effortArgs(kind, effort))];
282
+ : [...(model && modelFlag[kind] ? [modelFlag[kind], model] : []), ...(data.effort === undefined ? [] : effortArgs(kind, effort)),
283
+ ...(permissionMode && kind === "claude" ? ["--permission-mode", CLAUDE_NAMES[permissionMode]] : []), ...(permissionMode && kind === "codex" ? codexModeFlags(permissionMode) : [])];
284
+ // A Codex worker runs on a Phren-owned app-server (codex-servers.ts): the
285
+ // pane joins the thread the Hook started, and the brief is that thread's
286
+ // first turn. The typed arguments below stay the fallback.
287
+ const structured = kind === "codex" && role === "agent" && !options.canary && codexAppServerEnabled();
288
+ // OpenCode serves its own API on a port of its own (opencode-panes.ts): the
289
+ // Hook sends its prompts, answers its asks and interrupts it over HTTP, and
290
+ // the pane stays the owner's view. A brief goes the same way once it
291
+ // answers; its file still marks the dispatch so the arrival is recorded here.
292
+ const served = kind === "opencode" ? await prepareServedLaunch() : undefined;
293
+ if (served)
294
+ args.push(...served.args);
295
+ const briefFile = brief && (launchesWithBrief(kind) || structured || served) ? await writeLaunchBrief(brief, Date.now(), label) : undefined;
296
+ const briefLaunch = brief && briefFile && launchesWithBrief(kind) ? briefArgs(kind, briefFile) : undefined;
297
+ // sudo -A in the new agent asks the phone for the password (sudo.ts).
298
+ const variables = { ...askpassEnv(), ...(brief ? { [DISPATCH_ID_ENV]: brief.id } : {}), ...served?.env, ...(home ? claudeLaunchEnv(home) : {}) };
299
+ const env = Object.keys(variables).length ? variables : undefined;
159
300
  if (workspace && !objects(before.workspaces).some(w => w.workspace_id === workspace))
160
301
  throw new BridgeError(409, "The workspace changed.");
161
302
  const knownWorkspaces = new Set(objects(before.workspaces).map(w => w.workspace_id));
@@ -164,8 +305,12 @@ export async function launchSession(server, data, options = {}) {
164
305
  // never leaves a worktree or branch behind.
165
306
  const worktree = worktreeRequest ? await createLaunchWorktree(projectDirectory, worktreeRequest) : undefined;
166
307
  const cwd = worktree?.cwd ?? projectDirectory;
308
+ // Claude's folder-trust screen defaults to "No, exit" and Codex's holds the
309
+ // agent too; a folder the Hook picked or just created is trusted up front.
310
+ if (worktree || options.trustFolder)
311
+ await pretrustFolder(kind, cwd, worktree ? `new worktree for ${worktree.branch}` : "project folder", home ? { ...process.env, ...claudeLaunchEnv(home) } : process.env);
167
312
  try {
168
- await terminalProvider().create(server, { workspace, label, cwd });
313
+ await terminalProvider().create(server, { workspace, label, cwd, ...(env ? { env } : {}) });
169
314
  }
170
315
  catch (error) {
171
316
  await worktree?.discard();
@@ -188,10 +333,40 @@ export async function launchSession(server, data, options = {}) {
188
333
  }
189
334
  if (!created)
190
335
  throw new BridgeError(409, `${terminalName(server)} created "${label}" but its pane did not appear. Check ${terminalName(server)} on the computer.`);
336
+ const place = { workspace: created.workspaceId, tab: created.tabId, pane: created.paneId };
337
+ const structuredLaunch = structured ? await codexServers.launch({ server, ...place }, { cwd, ...(model ? { model } : {}),
338
+ ...(data.effort === undefined ? {} : { effort }), env: { ...(terminalProvider().paneEnv?.(server, place) ?? {}), ...(env ?? {}) },
339
+ ...(brief ? { dispatchId: brief.id } : {}), startThread: !!brief, ...(permissionMode ? { remoteArgs: codexModeFlags(permissionMode) } : {}) }).catch(error => {
340
+ logger.warn("launch", `Codex app-server unavailable, typing instead: ${error instanceof Error ? error.message : String(error)}`);
341
+ return undefined;
342
+ }) : undefined;
343
+ const appServer = structuredLaunch?.entry;
344
+ const binding = { server, workspace: created.workspaceId, tab: created.tabId, pane: created.paneId, source: kind };
345
+ // The brief is the thread's first turn, acknowledged with its id before
346
+ // the pane even starts; the pane's TUI shows it running when it joins.
347
+ // Refused outright, nothing was sent and the caller types it; a lost
348
+ // reply may have started it, so it is not offered for typing again.
349
+ let briefTurn;
350
+ if (appServer?.threadId && brief) {
351
+ try {
352
+ // The thread's first turn carries the mode; the TUI joining it has no flags to set.
353
+ if (permissionMode)
354
+ codexServers.holdSettings(appServer, { ...CODEX_MODES[permissionMode] });
355
+ await codexServers.prompt(appServer, brief.text);
356
+ briefTurn = "sent";
357
+ await recordBriefArrival(brief.id, "UserPromptSubmit", { ...binding, session: appServer.threadId }).catch(() => undefined);
358
+ }
359
+ catch (error) {
360
+ briefTurn = error instanceof AppServerRpcError ? undefined : "uncertain";
361
+ }
362
+ }
363
+ const agentArgs = structuredLaunch ? structuredLaunch.args : [...args, ...(briefLaunch ?? [])];
191
364
  try {
192
- await terminalProvider().startAgent(server, created.paneId, { name, kind, args, timeoutMs: timeout });
365
+ await startWhenShellReady(server, created.paneId, { name, kind, args: agentArgs, timeoutMs: timeout, ...(env ? { env } : {}) });
193
366
  }
194
367
  catch (error) {
368
+ if (appServer && !agentNotReady(error))
369
+ await codexServers.stop(appServer).catch(() => undefined);
195
370
  // A first-run screen (Claude's folder trust, a login notice) holds the
196
371
  // agent at startup. It did start: hand the pane back so the owner answers
197
372
  // that screen from the chat instead of stranding the workspace.
@@ -203,24 +378,55 @@ export async function launchSession(server, data, options = {}) {
203
378
  throw new BridgeError(409, `${host} couldn't start ${kind} in the new "${label}" pane (${reason}). The workspace was created and is still open on the computer — open it from ${host === "Herdr" ? "Herdr workspaces" : "its tmux session"}.`);
204
379
  }
205
380
  }
381
+ // Without a brief the pane's TUI started the thread; the Hook heard it.
382
+ if (appServer && !appServer.threadId)
383
+ await codexServers.awaitThread(appServer);
384
+ let servedBrief;
385
+ if (served) {
386
+ const variant = role === "conductor" || data.effort !== undefined ? effort : undefined;
387
+ const entry = await registerServedPane(server, created.paneId, cwd, served, { defaults: { ...(role === "conductor" ? { agent: "conductor" } : {}), ...(model ? { model } : {}), ...(variant ? { variant } : {}) } }).catch(() => undefined);
388
+ const sent = entry && brief ? await sendServedBrief(entry, brief.text) : undefined;
389
+ if (brief && sent?.sent) {
390
+ // Sent is enough to never type it again; the user turn appearing in
391
+ // the session is the acceptance the dispatch receipt waits for.
392
+ servedBrief = { session: sent.session, delivered: sent.delivered };
393
+ const at = { ...binding, session: sent.session };
394
+ await recordBriefArrival(brief.id, "SessionStart", at).catch(() => { });
395
+ if (sent.delivered)
396
+ await recordBriefArrival(brief.id, "UserPromptSubmit", at).catch(() => { });
397
+ }
398
+ }
206
399
  const after = await snapshot(server);
207
400
  const pane = findPane(after, { workspace: created.workspaceId, tab: created.tabId, pane: created.paneId });
208
401
  const agentStatus = typeof pane?.agent_status === "string" ? pane.agent_status : undefined;
209
- const sessionId = pane && pane.agent === kind ? await paneIdentity(server, pane) : undefined;
402
+ if (kind === "claude" && account)
403
+ recordPaneAccount(paneAccountKey(server, created.paneId), account, typeof pane?.terminal_id === "string" ? pane.terminal_id : undefined);
404
+ const sessionId = appServer?.threadId ?? (pane && pane.agent === kind ? await paneIdentity(server, pane) : undefined) ?? servedBrief?.session;
405
+ // The Hook, not the agent name, holds the role from here on.
406
+ if (role === "conductor" && !options.canary)
407
+ await recordConductor(server, pane ?? { pane_id: created.paneId, workspace_id: created.workspaceId, tab_id: created.tabId, agent: kind }, "launch", sessionId);
210
408
  const chat = !sessionId && pane && pane.agent === kind ? await paneChatState(server, pane).catch(() => ({})) : {};
211
- const binding = { server, workspace: created.workspaceId, tab: created.tabId, pane: created.paneId, source: kind };
212
409
  const target = sessionId ? { ...binding, session: sessionId }
213
410
  : chat.starting === true ? { ...binding, starting: true, startingToken: chat.startingToken } : undefined;
214
- return { ok: true, ...created, agent: kind, agentStatus, role, sessionId, target, ...(unchecked.length ? { unchecked } : {}),
411
+ return { ok: true, ...created, agent: kind, agentStatus, role, sessionId, target, ...(account ? { account } : {}), ...(permissionMode ? { permissionMode } : {}), ...(unchecked.length ? { unchecked } : {}),
412
+ // The caller types the brief itself unless it went with the launch.
413
+ ...(brief ? { briefLaunched: appServer ? briefTurn !== undefined : !!briefLaunch || !!servedBrief } : {}),
215
414
  ...(worktree ? { worktree: { path: worktree.path, branch: worktree.branch } } : {}) };
216
415
  }
217
416
  export async function workspaceAction(server, operation, data) {
218
- if (!["focus", "rename", "create", "close"].includes(operation))
417
+ if (!["focus", "rename", "create", "close", "scroll"].includes(operation))
219
418
  throw new BridgeError(400, "Unsupported Herdr action.");
220
- const s = await snapshot(server);
221
419
  const workspace = typeof data.workspaceId === "string" ? data.workspaceId : undefined;
222
420
  const tab = typeof data.tabId === "string" ? data.tabId : undefined;
223
421
  const pane = typeof data.paneId === "string" ? data.paneId : undefined;
422
+ if (operation === "scroll") {
423
+ // Every swipe step lands here, so it skips the snapshot: tmux itself
424
+ // refuses a pane that is gone.
425
+ if (terminalKind(server) !== "tmux")
426
+ throw new BridgeError(400, "Herdr scrolls in the terminal itself.");
427
+ return { ok: true, ...await tmuxScroll(server, pane, z.number().int().min(-200).max(200).parse(data.lines)) };
428
+ }
429
+ const s = await snapshot(server);
224
430
  if (workspace && !objects(s.workspaces).some(w => w.workspace_id === workspace))
225
431
  throw new BridgeError(409, "The workspace changed.");
226
432
  if (tab && !objects(s.tabs).some(t => t.tab_id === tab && (!workspace || t.workspace_id === workspace)))
@@ -15,8 +15,10 @@ import type { WorkspacesReader } from "./server-routes.js";
15
15
  *
16
16
  * Frames: `{ type: "overview", ...workspaces, phren }` and
17
17
  * `{ type: "heartbeat", phren }`. A phone that asks with `resources=1` also
18
- * gets `{ type: "resources", resources }` first and every
19
- * `OVERVIEW_RESOURCES_MS` after (an older phone never asks, so never meets it).
18
+ * gets `{ type: "resources", resources }` after the first overview, then at
19
+ * `OVERVIEW_RESOURCES_MS` intervals (an older phone never asks, so never meets it).
20
+ * One that asks with `sudo=1` gets `{ type: "sudo", requests }` after the first
21
+ * overview and whenever the pending sudo requests change.
20
22
  */
21
23
  export declare const OVERVIEW_TICK_MS: number;
22
24
  export declare const OVERVIEW_REFRESH_MS: number;
@@ -28,6 +30,11 @@ export interface OverviewStreamOptions {
28
30
  info: () => Json;
29
31
  /** Renews the approval watch lease `watchApprovals=1` asks for. */
30
32
  renew: (server: string) => void;
33
+ /** Pending sudo requests (`GET /v1/sudo`), for phones that ask with `sudo=1`. */
34
+ sudo?: {
35
+ list(): unknown[];
36
+ subscribe(listener: (requests: unknown[]) => void): () => void;
37
+ };
31
38
  /** This computer's resources (`GET /v1/resources`), for phones that ask. */
32
39
  resources?: () => Promise<unknown>;
33
40
  snapshot?: (server: string, maxAgeMs: number) => Promise<Json>;
@@ -45,7 +52,7 @@ export interface OverviewClient {
45
52
  close(code?: number, reason?: string): void;
46
53
  once(event: "close" | "error", listener: () => void): unknown;
47
54
  }
48
- export declare function overviewStream(options: OverviewStreamOptions): (client: OverviewClient, server: string, watchApprovals: boolean, withResources?: boolean) => {
55
+ export declare function overviewStream(options: OverviewStreamOptions): (client: OverviewClient, server: string, watchApprovals: boolean, withResources?: boolean, typedMux?: boolean, withSudo?: boolean) => {
49
56
  tick: () => Promise<void>;
50
57
  stop: () => void;
51
58
  };