@phren/cli 0.2.15 → 0.2.16

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 (386) hide show
  1. package/README.md +2 -2
  2. package/dist/agent-instructions.d.ts +12 -0
  3. package/dist/agent-instructions.js +52 -0
  4. package/dist/bridge/agent-hook-stores.d.ts +32 -0
  5. package/dist/bridge/agent-hook-stores.js +67 -0
  6. package/dist/bridge/agent-hooks.d.ts +193 -2
  7. package/dist/bridge/agent-hooks.js +1045 -38
  8. package/dist/bridge/canary.d.ts +27 -0
  9. package/dist/bridge/canary.js +189 -0
  10. package/dist/bridge/changes.d.ts +57 -0
  11. package/dist/bridge/changes.js +403 -0
  12. package/dist/bridge/client.d.ts +3 -0
  13. package/dist/bridge/client.js +36 -0
  14. package/dist/bridge/code-note.d.ts +22 -0
  15. package/dist/bridge/code-note.js +42 -0
  16. package/dist/bridge/code-routes.d.ts +133 -0
  17. package/dist/bridge/code-routes.js +319 -0
  18. package/dist/bridge/codex-threads.d.ts +27 -0
  19. package/dist/bridge/codex-threads.js +442 -0
  20. package/dist/bridge/command.d.ts +7 -0
  21. package/dist/bridge/command.js +50 -5
  22. package/dist/bridge/computer-names.d.ts +4 -0
  23. package/dist/bridge/computer-names.js +16 -0
  24. package/dist/bridge/computers.d.ts +9 -0
  25. package/dist/bridge/computers.js +111 -0
  26. package/dist/bridge/context.d.ts +14 -0
  27. package/dist/bridge/context.js +149 -0
  28. package/dist/bridge/dispatch-command.d.ts +3 -0
  29. package/dist/bridge/dispatch-command.js +93 -0
  30. package/dist/bridge/dispatch-hosts.d.ts +23 -0
  31. package/dist/bridge/dispatch-hosts.js +25 -0
  32. package/dist/bridge/dispatch-returns.d.ts +123 -0
  33. package/dist/bridge/dispatch-returns.js +279 -0
  34. package/dist/bridge/dispatch-tree.d.ts +54 -0
  35. package/dist/bridge/dispatch-tree.js +198 -0
  36. package/dist/bridge/dispatch.d.ts +207 -0
  37. package/dist/bridge/dispatch.js +261 -0
  38. package/dist/bridge/enroll.d.ts +31 -0
  39. package/dist/bridge/enroll.js +236 -0
  40. package/dist/bridge/fanout-messages.d.ts +74 -0
  41. package/dist/bridge/fanout-messages.js +230 -0
  42. package/dist/bridge/fanouts.d.ts +160 -0
  43. package/dist/bridge/fanouts.js +702 -0
  44. package/dist/bridge/file-range.d.ts +16 -0
  45. package/dist/bridge/file-range.js +90 -0
  46. package/dist/bridge/files.d.ts +20 -0
  47. package/dist/bridge/files.js +54 -0
  48. package/dist/bridge/git-publish.d.ts +23 -0
  49. package/dist/bridge/git-publish.js +145 -0
  50. package/dist/bridge/git-worktrees.d.ts +21 -0
  51. package/dist/bridge/git-worktrees.js +150 -0
  52. package/dist/bridge/git.d.ts +54 -0
  53. package/dist/bridge/git.js +552 -0
  54. package/dist/bridge/grants.d.ts +31 -0
  55. package/dist/bridge/grants.js +181 -0
  56. package/dist/bridge/hand-off.d.ts +79 -0
  57. package/dist/bridge/hand-off.js +151 -0
  58. package/dist/bridge/health.d.ts +128 -0
  59. package/dist/bridge/health.js +260 -0
  60. package/dist/bridge/herdr.d.ts +79 -6
  61. package/dist/bridge/herdr.js +292 -27
  62. package/dist/bridge/hook-main.js +2 -0
  63. package/dist/bridge/install.d.ts +32 -1
  64. package/dist/bridge/install.js +225 -38
  65. package/dist/bridge/launch-worktree.d.ts +21 -0
  66. package/dist/bridge/launch-worktree.js +70 -0
  67. package/dist/bridge/limits.d.ts +20 -0
  68. package/dist/bridge/limits.js +65 -0
  69. package/dist/bridge/locate.d.ts +16 -0
  70. package/dist/bridge/locate.js +75 -0
  71. package/dist/bridge/metrics.d.ts +29 -0
  72. package/dist/bridge/metrics.js +71 -0
  73. package/dist/bridge/model-switch.d.ts +35 -0
  74. package/dist/bridge/model-switch.js +250 -0
  75. package/dist/bridge/models.d.ts +46 -0
  76. package/dist/bridge/models.js +257 -0
  77. package/dist/bridge/opencode-approvals.d.ts +6 -0
  78. package/dist/bridge/opencode-approvals.js +60 -0
  79. package/dist/bridge/pane-text.d.ts +15 -0
  80. package/dist/bridge/pane-text.js +23 -0
  81. package/dist/bridge/peers.d.ts +27 -0
  82. package/dist/bridge/peers.js +130 -0
  83. package/dist/bridge/projects.d.ts +12 -1
  84. package/dist/bridge/projects.js +268 -20
  85. package/dist/bridge/protocol.d.ts +35 -2
  86. package/dist/bridge/protocol.js +42 -7
  87. package/dist/bridge/push.d.ts +83 -0
  88. package/dist/bridge/push.js +199 -0
  89. package/dist/bridge/questions.d.ts +38 -0
  90. package/dist/bridge/questions.js +205 -0
  91. package/dist/bridge/schedule-format.d.ts +103 -0
  92. package/dist/bridge/schedule-format.js +266 -0
  93. package/dist/bridge/schedule-launch.d.ts +11 -0
  94. package/dist/bridge/schedule-launch.js +169 -0
  95. package/dist/bridge/schedule-watch.d.ts +52 -0
  96. package/dist/bridge/schedule-watch.js +242 -0
  97. package/dist/bridge/schedules.d.ts +48 -0
  98. package/dist/bridge/schedules.js +205 -0
  99. package/dist/bridge/server-launch.d.ts +14 -0
  100. package/dist/bridge/server-launch.js +218 -0
  101. package/dist/bridge/server-overview.d.ts +45 -0
  102. package/dist/bridge/server-overview.js +102 -0
  103. package/dist/bridge/server-pane-routes.d.ts +29 -0
  104. package/dist/bridge/server-pane-routes.js +400 -0
  105. package/dist/bridge/server-routes.d.ts +106 -0
  106. package/dist/bridge/server-routes.js +538 -0
  107. package/dist/bridge/server-stream.d.ts +46 -0
  108. package/dist/bridge/server-stream.js +253 -0
  109. package/dist/bridge/server.d.ts +3 -15
  110. package/dist/bridge/server.js +162 -264
  111. package/dist/bridge/session-servers.d.ts +24 -0
  112. package/dist/bridge/session-servers.js +136 -0
  113. package/dist/bridge/side-questions.d.ts +74 -0
  114. package/dist/bridge/side-questions.js +252 -0
  115. package/dist/bridge/simulators.d.ts +28 -0
  116. package/dist/bridge/simulators.js +198 -0
  117. package/dist/bridge/speech-transcribe.d.ts +24 -0
  118. package/dist/bridge/speech-transcribe.js +124 -0
  119. package/dist/bridge/speech.d.ts +35 -0
  120. package/dist/bridge/speech.js +98 -0
  121. package/dist/bridge/steps.d.ts +13 -0
  122. package/dist/bridge/steps.js +222 -0
  123. package/dist/bridge/tab-activity.d.ts +18 -0
  124. package/dist/bridge/tab-activity.js +99 -0
  125. package/dist/bridge/terminal-choice.d.ts +64 -0
  126. package/dist/bridge/terminal-choice.js +281 -0
  127. package/dist/bridge/transcript-claude.d.ts +22 -0
  128. package/dist/bridge/transcript-claude.js +353 -0
  129. package/dist/bridge/transcript-codex.d.ts +30 -0
  130. package/dist/bridge/transcript-codex.js +282 -0
  131. package/dist/bridge/transcript-copilot.d.ts +4 -0
  132. package/dist/bridge/transcript-copilot.js +14 -0
  133. package/dist/bridge/transcript-opencode.d.ts +5 -0
  134. package/dist/bridge/transcript-opencode.js +26 -0
  135. package/dist/bridge/transcript-preview.d.ts +94 -0
  136. package/dist/bridge/transcript-preview.js +476 -0
  137. package/dist/bridge/transcripts.d.ts +81 -4
  138. package/dist/bridge/transcripts.js +332 -67
  139. package/dist/bridge/transport.d.ts +3 -0
  140. package/dist/bridge/transport.js +96 -15
  141. package/dist/bridge/uploads.d.ts +15 -0
  142. package/dist/bridge/uploads.js +44 -2
  143. package/dist/bridge/usage.d.ts +124 -0
  144. package/dist/bridge/usage.js +859 -0
  145. package/dist/bridge-hook.mjs +41246 -21385
  146. package/dist/cli/actions.js +14 -1
  147. package/dist/cli/config-proactivity.d.ts +3 -1
  148. package/dist/cli/config-proactivity.js +35 -3
  149. package/dist/cli/config.js +4 -1
  150. package/dist/cli/extract.js +3 -6
  151. package/dist/cli/govern.js +5 -2
  152. package/dist/cli/hooks-globs.js +1 -1
  153. package/dist/cli/hooks.d.ts +1 -1
  154. package/dist/cli/hooks.js +9 -7
  155. package/dist/cli/namespaces-projects.js +12 -6
  156. package/dist/cli/namespaces-store.js +37 -6
  157. package/dist/cli/namespaces-tasks.js +1 -1
  158. package/dist/cli/schedules.d.ts +1 -0
  159. package/dist/cli/schedules.js +164 -0
  160. package/dist/cli/session-background.js +1 -1
  161. package/dist/cli/session-git.d.ts +8 -5
  162. package/dist/cli/session-git.js +45 -120
  163. package/dist/cli/session-start.js +3 -1
  164. package/dist/cli/session-stop.js +19 -8
  165. package/dist/cli/team.js +13 -10
  166. package/dist/cli-handlers.d.ts +1 -1
  167. package/dist/cli-handlers.js +8 -4
  168. package/dist/cli-help.d.ts +5 -4
  169. package/dist/cli-help.js +15 -15
  170. package/dist/cli-registry.d.ts +4 -1
  171. package/dist/cli-registry.js +119 -6
  172. package/dist/content/archive.js +2 -2
  173. package/dist/content/citation.d.ts +11 -0
  174. package/dist/content/citation.js +18 -0
  175. package/dist/content/learning.js +2 -0
  176. package/dist/content/summarize.d.ts +14 -15
  177. package/dist/content/summarize.js +60 -5
  178. package/dist/content/validate.d.ts +3 -1
  179. package/dist/content/validate.js +26 -8
  180. package/dist/core/project-registry.d.ts +26 -0
  181. package/dist/core/project-registry.js +573 -0
  182. package/dist/core/project.js +2 -3
  183. package/dist/data/access.d.ts +7 -1
  184. package/dist/data/access.js +13 -3
  185. package/dist/data/tasks.d.ts +18 -3
  186. package/dist/data/tasks.js +8 -7
  187. package/dist/entrypoint.js +44 -10
  188. package/dist/fanout/adapters/claude.d.ts +2 -0
  189. package/dist/fanout/adapters/claude.js +7 -0
  190. package/dist/fanout/adapters/codex.d.ts +2 -0
  191. package/dist/fanout/adapters/codex.js +9 -0
  192. package/dist/fanout/adapters/opencode.d.ts +4 -0
  193. package/dist/fanout/adapters/opencode.js +9 -0
  194. package/dist/fanout/adapters/types.d.ts +21 -0
  195. package/dist/fanout/adapters/types.js +3 -0
  196. package/dist/fanout/command.d.ts +2 -0
  197. package/dist/fanout/command.js +78 -0
  198. package/dist/fanout/launcher.d.ts +27 -0
  199. package/dist/fanout/launcher.js +156 -0
  200. package/dist/fanout/opencode-serve.d.ts +24 -0
  201. package/dist/fanout/opencode-serve.js +191 -0
  202. package/dist/fanout/picker.d.ts +91 -0
  203. package/dist/fanout/picker.js +51 -0
  204. package/dist/fanout/usage.d.ts +5 -0
  205. package/dist/fanout/usage.js +51 -0
  206. package/dist/fanout/watchdog.d.ts +10 -0
  207. package/dist/fanout/watchdog.js +27 -0
  208. package/dist/filenames.d.ts +9 -0
  209. package/dist/filenames.js +11 -0
  210. package/dist/finding/context.js +4 -22
  211. package/dist/generated/memory-ui-graph.browser.js +279 -283
  212. package/dist/governance/policy-constants.d.ts +11 -0
  213. package/dist/governance/policy-constants.js +9 -0
  214. package/dist/governance/policy.d.ts +5 -8
  215. package/dist/governance/policy.js +7 -5
  216. package/dist/graph-core/camera.d.ts +24 -0
  217. package/dist/graph-core/camera.js +18 -0
  218. package/dist/graph-core/index.d.ts +2 -0
  219. package/dist/graph-core/index.js +2 -0
  220. package/dist/graph-core/labels.d.ts +77 -0
  221. package/dist/graph-core/labels.js +124 -0
  222. package/dist/graph-core/model.d.ts +13 -0
  223. package/dist/graph-core/model.js +33 -0
  224. package/dist/graph-core/types.d.ts +2 -0
  225. package/dist/home-paths.d.ts +7 -0
  226. package/dist/home-paths.js +21 -0
  227. package/dist/hooks.d.ts +3 -0
  228. package/dist/hooks.js +13 -0
  229. package/dist/index.js +24 -2
  230. package/dist/init/guard-globals.d.ts +1 -1
  231. package/dist/init/guard-globals.js +4 -4
  232. package/dist/init/init-configure.js +3 -3
  233. package/dist/init/init-uninstall.js +2 -2
  234. package/dist/init/init-walkthrough.js +1 -1
  235. package/dist/init/init.js +26 -6
  236. package/dist/init/management-preset.d.ts +1 -1
  237. package/dist/init/management-preset.js +2 -2
  238. package/dist/init/preferences.js +1 -1
  239. package/dist/init/self-wiring.js +1 -1
  240. package/dist/init/setup.d.ts +3 -26
  241. package/dist/init/setup.js +49 -588
  242. package/dist/init/shared.js +2 -0
  243. package/dist/init/store-gitignore.d.ts +1 -1
  244. package/dist/init/store-gitignore.js +2 -0
  245. package/dist/init/teardown.d.ts +1 -1
  246. package/dist/init/teardown.js +2 -2
  247. package/dist/link/context.js +1 -1
  248. package/dist/link/doctor.d.ts +22 -1
  249. package/dist/link/doctor.js +100 -54
  250. package/dist/link/link.js +29 -61
  251. package/dist/link/refresh.js +2 -2
  252. package/dist/link/skills.js +26 -5
  253. package/dist/machine-identity.d.ts +3 -0
  254. package/dist/machine-identity.js +6 -0
  255. package/dist/mcp/profile.d.ts +2 -15
  256. package/dist/mcp/profile.js +64 -9
  257. package/dist/memory-ui-graph.runtime.js +279 -283
  258. package/dist/modules/code-package.d.ts +16 -0
  259. package/dist/modules/code-package.js +152 -0
  260. package/dist/modules/command.d.ts +2 -0
  261. package/dist/modules/command.js +67 -0
  262. package/dist/modules/config.d.ts +4 -0
  263. package/dist/modules/config.js +70 -0
  264. package/dist/modules/manifest.d.ts +41 -0
  265. package/dist/modules/manifest.js +1 -0
  266. package/dist/modules/provision.d.ts +3 -0
  267. package/dist/modules/provision.js +84 -0
  268. package/dist/modules/registry.d.ts +16 -0
  269. package/dist/modules/registry.js +250 -0
  270. package/dist/modules/runtime.d.ts +15 -0
  271. package/dist/modules/runtime.js +59 -0
  272. package/dist/package-metadata.js +10 -2
  273. package/dist/phren-dotenv.js +4 -2
  274. package/dist/phren-paths.d.ts +3 -2
  275. package/dist/phren-paths.js +4 -5
  276. package/dist/profile-store.js +4 -5
  277. package/dist/project-config.d.ts +19 -1
  278. package/dist/project-config.js +29 -3
  279. package/dist/project-topics.js +4 -4
  280. package/dist/provider-adapters.js +1 -4
  281. package/dist/query-correlation.js +6 -6
  282. package/dist/session/artifacts.js +5 -5
  283. package/dist/session/checkpoints.js +5 -0
  284. package/dist/session/utils.d.ts +2 -2
  285. package/dist/session/utils.js +6 -6
  286. package/dist/shared/content.d.ts +1 -1
  287. package/dist/shared/content.js +1 -1
  288. package/dist/shared/data-utils.js +1 -1
  289. package/dist/shared/fragment-graph.d.ts +1 -1
  290. package/dist/shared/fragment-graph.js +5 -5
  291. package/dist/shared/index.js +48 -7
  292. package/dist/shared/retrieval.d.ts +18 -1
  293. package/dist/shared/retrieval.js +100 -11
  294. package/dist/shared/search-fallback.js +4 -6
  295. package/dist/shared/sqljs.d.ts +2 -0
  296. package/dist/shared/sqljs.js +4 -2
  297. package/dist/shared.d.ts +0 -1
  298. package/dist/shared.js +0 -1
  299. package/dist/shell/input.d.ts +1 -5
  300. package/dist/shell/input.js +16 -10
  301. package/dist/shell/palette.d.ts +2 -2
  302. package/dist/shell/palette.js +3 -7
  303. package/dist/shell/render.d.ts +3 -1
  304. package/dist/shell/render.js +4 -4
  305. package/dist/shell/shell.js +4 -1
  306. package/dist/shell/types.d.ts +1 -0
  307. package/dist/shell/types.js +4 -0
  308. package/dist/shell/view.d.ts +0 -4
  309. package/dist/shell/view.js +19 -27
  310. package/dist/skill/registry.js +25 -17
  311. package/dist/skill/state.d.ts +3 -0
  312. package/dist/skill/state.js +13 -7
  313. package/dist/status.js +38 -17
  314. package/dist/store-registry.d.ts +44 -18
  315. package/dist/store-registry.js +169 -60
  316. package/dist/store-weight.d.ts +1 -6
  317. package/dist/store-weight.js +4 -2
  318. package/dist/sync/auth-doctor.d.ts +8 -0
  319. package/dist/sync/auth-doctor.js +27 -0
  320. package/dist/sync/auth.d.ts +27 -0
  321. package/dist/sync/auth.js +114 -0
  322. package/dist/sync/conflict-resolve.d.ts +9 -0
  323. package/dist/sync/conflict-resolve.js +146 -0
  324. package/dist/sync/git-state.d.ts +4 -0
  325. package/dist/sync/git-state.js +49 -0
  326. package/dist/sync/outcome.d.ts +34 -0
  327. package/dist/sync/outcome.js +57 -0
  328. package/dist/sync/pull.d.ts +15 -7
  329. package/dist/sync/pull.js +84 -35
  330. package/dist/sync/store-merge.d.ts +29 -0
  331. package/dist/sync/store-merge.js +137 -0
  332. package/dist/sync/task-merge.d.ts +22 -0
  333. package/dist/sync/task-merge.js +158 -0
  334. package/dist/task/github.js +1 -1
  335. package/dist/task/lifecycle.d.ts +5 -0
  336. package/dist/task/lifecycle.js +67 -23
  337. package/dist/terminal-text.d.ts +5 -0
  338. package/dist/terminal-text.js +11 -0
  339. package/dist/test-global-setup.js +7 -0
  340. package/dist/tool-registry.d.ts +1 -1
  341. package/dist/tool-registry.js +3 -1
  342. package/dist/tools/code.d.ts +3 -0
  343. package/dist/tools/code.js +178 -0
  344. package/dist/tools/config.js +5 -0
  345. package/dist/tools/data.js +14 -7
  346. package/dist/tools/dispatch.d.ts +2 -0
  347. package/dist/tools/dispatch.js +66 -0
  348. package/dist/tools/finding.js +43 -41
  349. package/dist/tools/ops.js +5 -2
  350. package/dist/tools/search.js +21 -8
  351. package/dist/tools/session.js +21 -22
  352. package/dist/tools/tasks.js +8 -2
  353. package/dist/tools/types.d.ts +2 -2
  354. package/dist/tools/types.js +2 -2
  355. package/dist/ui/assets.js +1 -1
  356. package/dist/ui/data.js +14 -15
  357. package/dist/ui/deep-void.d.ts +1 -1
  358. package/dist/ui/deep-void.js +0 -1
  359. package/dist/ui/graph-chrome.d.ts +1 -1
  360. package/dist/ui/graph-chrome.js +51 -0
  361. package/dist/ui/page.js +5 -5
  362. package/dist/ui/scripts.js +67 -30
  363. package/dist/ui/server.js +34 -6
  364. package/dist/update.js +1 -1
  365. package/dist/utils-fts.js +1 -0
  366. package/dist/utils-helpers.d.ts +7 -0
  367. package/dist/utils-helpers.js +17 -0
  368. package/dist/utils.d.ts +1 -1
  369. package/dist/utils.js +1 -1
  370. package/package.json +45 -3
  371. package/plugins/opencode/phren-transcript.js +340 -0
  372. package/starter/README.md +4 -4
  373. package/starter/global/{CLAUDE.md → AGENTS.md} +2 -2
  374. package/starter/global/skills/conductor/SKILL.md +106 -0
  375. package/starter/global/skills/fanout/SKILL.md +20 -0
  376. package/starter/global/skills/phren-discover/SKILL.md +6 -6
  377. package/starter/global/skills/phren-init/SKILL.md +4 -4
  378. package/starter/global/skills/phren-sync/SKILL.md +3 -3
  379. package/starter/templates/frontend/reference/README.md +1 -1
  380. package/starter/templates/library/reference/README.md +1 -1
  381. package/starter/templates/monorepo/reference/README.md +1 -1
  382. package/starter/templates/python-project/reference/README.md +1 -1
  383. /package/starter/templates/frontend/{CLAUDE.md → AGENTS.md} +0 -0
  384. /package/starter/templates/library/{CLAUDE.md → AGENTS.md} +0 -0
  385. /package/starter/templates/monorepo/{CLAUDE.md → AGENTS.md} +0 -0
  386. /package/starter/templates/python-project/{CLAUDE.md → AGENTS.md} +0 -0
@@ -0,0 +1,74 @@
1
+ import { type Json, type Target } from "./protocol.js";
2
+ /** Claude Code's `/btw` side questions from the phone.
3
+ *
4
+ * `/btw <question>` asks a quick question while Claude keeps working. Claude
5
+ * 2.1.280 draws the answer in a panel under the conversation and writes
6
+ * nothing to the session JSONL, so the Hook reads the settled panel from the
7
+ * pane, scrolls it for a long answer, closes it with Escape and hands the text
8
+ * to the phone as a `side-answer` frame. Nothing of it enters the transcript. */
9
+ export type SideState = "pending" | "answer" | "error" | "cancelled";
10
+ export interface SideAnswer {
11
+ id: string;
12
+ question: string;
13
+ state: SideState;
14
+ answer?: string;
15
+ }
16
+ /** The panel as the pane draws it: the asked questions (this session's
17
+ * history, newest last and cut to the pane's width), the body lines, and
18
+ * whether Claude is still answering. */
19
+ export interface SidePanel {
20
+ questions: string[];
21
+ body: string[];
22
+ answering: boolean;
23
+ settled: boolean;
24
+ }
25
+ /** The question in a `/btw ` prompt for Claude, or undefined for any other text. */
26
+ export declare function sideQuestionText(source: string, text: string): string | undefined;
27
+ /** Parse the `/btw` panel out of visible pane text, or undefined when none is open. */
28
+ export declare function sidePanel(text: string): SidePanel | undefined;
29
+ /** Whether the newest question in the panel is the one the Hook asked: the
30
+ * panel cuts a long question to the pane's width with an ellipsis. */
31
+ export declare function panelAsks(panel: SidePanel, question: string): boolean;
32
+ /** The lines `next` adds below `previous` after the panel scrolled, or
33
+ * undefined when it did not move. Without an overlap the whole window is new. */
34
+ export declare function scrolledLines(previous: string[], next: string[]): string[] | undefined;
35
+ /** Remove the panel's indentation and the wrap-trailing spaces. */
36
+ export declare function answerText(lines: string[]): string;
37
+ export declare class SideQuestions {
38
+ private readonly options;
39
+ private records;
40
+ private open;
41
+ constructor(options?: {
42
+ timeoutMs?: number;
43
+ intervalMs?: number;
44
+ openMs?: number;
45
+ keepMs?: number;
46
+ });
47
+ private paneKey;
48
+ private read;
49
+ /** While a side question owns the pane, typed input would land in its panel
50
+ * (`x` clears the history, `f` forks), so every other input waits. */
51
+ assertAvailable(target: Target): void;
52
+ /** The side answers the phone has not dismissed for this conversation. */
53
+ list(target: Target): (SideAnswer & {
54
+ revision: number;
55
+ })[];
56
+ private prune;
57
+ /** Type `/btw <question>` into the Claude pane and watch for its answer.
58
+ * Returns at once; the answer arrives on the transcript stream. */
59
+ ask(target: Target, pane: Json, text: string): Promise<{
60
+ id: string;
61
+ }>;
62
+ /** The phone dismissed the card: cancel a pending question (closing its
63
+ * panel) and stop delivering it. */
64
+ dismiss(target: Target, id: string): {
65
+ ok: true;
66
+ };
67
+ private settle;
68
+ /** Close the panel only while it is still drawn: Escape anywhere else
69
+ * would interrupt Claude's running turn. */
70
+ private close;
71
+ /** Scroll a long answer to its end, stitching the windows by their overlap. */
72
+ private collect;
73
+ private watch;
74
+ }
@@ -0,0 +1,252 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { rpc, validateTarget } from "./herdr.js";
3
+ import { readPaneText } from "./pane-text.js";
4
+ import { BridgeError } from "./protocol.js";
5
+ const MAX_QUESTION = 4_000;
6
+ const MAX_ANSWER = 65_536;
7
+ /** The question in a `/btw ` prompt for Claude, or undefined for any other text. */
8
+ export function sideQuestionText(source, text) {
9
+ const match = /^\s*\/btw\s+(\S[\s\S]*)$/i.exec(text);
10
+ if (source !== "claude" || !match)
11
+ return undefined;
12
+ // One terminal line: a newline would submit the command early.
13
+ return match[1].replace(/\s+/g, " ").trim();
14
+ }
15
+ /** Parse the `/btw` panel out of visible pane text, or undefined when none is open. */
16
+ export function sidePanel(text) {
17
+ const lines = text.replace(/\r/g, "").split("\n");
18
+ let close = -1;
19
+ for (let index = lines.length - 1; index >= 0; index--) {
20
+ if (/\bEsc to close\s*$/.test(lines[index])) {
21
+ close = index;
22
+ break;
23
+ }
24
+ if (lines[index].trim())
25
+ return undefined;
26
+ }
27
+ if (close < 0)
28
+ return undefined;
29
+ // The footer can wrap: "⇧←/→ to browse · c to copy · f to fork ·" then
30
+ // "x to clear history · Esc to close" on a narrow pane.
31
+ let footerStart = close;
32
+ while (footerStart > 0 && lines[footerStart - 1].trim())
33
+ footerStart--;
34
+ const footer = lines.slice(footerStart, close + 1).join(" ");
35
+ // The panel's top edge is a run of ▔, which may carry the effort label.
36
+ let top = -1;
37
+ for (let index = footerStart - 1; index >= 0; index--)
38
+ if (/^▔{3,}/.test(lines[index].trimStart())) {
39
+ top = index;
40
+ break;
41
+ }
42
+ if (top < 0)
43
+ return undefined;
44
+ let index = top + 1;
45
+ while (index < footerStart && !lines[index].trim())
46
+ index++;
47
+ const questions = [];
48
+ while (index < footerStart && /^\s+\/btw\s/.test(lines[index]))
49
+ questions.push(lines[index++].trim().replace(/^\/btw\s+/, ""));
50
+ if (!questions.length)
51
+ return undefined;
52
+ const body = lines.slice(index, footerStart);
53
+ while (body.length && !body[0].trim())
54
+ body.shift();
55
+ while (body.length && !body.at(-1).trim())
56
+ body.pop();
57
+ const answering = body.length === 1 && /^\s*\S\s+Answering…\s*$/.test(body[0]);
58
+ return { questions, body: answering ? [] : body, answering, settled: !answering && /\bc to copy\b/.test(footer) };
59
+ }
60
+ /** Whether the newest question in the panel is the one the Hook asked: the
61
+ * panel cuts a long question to the pane's width with an ellipsis. */
62
+ export function panelAsks(panel, question) {
63
+ const shown = panel.questions.at(-1) ?? "";
64
+ if (shown.endsWith("…"))
65
+ return question.startsWith(shown.slice(0, -1).trimEnd());
66
+ return shown === question;
67
+ }
68
+ /** The lines `next` adds below `previous` after the panel scrolled, or
69
+ * undefined when it did not move. Without an overlap the whole window is new. */
70
+ export function scrolledLines(previous, next) {
71
+ if (previous.length === next.length && previous.every((line, index) => line === next[index]))
72
+ return undefined;
73
+ for (let shift = 1; shift < previous.length; shift++) {
74
+ const kept = previous.length - shift;
75
+ if (next.length < kept)
76
+ continue;
77
+ let same = true;
78
+ for (let index = 0; index < kept && same; index++)
79
+ same = previous[shift + index] === next[index];
80
+ if (same)
81
+ return next.slice(kept);
82
+ }
83
+ return next;
84
+ }
85
+ /** Remove the panel's indentation and the wrap-trailing spaces. */
86
+ export function answerText(lines) {
87
+ const indent = Math.min(...lines.filter(line => line.trim()).map(line => line.length - line.trimStart().length));
88
+ const text = lines.map(line => line.slice(Number.isFinite(indent) ? indent : 0).trimEnd()).join("\n").trim();
89
+ return text.length > MAX_ANSWER ? text.slice(0, MAX_ANSWER) + "…" : text;
90
+ }
91
+ const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
92
+ export class SideQuestions {
93
+ options;
94
+ records = new Map();
95
+ open = new Map();
96
+ constructor(options = {}) {
97
+ this.options = options;
98
+ }
99
+ paneKey(target) { return `${target.server}\0${target.pane}`; }
100
+ read(target) {
101
+ return readPaneText(target.server, target.pane, { method: "agent.read", source: "visible", lines: 80, timeoutMs: 2_000 });
102
+ }
103
+ /** While a side question owns the pane, typed input would land in its panel
104
+ * (`x` clears the history, `f` forks), so every other input waits. */
105
+ assertAvailable(target) {
106
+ if (this.open.has(this.paneKey(target)))
107
+ throw new BridgeError(409, "A side question is open in this terminal. Wait for its answer or dismiss it.");
108
+ }
109
+ /** The side answers the phone has not dismissed for this conversation. */
110
+ list(target) {
111
+ this.prune();
112
+ return [...this.records.values()].filter(record => record.target.server === target.server && record.target.pane === target.pane
113
+ && record.target.session === target.session)
114
+ .map(({ id, question, state, answer, revision }) => ({ id, question, state, ...(answer !== undefined ? { answer } : {}), revision }));
115
+ }
116
+ prune() {
117
+ const keep = this.options.keepMs ?? 30 * 60_000, now = Date.now();
118
+ for (const [id, record] of this.records)
119
+ if (record.settledAt && now - record.settledAt > keep)
120
+ this.records.delete(id);
121
+ while (this.records.size > 32)
122
+ this.records.delete(this.records.keys().next().value);
123
+ }
124
+ /** Type `/btw <question>` into the Claude pane and watch for its answer.
125
+ * Returns at once; the answer arrives on the transcript stream. */
126
+ async ask(target, pane, text) {
127
+ const question = sideQuestionText(target.source, text);
128
+ if (!question)
129
+ throw new BridgeError(422, "Side questions are for Claude Code: /btw followed by the question.");
130
+ if (question.length > MAX_QUESTION)
131
+ throw new BridgeError(413, "The side question is too long.");
132
+ this.assertAvailable(target);
133
+ const key = this.paneKey(target), id = randomUUID();
134
+ this.open.set(key, id);
135
+ try {
136
+ // A panel the person opened in the terminal takes keys, not a prompt.
137
+ if (sidePanel(await this.read(target)))
138
+ throw new BridgeError(409, "The terminal already shows a side question. Close it there first.");
139
+ await rpc(target.server, "agent.prompt", { target: target.pane, text: `/btw ${question}` });
140
+ }
141
+ catch (error) {
142
+ this.open.delete(key);
143
+ throw error;
144
+ }
145
+ const record = { id, question, state: "pending", target, revision: 1 };
146
+ this.records.set(id, record);
147
+ this.prune();
148
+ void this.watch(record, String(pane.terminal_id ?? "")).finally(() => { if (this.open.get(key) === id)
149
+ this.open.delete(key); });
150
+ return { id };
151
+ }
152
+ /** The phone dismissed the card: cancel a pending question (closing its
153
+ * panel) and stop delivering it. */
154
+ dismiss(target, id) {
155
+ const record = this.records.get(id);
156
+ if (!record || record.target.server !== target.server || record.target.pane !== target.pane || record.target.session !== target.session) {
157
+ throw new BridgeError(404, "That side question is no longer open.");
158
+ }
159
+ if (record.state === "pending")
160
+ record.cancel = true;
161
+ else
162
+ this.records.delete(id);
163
+ return { ok: true };
164
+ }
165
+ settle(record, state, answer) {
166
+ record.state = state;
167
+ record.revision++;
168
+ record.settledAt = Date.now();
169
+ if (answer !== undefined)
170
+ record.answer = answer;
171
+ if (record.cancel)
172
+ this.records.delete(record.id);
173
+ }
174
+ /** Close the panel only while it is still drawn: Escape anywhere else
175
+ * would interrupt Claude's running turn. */
176
+ async close(target) {
177
+ for (let attempt = 0; attempt < 3; attempt++) {
178
+ if (!sidePanel(await this.read(target)))
179
+ return;
180
+ await rpc(target.server, "agent.send_keys", { target: target.pane, keys: ["esc"] });
181
+ await sleep(Math.min(this.options.intervalMs ?? 700, 300));
182
+ }
183
+ }
184
+ /** Scroll a long answer to its end, stitching the windows by their overlap. */
185
+ async collect(target, first) {
186
+ const lines = [...first.body];
187
+ let window = first.body, perKey = 0, size = lines.join("\n").length;
188
+ for (let step = 0; step < 200 && size < MAX_ANSWER; step++) {
189
+ const presses = perKey > 0 ? Math.max(1, Math.floor((window.length - 2) / perKey)) : 1;
190
+ await rpc(target.server, "agent.send_keys", { target: target.pane, keys: Array(presses).fill("down") });
191
+ await sleep(Math.min(this.options.intervalMs ?? 700, 150));
192
+ const panel = sidePanel(await this.read(target));
193
+ if (!panel || panel.answering)
194
+ break;
195
+ const added = scrolledLines(window, panel.body);
196
+ if (added === undefined)
197
+ break;
198
+ if (!perKey && added.length)
199
+ perKey = added.length;
200
+ lines.push(...added);
201
+ size += added.join("\n").length;
202
+ window = panel.body;
203
+ }
204
+ return answerText(lines);
205
+ }
206
+ async watch(record, terminal) {
207
+ const { target } = record, started = Date.now();
208
+ const timeout = this.options.timeoutMs ?? 90_000, openWithin = this.options.openMs ?? 10_000;
209
+ let opened = false, previous;
210
+ try {
211
+ for (;;) {
212
+ await sleep(this.options.intervalMs ?? 700);
213
+ const pane = await validateTarget(target, false, false).catch(() => undefined);
214
+ if (!pane || (terminal && pane.terminal_id !== terminal))
215
+ return this.settle(record, "error", "The conversation in this pane changed.");
216
+ const panel = sidePanel(await this.read(target));
217
+ if (record.cancel) {
218
+ if (panel)
219
+ await this.close(target);
220
+ return this.settle(record, "cancelled");
221
+ }
222
+ if (!panel || !panelAsks(panel, record.question)) {
223
+ // Closed in the terminal after it opened: the person dismissed it there.
224
+ if (opened)
225
+ return this.settle(record, "cancelled");
226
+ if (Date.now() - started > openWithin)
227
+ return this.settle(record, "error", "Claude did not open the side question.");
228
+ continue;
229
+ }
230
+ opened = true;
231
+ if (!panel.answering) {
232
+ // A settled panel offers copy; without that hint, wait for the
233
+ // same body twice so a still-drawing answer is not cut short.
234
+ const body = panel.body.join("\n");
235
+ if (panel.settled || body === previous) {
236
+ const answer = await this.collect(target, panel);
237
+ await this.close(target);
238
+ return this.settle(record, "answer", answer);
239
+ }
240
+ previous = body;
241
+ }
242
+ if (Date.now() - started > timeout) {
243
+ await this.close(target);
244
+ return this.settle(record, "error", `No answer after ${Math.round(timeout / 1000)} seconds.`);
245
+ }
246
+ }
247
+ }
248
+ catch {
249
+ this.settle(record, "error", "The side question could not be read from the terminal.");
250
+ }
251
+ }
252
+ }
@@ -0,0 +1,28 @@
1
+ import { type Json } from "./protocol.js";
2
+ /** The iOS simulators booted on this Mac, from `simctl`; none elsewhere. */
3
+ export declare function bootedSimulators(): Promise<Json[]>;
4
+ /** A PNG of one booted simulator's screen. */
5
+ export declare function simulatorScreenshot(udid: string): Promise<Buffer>;
6
+ /** What the phone may ask a simulator to do. Boot, shutdown, launch and
7
+ * URL go through simctl; touches and keys go through the Simulator app's
8
+ * window with UI scripting, which needs Accessibility for the Hook's node. */
9
+ export type SimulatorAction = {
10
+ action: "boot" | "shutdown" | "home" | "lock" | "screenshot-ready";
11
+ } | {
12
+ action: "launch";
13
+ bundleId: string;
14
+ } | {
15
+ action: "openurl";
16
+ url: string;
17
+ } | {
18
+ action: "tap";
19
+ x: number;
20
+ y: number;
21
+ } | {
22
+ action: "type";
23
+ text: string;
24
+ submit?: boolean;
25
+ };
26
+ export declare function simulatorAct(udid: string, request: SimulatorAction): Promise<Json>;
27
+ /** The apps a simulator has, for the launcher. */
28
+ export declare function simulatorApps(udid: string): Promise<Json[]>;
@@ -0,0 +1,198 @@
1
+ import { execFile } from "node:child_process";
2
+ import { chmod, mkdir, readFile, rename, stat, unlink, writeFile } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import path from "node:path";
5
+ import { createHash, randomUUID } from "node:crypto";
6
+ import { promisify } from "node:util";
7
+ import { BridgeError, bridgeRoot } from "./protocol.js";
8
+ const exec = promisify(execFile);
9
+ const UDID = /^[A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12}$/i;
10
+ /** The iOS simulators booted on this Mac, from `simctl`; none elsewhere. */
11
+ export async function bootedSimulators() {
12
+ if (process.platform !== "darwin")
13
+ return [];
14
+ const { stdout } = await exec("/usr/bin/xcrun", ["simctl", "list", "devices", "booted", "-j"], { timeout: 8_000, maxBuffer: 4_194_304 }).catch(() => ({ stdout: "{}" }));
15
+ let parsed = {};
16
+ try {
17
+ parsed = JSON.parse(stdout);
18
+ }
19
+ catch {
20
+ return [];
21
+ }
22
+ const list = [];
23
+ for (const [runtimeID, devices] of Object.entries(parsed.devices ?? {})) {
24
+ // com.apple.CoreSimulator.SimRuntime.iOS-26-1 → iOS 26.1
25
+ const runtime = runtimeID.replace(/^.*SimRuntime\./, "").replace(/-(\d+)-(\d+)$/, " $1.$2").replace(/-/g, " ");
26
+ for (const device of devices ?? []) {
27
+ if (device.state !== "Booted" || !device.udid || !UDID.test(device.udid))
28
+ continue;
29
+ list.push({ udid: device.udid.toUpperCase(), name: String(device.name ?? "Simulator").slice(0, 120), runtime });
30
+ if (list.length >= 16)
31
+ return list;
32
+ }
33
+ }
34
+ return list;
35
+ }
36
+ /** A PNG of one booted simulator's screen. */
37
+ export async function simulatorScreenshot(udid) {
38
+ if (!UDID.test(udid))
39
+ throw new BridgeError(400, "Invalid simulator identifier.");
40
+ if (process.platform !== "darwin")
41
+ throw new BridgeError(404, "Simulators run on macOS only.");
42
+ const file = path.join(tmpdir(), `phren-sim-${randomUUID()}.png`);
43
+ try {
44
+ await exec("/usr/bin/xcrun", ["simctl", "io", udid, "screenshot", "--type=png", file], { timeout: 15_000 });
45
+ return await readFile(file);
46
+ }
47
+ catch (error) {
48
+ if (error instanceof BridgeError)
49
+ throw error;
50
+ throw new BridgeError(409, "Couldn't capture that simulator. Is it still booted?");
51
+ }
52
+ finally {
53
+ await unlink(file).catch(() => undefined);
54
+ }
55
+ }
56
+ /** The native helper (native/simtap.swift) that finds the Simulator window
57
+ * through the Accessibility API and posts touches and keys with CGEvent.
58
+ * AppleScript would need Automation consent, which a launchd agent can never
59
+ * be prompted for; the helper needs one Accessibility grant, added by hand.
60
+ * Compiled once per Hook version with swiftc, which any Mac with the
61
+ * simulators has. */
62
+ let building;
63
+ function helper() {
64
+ building ??= buildHelper().finally(() => { building = undefined; });
65
+ return building;
66
+ }
67
+ async function buildHelper() {
68
+ const dir = path.join(bridgeRoot(), "native");
69
+ const binary = path.join(dir, "simtap");
70
+ const code = typeof SIMTAP_SOURCE === "string" ? SIMTAP_SOURCE : await readFile(new URL("./native/simtap.swift", import.meta.url), "utf8");
71
+ const digest = createHash("sha256").update(code).digest("hex");
72
+ // Rebuilt only when the source changes: the Accessibility grant is tied
73
+ // to this binary, and a needless rebuild would make macOS ask again.
74
+ const saved = await readFile(binary + ".sha256", "utf8").then(JSON.parse).catch(() => undefined);
75
+ if (await stat(binary).catch(() => undefined) && saved?.sourceSha === digest)
76
+ return binary;
77
+ await mkdir(dir, { recursive: true, mode: 0o700 });
78
+ const temporary = path.join(dir, `simtap.${randomUUID()}`), source = temporary + ".swift";
79
+ const sidecar = temporary + ".sha256";
80
+ try {
81
+ await writeFile(source, code, { mode: 0o600, flag: "wx" });
82
+ await exec("/usr/bin/swiftc", ["-O", "-o", temporary, source], { timeout: 180_000 }).catch(() => {
83
+ throw new BridgeError(409, "Couldn't build the simulator input helper (needs Xcode's swiftc).");
84
+ });
85
+ await chmod(temporary, 0o700);
86
+ const binarySha = createHash("sha256").update(await readFile(temporary)).digest("hex");
87
+ await writeFile(sidecar, JSON.stringify({ sourceSha: digest, binarySha }), { mode: 0o600, flag: "wx" });
88
+ await rename(temporary, binary);
89
+ await rename(sidecar, binary + ".sha256");
90
+ }
91
+ finally {
92
+ await Promise.all([source, temporary, sidecar].map(file => unlink(file).catch(() => undefined)));
93
+ }
94
+ return binary;
95
+ }
96
+ let inputQueue = Promise.resolve();
97
+ function simtap(name, ...args) {
98
+ const task = inputQueue.catch(() => { }).then(() => executeSimtap(name, ...args));
99
+ inputQueue = task;
100
+ return task;
101
+ }
102
+ async function executeSimtap(name, ...args) {
103
+ const binary = await helper();
104
+ const saved = await readFile(binary + ".sha256", "utf8").then(JSON.parse).catch(() => undefined);
105
+ const binarySha = createHash("sha256").update(await readFile(binary)).digest("hex");
106
+ if (!saved || saved.binarySha !== binarySha)
107
+ throw new BridgeError(409, "Simulator input helper integrity check failed.");
108
+ try {
109
+ await exec(binary, [name, ...args], { timeout: 60_000 });
110
+ }
111
+ catch (error) {
112
+ const failure = error;
113
+ const message = String(failure?.stderr ?? failure?.message ?? "");
114
+ if (/accessibility/.test(message))
115
+ throw new BridgeError(403, `Touches and keys need one permission on the Mac: System Settings → Privacy & Security → Accessibility → add ${binary}`);
116
+ if (/no window/.test(message))
117
+ throw new BridgeError(409, "That simulator has no window on screen.");
118
+ if (/not running/.test(message))
119
+ throw new BridgeError(409, "The Simulator app is not running.");
120
+ throw new BridgeError(409, `The simulator did not take that: ${message.slice(0, 160) || "unknown error"}`);
121
+ }
122
+ }
123
+ // macOS virtual key codes.
124
+ const KEY_H = "4", KEY_L = "37";
125
+ export async function simulatorAct(udid, request) {
126
+ if (!UDID.test(udid))
127
+ throw new BridgeError(400, "Invalid simulator identifier.");
128
+ if (!["boot", "shutdown", "launch", "openurl", "home", "lock", "type", "tap", "screenshot-ready"].includes(request.action))
129
+ throw new BridgeError(400, "Unknown simulator action.");
130
+ if (process.platform !== "darwin")
131
+ throw new BridgeError(404, "Simulators run on macOS only.");
132
+ const simctl = (...args) => exec("/usr/bin/xcrun", ["simctl", ...args], { timeout: 30_000 }).catch(() => { throw new BridgeError(409, `simctl ${args[0]} failed for that simulator.`); });
133
+ switch (request.action) {
134
+ case "boot":
135
+ await simctl("boot", udid);
136
+ break;
137
+ case "shutdown":
138
+ await simctl("shutdown", udid);
139
+ break;
140
+ case "launch":
141
+ if (typeof request.bundleId !== "string" || !/^[A-Za-z0-9][A-Za-z0-9.-]{2,199}$/.test(request.bundleId))
142
+ throw new BridgeError(400, "Invalid bundle identifier.");
143
+ await simctl("launch", udid, request.bundleId);
144
+ break;
145
+ case "openurl":
146
+ if (typeof request.url !== "string" || !/^[a-z][a-z0-9+.-]*:/i.test(request.url) || request.url.length > 2048)
147
+ throw new BridgeError(400, "Invalid URL.");
148
+ await simctl("openurl", udid, request.url);
149
+ break;
150
+ case "home":
151
+ await simtap(await deviceName(udid), "key", KEY_H, "cmd", "shift");
152
+ break;
153
+ case "lock":
154
+ await simtap(await deviceName(udid), "key", KEY_L, "cmd");
155
+ break;
156
+ case "type":
157
+ if (typeof request.text !== "string" || !request.text || request.text.length > 500
158
+ || /[\x00-\x09\x0b-\x1f\x7f]/.test(request.text) || (request.text.includes("\n") && request.submit !== true)
159
+ || (request.submit !== undefined && typeof request.submit !== "boolean"))
160
+ throw new BridgeError(400, "Type at most 500 characters; newlines require submit: true and other control characters are forbidden.");
161
+ await simtap(await deviceName(udid), "type", request.text, ...(request.submit === true ? ["submit"] : []));
162
+ break;
163
+ case "tap": {
164
+ // x and y are fractions of the screenshot.
165
+ const { x, y } = request;
166
+ if (![x, y].every(v => typeof v === "number" && v >= 0 && v <= 1))
167
+ throw new BridgeError(400, "Tap outside the screen.");
168
+ await simtap(await deviceName(udid), "tap", String(x), String(y));
169
+ break;
170
+ }
171
+ case "screenshot-ready": break;
172
+ default: throw new BridgeError(400, "Unknown simulator action.");
173
+ }
174
+ return { ok: true };
175
+ }
176
+ async function deviceName(udid) {
177
+ const device = (await bootedSimulators()).find(d => d.udid === udid.toUpperCase());
178
+ if (!device)
179
+ throw new BridgeError(409, "That simulator is not booted.");
180
+ return String(device.name);
181
+ }
182
+ /** The apps a simulator has, for the launcher. */
183
+ export async function simulatorApps(udid) {
184
+ if (!UDID.test(udid))
185
+ throw new BridgeError(400, "Invalid simulator identifier.");
186
+ if (process.platform !== "darwin")
187
+ return [];
188
+ const { stdout } = await exec("/usr/bin/xcrun", ["simctl", "listapps", udid], { timeout: 15_000, maxBuffer: 4_194_304 }).catch(() => ({ stdout: "" }));
189
+ const apps = [];
190
+ const blocks = stdout.split(/\n(?=\s{4}"[^"]+" =\s+\{)/);
191
+ for (const block of blocks) {
192
+ const id = /CFBundleIdentifier = "?([^";\n]+)"?;/.exec(block)?.[1], name = /CFBundleDisplayName = "?([^";\n]+)"?;/.exec(block)?.[1];
193
+ const type = /ApplicationType = "?([^";\n]+)"?;/.exec(block)?.[1];
194
+ if (id && name && type === "User" && !/\.xctrunner$/.test(id))
195
+ apps.push({ bundleId: id, name });
196
+ }
197
+ return apps.sort((a, b) => String(a.name).localeCompare(String(b.name))).slice(0, 100);
198
+ }
@@ -0,0 +1,24 @@
1
+ /** Dictation through ElevenLabs Scribe v2 Realtime, for the phone's opt-in
2
+ * Scribe input. The phone streams 16 kHz mono PCM as binary frames; this
3
+ * computer forwards it to ElevenLabs with its own key, which never leaves
4
+ * here, and sends back `{type: "partial"|"committed", text}` frames. Errors
5
+ * are fixed messages by code: ElevenLabs' own text is never passed on. */
6
+ export declare const TRANSCRIBE_MODEL = "scribe_v2_realtime";
7
+ export declare const TRANSCRIBE_RATE = 16000;
8
+ /** The two sockets as the relay uses them, so tests can stand in for both. */
9
+ export interface RelaySocket {
10
+ readonly readyState: number;
11
+ send(data: string): void;
12
+ close(code?: number, reason?: string): void;
13
+ on(event: "message", listener: (data: Buffer, isBinary: boolean) => void): unknown;
14
+ on(event: "open" | "close", listener: () => void): unknown;
15
+ on(event: "error", listener: (error: Error) => void): unknown;
16
+ }
17
+ export interface TranscribeOptions {
18
+ key?: () => Promise<string | undefined>;
19
+ connect?: (url: string, key: string) => RelaySocket;
20
+ maxSessionMs?: number;
21
+ }
22
+ /** The upstream URL: VAD commits, the phone's language and its vocabulary as keyterms. */
23
+ export declare function transcribeURL(query: URLSearchParams): string;
24
+ export declare function relayTranscription(client: RelaySocket, query: URLSearchParams, options?: TranscribeOptions): Promise<void>;