@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
@@ -3,15 +3,21 @@ import { defaultPhrenPath } from "../shared.js";
3
3
  import { disabledHint } from "../modules/registry.js";
4
4
  import { execFile } from "node:child_process";
5
5
  import { usageStatusLine } from "./usage.js";
6
- import { chmod, copyFile, mkdir, open, readFile, rename, symlink, unlink, lstat, writeFile } from "node:fs/promises";
6
+ import { access, chmod, copyFile, mkdir, open, readFile, rename, symlink, unlink, lstat, writeFile } from "node:fs/promises";
7
7
  import { homedir } from "node:os";
8
8
  import { codexHome, claudeConfigDir } from "../home-paths.js";
9
+ import { claudeHomes } from "./claude-accounts.js";
10
+ import { syncAccountMcpServers } from "./claude-account-setup.js";
9
11
  import path from "node:path";
10
12
  import { fileURLToPath } from "node:url";
11
13
  import { promisify } from "node:util";
12
14
  import { bridgeRoot, object, objects, atomic, socketPath } from "./protocol.js";
13
15
  import { herdrRoot } from "./herdr.js";
14
16
  import { health } from "./transport.js";
17
+ import { FAST_HOOK_SOURCE, fastHookPath } from "./hook-fast.js";
18
+ import { installAskpass, removeAskpass } from "./sudo.js";
19
+ import { readStoredVoice, SPEECH_VOICE_ENV, writeSpeechVoice } from "./speech-voice.js";
20
+ import { carryCodexHookTrust } from "./codex-hook-trust.js";
15
21
  const exec = promisify(execFile);
16
22
  const label = "com.phren.hook";
17
23
  const unit = "phren-hook.service";
@@ -62,6 +68,34 @@ export function upgradeKeys(text) {
62
68
  }
63
69
  const quote = (s) => "'" + s.replace(/'/g, "'\\''") + "'";
64
70
  const xml = (s) => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
71
+ /** The service environment install writes. Any other key in an existing
72
+ * LaunchAgent (a voice, a proxy, an API override someone added by hand) is
73
+ * kept: before, `phren bridge update` rewrote the plist and dropped it. */
74
+ const MANAGED_ENVIRONMENT = new Set(["PATH", "PHREN_BRIDGE_HOME", "PHREN_HERDR_HOME", "PHREN_PATH", "PHREN_PROFILE"]);
75
+ /** The existing LaunchAgent's own EnvironmentVariables beyond phren's, read
76
+ * with plutil. A missing or unreadable plist has none. */
77
+ export async function extraLaunchAgentEnvironment(file, read = async (f) => (await exec("plutil", ["-convert", "json", "-o", "-", f])).stdout) {
78
+ let parsed;
79
+ try {
80
+ parsed = JSON.parse(await read(file));
81
+ }
82
+ catch {
83
+ return {};
84
+ }
85
+ const extra = {};
86
+ for (const [key, value] of Object.entries(object(object(parsed).EnvironmentVariables))) {
87
+ if (!MANAGED_ENVIRONMENT.has(key) && /^[A-Za-z_][A-Za-z0-9_]{0,127}$/.test(key) && typeof value === "string")
88
+ extra[key] = value;
89
+ }
90
+ return extra;
91
+ }
92
+ /** The Hook's LaunchAgent: phren's own environment first, then every kept key. */
93
+ export function launchAgentXml(values, extra = {}) {
94
+ const environment = [["PATH", values.path], ["PHREN_BRIDGE_HOME", values.root], ["PHREN_HERDR_HOME", values.herdr],
95
+ ["PHREN_PATH", values.store], ["PHREN_PROFILE", values.profile], ...Object.entries(extra).filter(([key]) => !MANAGED_ENVIRONMENT.has(key))];
96
+ const env = environment.map(([key, value]) => `<key>${xml(key)}</key><string>${xml(value)}</string>`).join("");
97
+ return `<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0"><dict><key>Label</key><string>${xml(values.label)}</string><key>ProgramArguments</key><array><string>${xml(values.node)}</string><string>${xml(values.program)}</string><string>serve</string></array><key>Umask</key><integer>63</integer><key>RunAtLoad</key><true/><key>KeepAlive</key><true/><key>ThrottleInterval</key><integer>5</integer><key>Nice</key><integer>-5</integer><key>EnvironmentVariables</key><dict>${env}</dict><key>StandardErrorPath</key><string>${xml(path.join(values.root, "service.log"))}</string></dict></plist>\n`;
98
+ }
65
99
  const systemdQuote = (s) => '"' + s.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/%/g, "%%") + '"';
66
100
  async function commandOutput(file, args, env) {
67
101
  try {
@@ -154,15 +188,29 @@ async function startService() {
154
188
  }
155
189
  }
156
190
  // RunAtLoad does not always fire for a job bootstrapped from an SSH login.
157
- await exec("launchctl", ["kickstart", `${domain}/${label}`]).catch(() => { });
191
+ // A failed kickstart is only fatal if the version check below also fails.
192
+ const kickstartError = await exec("launchctl", ["kickstart", `${domain}/${label}`]).then(() => undefined, error => String(error.stderr || error.message).trim());
158
193
  if (!gui)
159
194
  console.log(`No one is logged in at this Mac's screen, so the Phren Hook runs in ${domain}. After a screen login, run phren bridge install again to move it into gui/${uid}.`);
195
+ return kickstartError;
160
196
  }
161
197
  else {
162
198
  await exec("systemctl", ["--user", "daemon-reload"]);
163
199
  await exec("systemctl", ["--user", "enable", "--now", unit]);
164
200
  }
165
201
  }
202
+ async function serviceReady(version) {
203
+ for (let i = 0; i < 50; i++) {
204
+ try {
205
+ if ((await health()).version === version)
206
+ return true;
207
+ }
208
+ catch { /* Hook is still starting */ }
209
+ if (i < 49)
210
+ await new Promise(resolve => setTimeout(resolve, 200));
211
+ }
212
+ return false;
213
+ }
166
214
  export async function install(version, noService = false) {
167
215
  if (!["darwin", "linux"].includes(process.platform))
168
216
  throw new Error("Phren Hook supports macOS and Linux.");
@@ -192,19 +240,26 @@ export async function install(version, noService = false) {
192
240
  const stagedBundle = installedBundle + `.phren-${process.pid}`;
193
241
  await copyFile(bundle, stagedBundle);
194
242
  await rename(stagedBundle, installedBundle);
243
+ await atomic(fastHookPath(destination), FAST_HOOK_SOURCE);
195
244
  const previous = await readFile(path.join(root, "installed.json"), "utf8").then(v => JSON.parse(v)).catch(() => null);
196
245
  const gateway = await detectGateway();
197
246
  await atomic(path.join(root, "dispatch"), gatewayScript(gateway, {
198
247
  root, herdr, store: modules.store, profile: modules.profile, node: process.execPath,
199
248
  bundle: path.join(root, "current/bridge-hook.mjs"), socket: socketPath(), timing: path.join(root, "gateway.json"),
200
249
  }), 0o700);
250
+ await installAskpass(process.execPath, path.join(root, "current/bridge-hook.mjs"));
201
251
  const environmentPath = [path.dirname(process.execPath), path.join(homedir(), ".local/bin"), "/opt/homebrew/bin", "/usr/local/bin", "/usr/bin", "/bin", "/usr/sbin"].join(":");
202
252
  const program = path.join(root, "current/bridge-hook.mjs");
203
253
  if (!noService) {
204
254
  if (process.platform === "darwin") {
205
255
  const folder = path.join(homedir(), "Library/LaunchAgents");
206
256
  await mkdir(folder, { recursive: true });
207
- await atomic(path.join(folder, `${label}.plist`), `<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0"><dict><key>Label</key><string>${label}</string><key>ProgramArguments</key><array><string>${xml(process.execPath)}</string><string>${xml(program)}</string><string>serve</string></array><key>Umask</key><integer>63</integer><key>RunAtLoad</key><true/><key>KeepAlive</key><true/><key>ThrottleInterval</key><integer>5</integer><key>Nice</key><integer>-5</integer><key>EnvironmentVariables</key><dict><key>PATH</key><string>${xml(environmentPath)}</string><key>PHREN_BRIDGE_HOME</key><string>${xml(root)}</string><key>PHREN_HERDR_HOME</key><string>${xml(herdr)}</string><key>PHREN_PATH</key><string>${xml(modules.store)}</string><key>PHREN_PROFILE</key><string>${xml(modules.profile)}</string></dict><key>StandardErrorPath</key><string>${xml(path.join(root, "service.log"))}</string></dict></plist>\n`);
257
+ const plist = path.join(folder, `${label}.plist`);
258
+ const extra = await extraLaunchAgentEnvironment(plist);
259
+ // The talk-mode voice used to live only here; it moves to the Hook's own setting.
260
+ if (extra[SPEECH_VOICE_ENV] && !(await readStoredVoice()))
261
+ await writeSpeechVoice(extra[SPEECH_VOICE_ENV]).catch(() => { });
262
+ await atomic(plist, launchAgentXml({ label, node: process.execPath, program, path: environmentPath, root, herdr, store: modules.store, profile: modules.profile }, extra));
208
263
  }
209
264
  else {
210
265
  const folder = path.join(homedir(), ".config/systemd/user");
@@ -216,26 +271,26 @@ export async function install(version, noService = false) {
216
271
  await activate(version);
217
272
  try {
218
273
  if (!noService) {
219
- await startService();
220
- let ready = false;
221
- for (let i = 0; i < 30; i++) {
222
- try {
223
- const status = await health();
224
- ready = status.version === version;
225
- }
226
- catch { /* bounded readiness check */ }
227
- if (ready)
228
- break;
229
- await new Promise(resolve => setTimeout(resolve, 200));
274
+ let kickstartError = await startService();
275
+ let ready = await serviceReady(version);
276
+ if (!ready && process.platform === "darwin") {
277
+ // launchd may accept bootstrap but leave a throttled or old job behind.
278
+ // Reload the plist and give the new job a second bounded start window.
279
+ await stopService();
280
+ kickstartError = await startService();
281
+ ready = await serviceReady(version);
230
282
  }
231
283
  if (!ready) {
232
284
  const uid = process.getuid(), domain = process.platform === "darwin" ? launchDomain(uid, await guiSession(uid)) : undefined;
233
- throw new Error(`The new Phren Hook did not become ready. See ${serviceLog}. ` + (domain
285
+ throw new Error(`The new Phren Hook ${version} did not become ready after ${domain ? "two launchd starts" : "starting the service"}.${kickstartError ? ` Last launchctl kickstart error: ${kickstartError}.` : ""} See ${serviceLog}. ` + (domain
234
286
  ? `To start it by hand:\n ${launchCommands(domain, launchAgentPlist()).join("\n ")}`
235
287
  : `Check systemctl --user status ${unit}.`));
236
288
  }
237
289
  }
238
290
  await applyAgentHooks(hookEdits);
291
+ const synced = await syncAccountMcpServers().catch(() => []);
292
+ if (synced.length)
293
+ console.log(`Claude accounts: refreshed MCP servers in ${synced.join(", ")}.`);
239
294
  if (await applyOpencodePlugin()) {
240
295
  console.log("opencode chat: restart any opencode session started before now so it loads the transcript plugin.");
241
296
  }
@@ -256,6 +311,8 @@ export async function install(version, noService = false) {
256
311
  console.log(`Updated ${after.changed} Phren iPhone key(s); other keys were preserved.`);
257
312
  }
258
313
  await atomic(path.join(root, "installed.json"), JSON.stringify({ version, previous: previous?.version === version ? previous.previous : previous?.version, node: process.execPath, gateway }, null, 2) + "\n");
314
+ // Last, so a failed install restores hooks.json without leaving trust for entries it no longer has.
315
+ await carryCodexHookTrust(program, codexHooksBefore(hookEdits));
259
316
  console.log("Agent hooks installed. In Codex, review the new Phren entries in /hooks. Existing agents may need to resume before new hooks load.");
260
317
  console.log(`SSH gateway: ${gateway}${gateway === "node" ? " (no socat or nc -U found)" : ""}.`);
261
318
  console.log(`Phren Hook ${version} installed${noService ? " (service not started)" : " and running"}. Run phren bridge doctor.`);
@@ -287,6 +344,7 @@ export async function uninstall() {
287
344
  }
288
345
  await applyAgentHooks(await planAgentHooks(path.join(bridgeRoot(), "current/bridge-hook.mjs"), true));
289
346
  await applyOpencodePlugin(true);
347
+ await removeAskpass();
290
348
  // Preserve journal, settings, uploaded images, rollback version and SSH backups.
291
349
  console.log("Phren Hook stopped and its background service removed. Remove phren-iphone, phren-android and phren-computer keys from authorized_keys to revoke device access. Local data remains in " + bridgeRoot());
292
350
  }
@@ -300,14 +358,22 @@ async function missingFile(operation) {
300
358
  throw error;
301
359
  }
302
360
  }
303
- export async function planAgentHooks(program, remove = false, modules) {
361
+ /** Whether the version `current/` points at ships the Claude forwarder; one
362
+ * from before it does not, and its Claude callbacks run the bundle. */
363
+ const currentHasFastHook = (root) => access(fastHookPath(path.join(root, "current"))).then(() => true, () => false);
364
+ export async function planAgentHooks(program, remove = false, modules, fastClaude = true) {
304
365
  const edits = [];
366
+ // Extra Claude homes (one per account) get the same hooks; a symlinked settings.json shares another home's, so it is skipped.
367
+ const extraClaude = claudeHomes().slice(1).map(home => ["claude", path.join(home.dir, "settings.json")]);
305
368
  for (const [source, file] of [
306
369
  ["codex", path.join(codexHome(), "hooks.json")],
307
370
  ["claude", path.join(claudeConfigDir(), "settings.json")],
371
+ ...extraClaude,
308
372
  ["copilot", path.join(process.env.COPILOT_HOME || path.join(homedir(), ".copilot"), "hooks/phren.json")],
309
373
  ]) {
310
374
  const metadata = await missingFile(lstat(file));
375
+ if (metadata && extraClaude.some(([, extra]) => extra === file) && (!metadata.isFile() || metadata.isSymbolicLink() || metadata.size > 2_097_152))
376
+ continue;
311
377
  if (metadata && (!metadata.isFile() || metadata.isSymbolicLink() || metadata.size > 2_097_152)) {
312
378
  throw new Error(`Agent settings require a manual update: ${file}`);
313
379
  }
@@ -321,8 +387,11 @@ export async function planAgentHooks(program, remove = false, modules) {
321
387
  if (config.hooks !== undefined && (!config.hooks || typeof config.hooks !== "object" || Array.isArray(config.hooks)))
322
388
  throw new Error(`Invalid hook configuration: ${file}`);
323
389
  const hooks = object(config.hooks);
324
- const command = `${quote(process.execPath)} ${quote(program)} hook ${source}`;
325
- const ownHook = (entry) => typeof entry === "string" && entry.endsWith(` ${quote(program)} hook ${source}`);
390
+ // Claude's callbacks run the small forwarder beside the bundle (hook-fast.ts)
391
+ // instead of loading the whole bundle for every event.
392
+ const fast = fastHookPath(path.dirname(program));
393
+ const command = source === "claude" && fastClaude ? `${quote(process.execPath)} ${quote(fast)} claude` : `${quote(process.execPath)} ${quote(program)} hook ${source}`;
394
+ const ownHook = (entry) => typeof entry === "string" && (entry.endsWith(` ${quote(program)} hook ${source}`) || (source === "claude" && entry.endsWith(` ${quote(fast)} claude`)));
326
395
  if (remove || modules?.has("hook") === false) {
327
396
  const owned = Object.values(hooks).flatMap(objects).some(group => ownHook(group.command) || ownHook(group.bash) || objects(group.hooks).some(hook => ownHook(hook.command)));
328
397
  const statusChanged = source === "claude" && JSON.stringify(usageStatusLine(config.statusLine, program, true)) !== JSON.stringify(config.statusLine);
@@ -339,7 +408,7 @@ export async function planAgentHooks(program, remove = false, modules) {
339
408
  config.version = 1;
340
409
  for (const event of ["SessionStart", "UserPromptSubmit"]) {
341
410
  const entries = objects(hooks[event]).filter(h => !ownHook(h.bash) && !ownHook(h.command));
342
- hooks[event] = remove || modules?.has("hook") === false ? entries : [...entries, { type: "command", bash: command, timeoutSec: 3 }];
411
+ hooks[event] = remove || modules?.has("hook") === false ? entries : [...entries, { type: "command", bash: command, timeoutSec: 15 }];
343
412
  }
344
413
  }
345
414
  else {
@@ -350,7 +419,7 @@ export async function planAgentHooks(program, remove = false, modules) {
350
419
  // Codex names tools differently across versions; filter its callbacks
351
420
  // inside the Hook. Claude can narrow its registration here.
352
421
  const group = event.endsWith("ToolUse") ? { ...(source === "claude" ? { matcher: "Bash|Write|Edit|MultiEdit|NotebookEdit|apply_patch|str_replace_editor" } : {}), hooks: [{ type: "command", command, timeout: 10 }] }
353
- : { hooks: [{ type: "command", command, timeout: event === "PermissionRequest" ? 60 : 3 }] };
422
+ : { hooks: [{ type: "command", command, timeout: event === "PermissionRequest" ? 60 : 15 }] };
354
423
  const owner = event.endsWith("ToolUse") ? "git" : "hook";
355
424
  hooks[event] = remove || modules?.has("hook") === false || modules?.has(owner) === false ? groups : [...groups, group];
356
425
  }
@@ -422,6 +491,8 @@ async function applyAgentHooks(edits) {
422
491
  await atomic(file, after);
423
492
  }
424
493
  }
494
+ /** Codex's hooks.json as it stood before `edits` rewrote it, when they did. */
495
+ const codexHooksBefore = (edits) => edits.find(edit => edit.file === path.join(codexHome(), "hooks.json"))?.before;
425
496
  async function restoreAgentHooks(edits) {
426
497
  for (const { file, before, after } of edits) {
427
498
  // A concurrent user edit always wins over rollback.
@@ -440,6 +511,13 @@ export async function rollback() {
440
511
  await stopService();
441
512
  await activate(config.previous);
442
513
  await startService();
514
+ // The version now in `current/` decides whether Claude's callbacks run its
515
+ // forwarder or, from before the forwarder, its bundle.
516
+ const root = bridgeRoot();
517
+ const program = path.join(root, "current/bridge-hook.mjs");
518
+ const edits = await planAgentHooks(program, false, moduleSnapshot(defaultPhrenPath(), undefined, true), await currentHasFastHook(root));
519
+ await applyAgentHooks(edits);
520
+ await carryCodexHookTrust(program, codexHooksBefore(edits));
443
521
  await atomic(path.join(bridgeRoot(), "installed.json"), JSON.stringify({ version: config.previous, previous: config.version }) + "\n");
444
522
  }
445
523
  export async function reconcileModuleHooks(store, profile) {
@@ -448,7 +526,10 @@ export async function reconcileModuleHooks(store, profile) {
448
526
  // Synced enablement alone never installs a host service or enrolls a key.
449
527
  if (!await missingFile(readFile(path.join(root, "installed.json"))))
450
528
  return;
451
- await applyAgentHooks(await planAgentHooks(path.join(root, "current/bridge-hook.mjs"), false, modules));
529
+ const program = path.join(root, "current/bridge-hook.mjs");
530
+ const edits = await planAgentHooks(program, false, modules, await currentHasFastHook(root));
531
+ await applyAgentHooks(edits);
532
+ await carryCodexHookTrust(program, codexHooksBefore(edits));
452
533
  await applyOpencodePlugin(!modules.has("hook"));
453
534
  if (!modules.has("hook"))
454
535
  await stopService();
@@ -0,0 +1,96 @@
1
+ import { z } from "zod";
2
+ import { type Target } from "./protocol.js";
3
+ /**
4
+ * A worker's first prompt carried by its launch instead of typed into a
5
+ * starting pane. The brief is written to a private file on the computer that
6
+ * starts the agent, and the harness gets one short argument pointing at it:
7
+ * `claude "<prompt>"` and `codex "<prompt>"` both open the interactive TUI
8
+ * and submit that prompt themselves, so there is no Enter to lose and no
9
+ * starting pane to wait for. The same id is exported to the agent as
10
+ * `PHREN_DISPATCH_ID`, and its SessionStart and UserPromptSubmit hooks echo
11
+ * it back: the receipt is that echo, not a match on typed text.
12
+ *
13
+ * OpenCode takes its brief over the HTTP API its launched TUI serves
14
+ * (opencode-panes.ts); the file is still written so the arrival is recorded
15
+ * here. Copilot, with no such argument or API, keeps the typed path.
16
+ */
17
+ /** A dispatch receipt id or a scheduled run id: what `PHREN_DISPATCH_ID` carries. */
18
+ export declare const briefId: z.ZodString;
19
+ export declare const launchBriefSchema: z.ZodObject<{
20
+ id: z.ZodString;
21
+ text: z.ZodString;
22
+ }, z.core.$strict>;
23
+ export type LaunchBrief = z.infer<typeof launchBriefSchema>;
24
+ /** The variable a launched agent's hooks read its brief id from. */
25
+ export declare const DISPATCH_ID_ENV = "PHREN_DISPATCH_ID";
26
+ export declare function briefRoot(): string;
27
+ /** The harnesses whose TUI takes a first prompt as an argument, and the
28
+ * arguments that carry it. Claude reads outside its working directory only
29
+ * with permission, so the brief's own folder is added to its tool access;
30
+ * `--add-dir` takes several values, so it comes after the prompt. */
31
+ export declare function briefArgs(kind: string, file: string): string[] | undefined;
32
+ export declare function launchesWithBrief(kind: string): boolean;
33
+ /**
34
+ * The label the dispatcher gave a launched worker, kept beside its brief so
35
+ * this Hook can name the worker's session by it: the harness titles a session
36
+ * after its first prompt, which is only "Read and follow the brief in ...".
37
+ * Undefined for an id this computer wrote no label for (older dispatches).
38
+ */
39
+ export declare function briefLabel(id: string): Promise<string | undefined>;
40
+ /**
41
+ * Writes the brief (0600, in a 0700 folder of its own) and returns its path.
42
+ * A `label` is written beside it, inside the same folder, so it is published
43
+ * with the brief and never lags it.
44
+ * The folder is filled beside `briefs/` and renamed into place, so a brief
45
+ * folder never exists without its `brief.md`: anything that lists `briefs/`
46
+ * (the arrival route, a test, the owner) sees a whole brief or none. Writing
47
+ * it in place left a moment where the folder was there and the file was not.
48
+ */
49
+ export declare function writeLaunchBrief(brief: LaunchBrief, now?: number, label?: string): Promise<string>;
50
+ export declare const arrivalSchema: z.ZodObject<{
51
+ started: z.ZodOptional<z.ZodObject<{
52
+ at: z.ZodString;
53
+ target: z.ZodObject<{
54
+ server: z.ZodString;
55
+ workspace: z.ZodString;
56
+ tab: z.ZodString;
57
+ pane: z.ZodString;
58
+ source: z.ZodEnum<{
59
+ claude: "claude";
60
+ codex: "codex";
61
+ copilot: "copilot";
62
+ opencode: "opencode";
63
+ phren: "phren";
64
+ }>;
65
+ session: z.ZodUnion<readonly [z.ZodString, z.ZodString]>;
66
+ }, z.core.$strip>;
67
+ }, z.core.$strict>>;
68
+ accepted: z.ZodOptional<z.ZodObject<{
69
+ at: z.ZodString;
70
+ target: z.ZodObject<{
71
+ server: z.ZodString;
72
+ workspace: z.ZodString;
73
+ tab: z.ZodString;
74
+ pane: z.ZodString;
75
+ source: z.ZodEnum<{
76
+ claude: "claude";
77
+ codex: "codex";
78
+ copilot: "copilot";
79
+ opencode: "opencode";
80
+ phren: "phren";
81
+ }>;
82
+ session: z.ZodUnion<readonly [z.ZodString, z.ZodString]>;
83
+ }, z.core.$strip>;
84
+ }, z.core.$strict>>;
85
+ }, z.core.$strict>;
86
+ export type BriefArrival = z.infer<typeof arrivalSchema>;
87
+ /** What the worker's own hooks have said about its brief: `started` at its
88
+ * SessionStart, `accepted` when the brief prompt was submitted. Empty while
89
+ * neither has arrived; undefined when this computer wrote no such brief. */
90
+ export declare function briefArrival(id: string): Promise<BriefArrival | undefined>;
91
+ /** The brief id in a prompt that points at a brief file, for callbacks that
92
+ * cannot trust their own environment (Codex's shared hook daemon). */
93
+ export declare function briefIdInPrompt(prompt: string): string | undefined;
94
+ /** Records a worker hook's report about its brief. Only the first of each
95
+ * event counts, and only for a brief this computer wrote. */
96
+ export declare function recordBriefArrival(id: string, event: string, target: Target, now?: Date): Promise<void>;
@@ -0,0 +1,164 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { lstat, mkdir, readdir, readFile, rename, rm, stat } from "node:fs/promises";
3
+ import path from "node:path";
4
+ import { z } from "zod";
5
+ import { atomic, bridgeRoot, targetSchema } from "./protocol.js";
6
+ /**
7
+ * A worker's first prompt carried by its launch instead of typed into a
8
+ * starting pane. The brief is written to a private file on the computer that
9
+ * starts the agent, and the harness gets one short argument pointing at it:
10
+ * `claude "<prompt>"` and `codex "<prompt>"` both open the interactive TUI
11
+ * and submit that prompt themselves, so there is no Enter to lose and no
12
+ * starting pane to wait for. The same id is exported to the agent as
13
+ * `PHREN_DISPATCH_ID`, and its SessionStart and UserPromptSubmit hooks echo
14
+ * it back: the receipt is that echo, not a match on typed text.
15
+ *
16
+ * OpenCode takes its brief over the HTTP API its launched TUI serves
17
+ * (opencode-panes.ts); the file is still written so the arrival is recorded
18
+ * here. Copilot, with no such argument or API, keeps the typed path.
19
+ */
20
+ /** A dispatch receipt id or a scheduled run id: what `PHREN_DISPATCH_ID` carries. */
21
+ export const briefId = z.string().regex(/^[A-Za-z0-9_-]{8,64}$/);
22
+ export const launchBriefSchema = z.object({
23
+ id: briefId,
24
+ text: z.string().min(1).max(32768).refine(value => !!value.trim() && !/[\x00-\x08\x0b-\x1f\x7f]/.test(value)),
25
+ }).strict();
26
+ /** The variable a launched agent's hooks read its brief id from. */
27
+ export const DISPATCH_ID_ENV = "PHREN_DISPATCH_ID";
28
+ /** Briefs older than this are removed when the next one is written; a worker
29
+ * may re-read its brief after a compaction, so it is not removed on arrival. */
30
+ const KEEP_MS = 7 * 24 * 60 * 60 * 1000;
31
+ const MAX_BRIEFS = 256;
32
+ export function briefRoot() { return path.join(bridgeRoot(), "briefs"); }
33
+ function briefDirectory(id) { return path.join(briefRoot(), briefId.parse(id)); }
34
+ /** The harnesses whose TUI takes a first prompt as an argument, and the
35
+ * arguments that carry it. Claude reads outside its working directory only
36
+ * with permission, so the brief's own folder is added to its tool access;
37
+ * `--add-dir` takes several values, so it comes after the prompt. */
38
+ export function briefArgs(kind, file) {
39
+ if (!launchesWithBrief(kind))
40
+ return undefined;
41
+ const prompt = `Read and follow the brief in ${file}`;
42
+ if (kind === "claude")
43
+ return [prompt, "--add-dir", path.dirname(file)];
44
+ return [prompt];
45
+ }
46
+ export function launchesWithBrief(kind) { return kind === "claude" || kind === "codex"; }
47
+ async function prune(now) {
48
+ const root = briefRoot();
49
+ const names = (await readdir(root).catch(() => [])).filter(name => briefId.safeParse(name).success);
50
+ const entries = (await Promise.all(names.map(async (name) => {
51
+ const info = await lstat(path.join(root, name)).catch(() => undefined);
52
+ return info?.isDirectory() ? { name, at: info.mtimeMs } : undefined;
53
+ }))).filter((entry) => !!entry).sort((a, b) => b.at - a.at);
54
+ const stale = entries.filter((entry, index) => index >= MAX_BRIEFS - 1 || now - entry.at > KEEP_MS);
55
+ await Promise.all(stale.map(entry => rm(path.join(root, entry.name), { recursive: true, force: true }).catch(() => undefined)));
56
+ }
57
+ const LABEL_FILE = "label";
58
+ const MAX_LABEL = 200;
59
+ /** A dispatch label as stored and shown: control characters and runs of blanks collapsed, at most 200 characters. */
60
+ function cleanLabel(value) { return value.replace(/[\x00-\x1f\x7f]+/g, " ").replace(/\s+/g, " ").trim().slice(0, MAX_LABEL).trim(); }
61
+ /**
62
+ * The label the dispatcher gave a launched worker, kept beside its brief so
63
+ * this Hook can name the worker's session by it: the harness titles a session
64
+ * after its first prompt, which is only "Read and follow the brief in ...".
65
+ * Undefined for an id this computer wrote no label for (older dispatches).
66
+ */
67
+ export async function briefLabel(id) {
68
+ if (!briefId.safeParse(id).success)
69
+ return undefined;
70
+ const file = path.join(briefDirectory(id), LABEL_FILE);
71
+ try {
72
+ const info = await lstat(file);
73
+ if (!info.isFile() || info.size > 4 * MAX_LABEL)
74
+ return undefined;
75
+ return cleanLabel(await readFile(file, "utf8")) || undefined;
76
+ }
77
+ catch {
78
+ return undefined;
79
+ }
80
+ }
81
+ /**
82
+ * Writes the brief (0600, in a 0700 folder of its own) and returns its path.
83
+ * A `label` is written beside it, inside the same folder, so it is published
84
+ * with the brief and never lags it.
85
+ * The folder is filled beside `briefs/` and renamed into place, so a brief
86
+ * folder never exists without its `brief.md`: anything that lists `briefs/`
87
+ * (the arrival route, a test, the owner) sees a whole brief or none. Writing
88
+ * it in place left a moment where the folder was there and the file was not.
89
+ */
90
+ export async function writeLaunchBrief(brief, now = Date.now(), label) {
91
+ await mkdir(briefRoot(), { recursive: true, mode: 0o700 });
92
+ await prune(now);
93
+ const directory = briefDirectory(brief.id);
94
+ const file = path.join(directory, "brief.md");
95
+ const text = brief.text.endsWith("\n") ? brief.text : `${brief.text}\n`;
96
+ const named = label ? cleanLabel(label) : "";
97
+ const fill = async (folder) => {
98
+ await atomic(path.join(folder, "brief.md"), text);
99
+ if (named)
100
+ await atomic(path.join(folder, LABEL_FILE), named);
101
+ };
102
+ // The same id again (a retried launch) replaces the text and label in the existing folder.
103
+ if (await stat(directory).catch(() => undefined)) {
104
+ await fill(directory);
105
+ return file;
106
+ }
107
+ const staging = path.join(bridgeRoot(), "briefs-staging");
108
+ await mkdir(staging, { recursive: true, mode: 0o700 });
109
+ const draft = path.join(staging, `${brief.id}.${randomUUID()}`);
110
+ try {
111
+ await mkdir(draft, { mode: 0o700 });
112
+ await fill(draft);
113
+ await rename(draft, directory);
114
+ }
115
+ catch (error) {
116
+ await rm(draft, { recursive: true, force: true }).catch(() => undefined);
117
+ // Another writer published the same id first: write into its folder.
118
+ if (!(await stat(path.join(directory, "brief.md")).catch(() => undefined)))
119
+ throw error;
120
+ await fill(directory);
121
+ }
122
+ return file;
123
+ }
124
+ const arrivalEvent = z.object({ at: z.string().datetime(), target: targetSchema }).strict();
125
+ export const arrivalSchema = z.object({ started: arrivalEvent.optional(), accepted: arrivalEvent.optional() }).strict();
126
+ /** What the worker's own hooks have said about its brief: `started` at its
127
+ * SessionStart, `accepted` when the brief prompt was submitted. Empty while
128
+ * neither has arrived; undefined when this computer wrote no such brief. */
129
+ export async function briefArrival(id) {
130
+ const directory = briefDirectory(id);
131
+ if (!(await stat(directory).catch(() => undefined))?.isDirectory())
132
+ return undefined;
133
+ const text = await readFile(path.join(directory, "arrival.json"), "utf8").catch(() => undefined);
134
+ const parsed = text === undefined ? undefined : arrivalSchema.safeParse((() => { try {
135
+ return JSON.parse(text);
136
+ }
137
+ catch {
138
+ return undefined;
139
+ } })());
140
+ return parsed?.success ? parsed.data : {};
141
+ }
142
+ /** The brief id in a prompt that points at a brief file, for callbacks that
143
+ * cannot trust their own environment (Codex's shared hook daemon). */
144
+ export function briefIdInPrompt(prompt) {
145
+ const escaped = briefRoot().replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
146
+ const match = new RegExp(`${escaped}[\\\\/]([A-Za-z0-9_-]{8,64})[\\\\/]brief\\.md`).exec(prompt);
147
+ return match?.[1];
148
+ }
149
+ let arrivals = Promise.resolve();
150
+ /** Records a worker hook's report about its brief. Only the first of each
151
+ * event counts, and only for a brief this computer wrote. */
152
+ export function recordBriefArrival(id, event, target, now = new Date()) {
153
+ const kind = event === "UserPromptSubmit" ? "accepted" : event === "SessionStart" ? "started" : undefined;
154
+ if (!kind || !briefId.safeParse(id).success)
155
+ return Promise.resolve();
156
+ const run = arrivals.then(async () => {
157
+ const current = await briefArrival(id);
158
+ if (!current || current[kind])
159
+ return;
160
+ await atomic(path.join(briefDirectory(id), "arrival.json"), arrivalSchema.parse({ ...current, [kind]: { at: now.toISOString(), target } }));
161
+ });
162
+ arrivals = run.catch(() => undefined);
163
+ return run;
164
+ }
@@ -21,6 +21,9 @@ type EffortReply = {
21
21
  * the scrollback never confirms. A cap reports the level actually set; an
22
22
  * override or refusal is an error. */
23
23
  export declare function claudeEffortReply(text: string): EffortReply | undefined;
24
+ /** Empty prompts can draw a dim placeholder. Only ANSI evidence that every
25
+ * character after the prompt is dim distinguishes that from a person's draft. */
26
+ export declare function emptyComposer(line: string): boolean;
24
27
  /** Only a footer below Codex's empty composer proves the active model. Text
25
28
  * in history, a menu, or the startup banner must never confirm a switch. */
26
29
  export declare function codexModelStatus(text: string, model: AgentModel): boolean;
@@ -6,6 +6,7 @@ import { ModelCatalog } from "./models.js";
6
6
  import { BridgeError } from "./protocol.js";
7
7
  import { sideQuestionText } from "./side-questions.js";
8
8
  import { stripTerminal } from "../terminal-text.js";
9
+ import { codexServers } from "./codex-servers.js";
9
10
  export const MODEL_BUSY = "This agent is working. The model switch can happen when the turn ends. Choose Switch after this turn.";
10
11
  export const SLASH_BUSY = "This agent is working. Slash commands run between turns; send it again when this turn ends.";
11
12
  /** Busy slash commands must never enter the harness's text queue. Claude's
@@ -55,7 +56,7 @@ export function claudeEffortReply(text) {
55
56
  }
56
57
  /** Empty prompts can draw a dim placeholder. Only ANSI evidence that every
57
58
  * character after the prompt is dim distinguishes that from a person's draft. */
58
- function emptyComposer(line) {
59
+ export function emptyComposer(line) {
59
60
  if (!/^\s*[›❯>]\s*/.test(stripTerminal(line)))
60
61
  return false;
61
62
  let dim = false, prompt = false;
@@ -145,6 +146,21 @@ export class ModelSwitcher {
145
146
  throw new BridgeError(409, `Could not verify ${step}. Open terminal to check the model.`);
146
147
  };
147
148
  try {
149
+ // A Codex pane on the Hook's own app-server takes the model and effort
150
+ // with its next turn (turn/start overrides), as T3 does: no menu is
151
+ // walked in its TUI, and a working turn is left alone.
152
+ const served = target.source === "codex" ? codexServers.forTarget(target) : undefined;
153
+ if (served) {
154
+ const model = (await this.catalog.list("codex")).find(model => model.id === id);
155
+ if (!model)
156
+ throw new BridgeError(422, "That model is not in the computer's catalogue. Refresh the model list.");
157
+ const effort = chosenEffort ?? model.defaultReasoningEffort;
158
+ if (effort && model.supportedReasoningEfforts?.length && !model.supportedReasoningEfforts.includes(effort)) {
159
+ throw new BridgeError(422, "The catalogue does not confirm that reasoning effort. Refresh the model list.");
160
+ }
161
+ codexServers.setNextTurn(served, model.id, effort);
162
+ return { ok: true, model: model.id, name: model.name, ...(effort ? { effort } : {}), applies: "next-turn" };
163
+ }
148
164
  terminal = (await validate(true)).terminal_id;
149
165
  if (target.source === "opencode")
150
166
  throw new BridgeError(422, "OpenCode uses an interactive /models picker. Open terminal to switch models; remote selection cannot yet be verified.");
@@ -1,4 +1,4 @@
1
- import { type Json } from "./protocol.js";
1
+ import { BridgeError, type Json } from "./protocol.js";
2
2
  /** One entry of a `/model` menu as the phone draws it. */
3
3
  export interface AgentModel {
4
4
  id: string;
@@ -35,12 +35,16 @@ export declare function readClaudeModels(configDir?: string, installed?: string
35
35
  export declare function readOpenCodeModels(executable?: string, configDir?: string): Promise<AgentModel[]>;
36
36
  /** "claude-fable-5-1" reads as "Fable 5.1"; a date suffix is dropped. */
37
37
  export declare function claudeName(id: string): string;
38
- /** Catalogues change rarely and app-server takes seconds to start. */
38
+ /** The account a request names is not one on this computer (or has no catalogue for that source). */
39
+ export declare const accountUnavailable: (account: string) => BridgeError;
40
+ /** Catalogues change rarely and app-server takes seconds to start. Cached per
41
+ * `${source}:${account}`; only Claude has accounts, each reading its own home. */
39
42
  export declare class ModelCatalog {
40
43
  private readonly codex;
41
44
  private readonly claude;
42
45
  private readonly opencode;
46
+ private readonly cacheMs;
43
47
  private cache;
44
- constructor(codex?: () => Promise<AgentModel[]>, claude?: () => Promise<AgentModel[]>, opencode?: () => Promise<AgentModel[]>);
45
- list(source: string): Promise<AgentModel[]>;
48
+ constructor(codex?: () => Promise<AgentModel[]>, claude?: (configDir?: string) => Promise<AgentModel[]>, opencode?: () => Promise<AgentModel[]>, cacheMs?: number);
49
+ list(source: string, account?: string): Promise<AgentModel[]>;
46
50
  }