@phren/cli 0.2.14 → 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 (387) 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.d.ts +2 -0
  235. package/dist/init/init-walkthrough.js +17 -6
  236. package/dist/init/init.js +26 -6
  237. package/dist/init/management-preset.d.ts +1 -1
  238. package/dist/init/management-preset.js +2 -2
  239. package/dist/init/preferences.js +1 -1
  240. package/dist/init/self-wiring.js +1 -1
  241. package/dist/init/setup.d.ts +3 -26
  242. package/dist/init/setup.js +49 -588
  243. package/dist/init/shared.js +2 -0
  244. package/dist/init/store-gitignore.d.ts +1 -1
  245. package/dist/init/store-gitignore.js +2 -0
  246. package/dist/init/teardown.d.ts +1 -1
  247. package/dist/init/teardown.js +2 -2
  248. package/dist/link/context.js +1 -1
  249. package/dist/link/doctor.d.ts +22 -1
  250. package/dist/link/doctor.js +100 -54
  251. package/dist/link/link.js +29 -61
  252. package/dist/link/refresh.js +2 -2
  253. package/dist/link/skills.js +26 -5
  254. package/dist/machine-identity.d.ts +3 -0
  255. package/dist/machine-identity.js +6 -0
  256. package/dist/mcp/profile.d.ts +2 -15
  257. package/dist/mcp/profile.js +64 -9
  258. package/dist/memory-ui-graph.runtime.js +279 -283
  259. package/dist/modules/code-package.d.ts +16 -0
  260. package/dist/modules/code-package.js +152 -0
  261. package/dist/modules/command.d.ts +2 -0
  262. package/dist/modules/command.js +67 -0
  263. package/dist/modules/config.d.ts +4 -0
  264. package/dist/modules/config.js +70 -0
  265. package/dist/modules/manifest.d.ts +41 -0
  266. package/dist/modules/manifest.js +1 -0
  267. package/dist/modules/provision.d.ts +3 -0
  268. package/dist/modules/provision.js +84 -0
  269. package/dist/modules/registry.d.ts +16 -0
  270. package/dist/modules/registry.js +250 -0
  271. package/dist/modules/runtime.d.ts +15 -0
  272. package/dist/modules/runtime.js +59 -0
  273. package/dist/package-metadata.js +10 -2
  274. package/dist/phren-dotenv.js +4 -2
  275. package/dist/phren-paths.d.ts +3 -2
  276. package/dist/phren-paths.js +4 -5
  277. package/dist/profile-store.js +4 -5
  278. package/dist/project-config.d.ts +19 -1
  279. package/dist/project-config.js +29 -3
  280. package/dist/project-topics.js +4 -4
  281. package/dist/provider-adapters.js +1 -4
  282. package/dist/query-correlation.js +6 -6
  283. package/dist/session/artifacts.js +5 -5
  284. package/dist/session/checkpoints.js +5 -0
  285. package/dist/session/utils.d.ts +2 -2
  286. package/dist/session/utils.js +6 -6
  287. package/dist/shared/content.d.ts +1 -1
  288. package/dist/shared/content.js +1 -1
  289. package/dist/shared/data-utils.js +1 -1
  290. package/dist/shared/fragment-graph.d.ts +1 -1
  291. package/dist/shared/fragment-graph.js +5 -5
  292. package/dist/shared/index.js +48 -7
  293. package/dist/shared/retrieval.d.ts +18 -1
  294. package/dist/shared/retrieval.js +100 -11
  295. package/dist/shared/search-fallback.js +4 -6
  296. package/dist/shared/sqljs.d.ts +2 -0
  297. package/dist/shared/sqljs.js +4 -2
  298. package/dist/shared.d.ts +0 -1
  299. package/dist/shared.js +0 -1
  300. package/dist/shell/input.d.ts +1 -5
  301. package/dist/shell/input.js +16 -10
  302. package/dist/shell/palette.d.ts +2 -2
  303. package/dist/shell/palette.js +3 -7
  304. package/dist/shell/render.d.ts +3 -1
  305. package/dist/shell/render.js +4 -4
  306. package/dist/shell/shell.js +4 -1
  307. package/dist/shell/types.d.ts +1 -0
  308. package/dist/shell/types.js +4 -0
  309. package/dist/shell/view.d.ts +0 -4
  310. package/dist/shell/view.js +19 -27
  311. package/dist/skill/registry.js +25 -17
  312. package/dist/skill/state.d.ts +3 -0
  313. package/dist/skill/state.js +13 -7
  314. package/dist/status.js +38 -17
  315. package/dist/store-registry.d.ts +44 -18
  316. package/dist/store-registry.js +169 -60
  317. package/dist/store-weight.d.ts +1 -6
  318. package/dist/store-weight.js +4 -2
  319. package/dist/sync/auth-doctor.d.ts +8 -0
  320. package/dist/sync/auth-doctor.js +27 -0
  321. package/dist/sync/auth.d.ts +27 -0
  322. package/dist/sync/auth.js +114 -0
  323. package/dist/sync/conflict-resolve.d.ts +9 -0
  324. package/dist/sync/conflict-resolve.js +146 -0
  325. package/dist/sync/git-state.d.ts +4 -0
  326. package/dist/sync/git-state.js +49 -0
  327. package/dist/sync/outcome.d.ts +34 -0
  328. package/dist/sync/outcome.js +57 -0
  329. package/dist/sync/pull.d.ts +15 -7
  330. package/dist/sync/pull.js +84 -35
  331. package/dist/sync/store-merge.d.ts +29 -0
  332. package/dist/sync/store-merge.js +137 -0
  333. package/dist/sync/task-merge.d.ts +22 -0
  334. package/dist/sync/task-merge.js +158 -0
  335. package/dist/task/github.js +1 -1
  336. package/dist/task/lifecycle.d.ts +5 -0
  337. package/dist/task/lifecycle.js +67 -23
  338. package/dist/terminal-text.d.ts +5 -0
  339. package/dist/terminal-text.js +11 -0
  340. package/dist/test-global-setup.js +7 -0
  341. package/dist/tool-registry.d.ts +1 -1
  342. package/dist/tool-registry.js +3 -1
  343. package/dist/tools/code.d.ts +3 -0
  344. package/dist/tools/code.js +178 -0
  345. package/dist/tools/config.js +5 -0
  346. package/dist/tools/data.js +14 -7
  347. package/dist/tools/dispatch.d.ts +2 -0
  348. package/dist/tools/dispatch.js +66 -0
  349. package/dist/tools/finding.js +43 -41
  350. package/dist/tools/ops.js +5 -2
  351. package/dist/tools/search.js +21 -8
  352. package/dist/tools/session.js +21 -22
  353. package/dist/tools/tasks.js +8 -2
  354. package/dist/tools/types.d.ts +2 -2
  355. package/dist/tools/types.js +2 -2
  356. package/dist/ui/assets.js +1 -1
  357. package/dist/ui/data.js +14 -15
  358. package/dist/ui/deep-void.d.ts +1 -1
  359. package/dist/ui/deep-void.js +0 -1
  360. package/dist/ui/graph-chrome.d.ts +1 -1
  361. package/dist/ui/graph-chrome.js +51 -0
  362. package/dist/ui/page.js +5 -5
  363. package/dist/ui/scripts.js +67 -30
  364. package/dist/ui/server.js +34 -6
  365. package/dist/update.js +1 -1
  366. package/dist/utils-fts.js +1 -0
  367. package/dist/utils-helpers.d.ts +7 -0
  368. package/dist/utils-helpers.js +17 -0
  369. package/dist/utils.d.ts +1 -1
  370. package/dist/utils.js +1 -1
  371. package/package.json +45 -3
  372. package/plugins/opencode/phren-transcript.js +340 -0
  373. package/starter/README.md +4 -4
  374. package/starter/global/{CLAUDE.md → AGENTS.md} +2 -2
  375. package/starter/global/skills/conductor/SKILL.md +106 -0
  376. package/starter/global/skills/fanout/SKILL.md +20 -0
  377. package/starter/global/skills/phren-discover/SKILL.md +6 -6
  378. package/starter/global/skills/phren-init/SKILL.md +4 -4
  379. package/starter/global/skills/phren-sync/SKILL.md +3 -3
  380. package/starter/templates/frontend/reference/README.md +1 -1
  381. package/starter/templates/library/reference/README.md +1 -1
  382. package/starter/templates/monorepo/reference/README.md +1 -1
  383. package/starter/templates/python-project/reference/README.md +1 -1
  384. /package/starter/templates/frontend/{CLAUDE.md → AGENTS.md} +0 -0
  385. /package/starter/templates/library/{CLAUDE.md → AGENTS.md} +0 -0
  386. /package/starter/templates/monorepo/{CLAUDE.md → AGENTS.md} +0 -0
  387. /package/starter/templates/python-project/{CLAUDE.md → AGENTS.md} +0 -0
@@ -0,0 +1,442 @@
1
+ import { createHash } from "node:crypto";
2
+ import { mkdir, open, readFile, stat } from "node:fs/promises";
3
+ import { codexHome } from "../home-paths.js";
4
+ import path from "node:path";
5
+ import { atomic, bridgeRoot, object, objects, sessionId } from "./protocol.js";
6
+ /** Codex 0.155 keeps a thread's history in `thread_history_1.sqlite` and no
7
+ * longer writes the rollout file its `state_5.sqlite` still names. The Hook
8
+ * materializes such a thread into a rollout-shaped JSONL of its own, append
9
+ * only, so every reader of Codex transcripts keeps working unchanged. */
10
+ const MAX_ITEMS = 20_000, OUTPUT_TAIL = 4_000;
11
+ const STALLED_AFTER_MS = 10 * 60 * 1_000;
12
+ export function materializedRoot() { return path.join(bridgeRoot(), "codex-threads"); }
13
+ export function materializedPath(session) { return path.join(materializedRoot(), `${session}.jsonl`); }
14
+ async function openReadOnly(file) {
15
+ try {
16
+ await stat(file);
17
+ const sqlite = await import("node:sqlite");
18
+ return new sqlite.DatabaseSync(file, { readOnly: true });
19
+ }
20
+ catch {
21
+ return undefined;
22
+ }
23
+ }
24
+ /** A working pane whose projection cursor stopped at an unfinished turn can
25
+ * keep accepting input even though none of it will be readable again. */
26
+ export async function threadHealth(session, agentStatus) {
27
+ if (!sessionId.safeParse(session).success || !["working", "blocked", "waiting"].includes(String(agentStatus)))
28
+ return { stalled: false };
29
+ const stateFile = materializedPath(session) + ".state.json";
30
+ let cursor, cursorMtime;
31
+ try {
32
+ cursor = { lastOrdinal: -1, maxUpdated: -1, count: 0, done: {}, ...object(JSON.parse(await readFile(stateFile, "utf8"))) };
33
+ cursorMtime = (await stat(stateFile)).mtimeMs;
34
+ }
35
+ catch {
36
+ return { stalled: false };
37
+ }
38
+ if (Date.now() - cursorMtime < STALLED_AFTER_MS)
39
+ return { stalled: false };
40
+ const history = await openReadOnly(path.join(codexHome(), "thread_history_1.sqlite"));
41
+ if (!history)
42
+ return { stalled: false };
43
+ try {
44
+ const summary = object(history.prepare("select count(*) as n, max(rollout_ordinal) as last, max(updated_at_ordinal) as updated from thread_items where thread_id = ?").get(session));
45
+ // The store may have advanced just before the materializer catches up.
46
+ if (cursor.count !== Number(summary.n) || cursor.lastOrdinal !== Number(summary.last) || cursor.maxUpdated !== Number(summary.updated))
47
+ return { stalled: false };
48
+ const turn = object(history.prepare("select status, rollout_end_ordinal from thread_turns where thread_id = ? order by rollout_ordinal desc limit 1").get(session));
49
+ if (turn.status !== "inProgress" || turn.rollout_end_ordinal !== null)
50
+ return { stalled: false };
51
+ return { stalled: true, since: new Date(cursorMtime).toISOString() };
52
+ }
53
+ catch {
54
+ return { stalled: false };
55
+ }
56
+ finally {
57
+ history.close();
58
+ }
59
+ }
60
+ const materializations = new Map();
61
+ /** The thread store accumulates agent-message deltas in place. Only text
62
+ * from the newest unfinished message is public; reasoning is never read out. */
63
+ function pendingMessage(history, session) {
64
+ const turn = object(history.prepare("select turn_id, status, started_at from thread_turns where thread_id = ? order by rollout_ordinal desc limit 1").get(session));
65
+ if (turn.status !== "inProgress")
66
+ return undefined;
67
+ // Queued steering can be appended while the current reply is still growing.
68
+ // It does not finish that reply or make its partial text safe to persist.
69
+ const row = object(history.prepare(`select item_json from thread_items where thread_id = ? and turn_id = ?
70
+ and not (item_type = 'userMessage' and case when json_valid(item_json)
71
+ then coalesce(json_extract(item_json, '$.status'), '') else '' end = 'queued')
72
+ order by rollout_ordinal desc limit 1`).get(session, turn.turn_id));
73
+ let item;
74
+ try {
75
+ item = object(JSON.parse(String(row.item_json)));
76
+ }
77
+ catch {
78
+ return undefined;
79
+ }
80
+ if (item.type !== "agentMessage" || finished(item) || item.delivery === "async")
81
+ return undefined;
82
+ const started = Number(turn.started_at);
83
+ if (!Number.isFinite(started) || started <= 0)
84
+ return undefined;
85
+ return { id: String(item.id), turnStartedAt: new Date(started > 1e12 ? started : started * 1000).toISOString(),
86
+ text: typeof item.text === "string" ? item.text.slice(0, 32_768) : "" };
87
+ }
88
+ export async function codexThreadPreview(session) {
89
+ if (!sessionId.safeParse(session).success)
90
+ return undefined;
91
+ const history = await openReadOnly(path.join(codexHome(), "thread_history_1.sqlite"));
92
+ if (!history)
93
+ return undefined;
94
+ try {
95
+ const pending = pendingMessage(history, session);
96
+ return pending?.text ? { turnStartedAt: pending.turnStartedAt, text: pending.text } : undefined;
97
+ }
98
+ catch {
99
+ return undefined;
100
+ }
101
+ finally {
102
+ history.close();
103
+ }
104
+ }
105
+ /** Bring the materialized file up to date with the store. Returns the file
106
+ * when the thread exists there, undefined otherwise. Safe to call often:
107
+ * an unchanged thread costs one aggregate query. */
108
+ export async function materializeCodexThread(session) {
109
+ if (!sessionId.safeParse(session).success)
110
+ return undefined;
111
+ const key = materializedPath(session);
112
+ const pending = materializations.get(key);
113
+ if (pending)
114
+ return pending;
115
+ const work = materializeThread(session);
116
+ materializations.set(key, work);
117
+ try {
118
+ return await work;
119
+ }
120
+ finally {
121
+ materializations.delete(key);
122
+ }
123
+ }
124
+ async function materializeThread(session) {
125
+ if (!sessionId.safeParse(session).success)
126
+ return undefined;
127
+ const history = await openReadOnly(path.join(codexHome(), "thread_history_1.sqlite"));
128
+ if (!history)
129
+ return undefined;
130
+ try {
131
+ const summary = object(history.prepare("select count(*) as n, max(rollout_ordinal) as last, max(updated_at_ordinal) as updated from thread_items where thread_id = ?").get(session));
132
+ if (!Number(summary.n))
133
+ return undefined;
134
+ const file = materializedPath(session), stateFile = file + ".state.json";
135
+ await mkdir(materializedRoot(), { recursive: true, mode: 0o700 });
136
+ let state = { lastOrdinal: -1, maxUpdated: -1, count: 0, done: {} };
137
+ try {
138
+ state = { ...state, ...object(JSON.parse(await readFile(stateFile, "utf8"))) };
139
+ }
140
+ catch { /* first time */ }
141
+ const fresh = state.count === 0;
142
+ const turn = object(history.prepare("select turn_id, status from thread_turns where thread_id = ? order by rollout_ordinal desc limit 1").get(session));
143
+ const turnSignature = JSON.stringify(turn);
144
+ if (!fresh && state.count === Number(summary.n) && state.lastOrdinal === Number(summary.last) && state.maxUpdated === Number(summary.updated)
145
+ && state.turnSignature === turnSignature)
146
+ return file;
147
+ const pending = pendingMessage(history, session);
148
+ const rows = objects(history.prepare("select rollout_ordinal, item_type, item_json, updated_at_ordinal from thread_items where thread_id = ? order by rollout_ordinal limit ?").all(session, MAX_ITEMS));
149
+ const lines = [];
150
+ if (fresh) {
151
+ const meta = await threadMeta(session);
152
+ // A child thread's row names its parent inside `source`; the child
153
+ // agent tree verifies that link from the first line, so it rides along.
154
+ lines.push(JSON.stringify({ type: "session_meta", payload: { id: session, ...(meta.cwd ? { cwd: meta.cwd } : {}),
155
+ source: meta.spawn ? { subagent: { thread_spawn: meta.spawn } } : "codex-thread-store" } }));
156
+ if (meta.model)
157
+ lines.push(JSON.stringify({ type: "turn_context", payload: { model: meta.model } }));
158
+ }
159
+ for (const row of rows) {
160
+ let item;
161
+ try {
162
+ item = object(JSON.parse(String(row.item_json)));
163
+ }
164
+ catch {
165
+ continue;
166
+ }
167
+ const id = String(item.id ?? `ordinal-${row.rollout_ordinal}`), emitted = state.done[id];
168
+ if (item.type === "agentMessage" && id === pending?.id)
169
+ continue;
170
+ const calls = callRows(item), output = outputRow(item);
171
+ // Preserve only queue state actually recorded by the harness. The
172
+ // append-only transcript pairs the queued user row with a content-free
173
+ // consumption marker when that same item leaves the queue.
174
+ if (emitted === "queued" && item.type === "userMessage" && item.status !== "queued") {
175
+ lines.push(JSON.stringify({ type: "phren_queue_consumed", key: queueKey(session, id) }));
176
+ state.done[id] = "done";
177
+ continue;
178
+ }
179
+ if (!emitted) {
180
+ if (calls) {
181
+ for (const call of calls)
182
+ lines.push(JSON.stringify(call));
183
+ state.done[id] = "call";
184
+ }
185
+ else if (subAgentRow(item)) {
186
+ // A child Codex agent (spawn, interaction, completion) rides along
187
+ // as the event the rollout carried before 0.155, so the child
188
+ // agent tree keeps finding native subagents.
189
+ lines.push(JSON.stringify(subAgentRow(item)));
190
+ state.done[id] = "done";
191
+ continue;
192
+ }
193
+ else if (messageRow(item)) {
194
+ const message = messageRow(item);
195
+ const queued = item.type === "userMessage" && item.status === "queued";
196
+ lines.push(JSON.stringify(queued ? { ...message, phrenQueued: true, phrenQueueKey: queueKey(session, id) } : message));
197
+ // A question the agent asked (delivered async) rides along as the
198
+ // same event the rollout would carry, so the pending scan sees it.
199
+ const asked = questionEvent(item);
200
+ if (asked)
201
+ lines.push(JSON.stringify(asked));
202
+ state.done[id] = queued ? "queued" : "done";
203
+ continue;
204
+ }
205
+ else if (isQueuedQuestionItem(item)) {
206
+ // The queued follow-up question reads in the transcript as the
207
+ // asking sentence; the Hook answers it from the store, not by
208
+ // quoting a reply, so no async event rides along here.
209
+ const title = questionTitle(objects(item.questions));
210
+ if (title)
211
+ lines.push(JSON.stringify({ type: "response_item", payload: { type: "message", role: "assistant", content: [{ type: "output_text", text: title }] } }));
212
+ state.done[id] = "done";
213
+ continue;
214
+ }
215
+ else
216
+ continue;
217
+ }
218
+ if (state.done[id] === "call" && output) {
219
+ lines.push(JSON.stringify(output));
220
+ state.done[id] = "done";
221
+ }
222
+ }
223
+ if (lines.length) {
224
+ const handle = await open(file, "a", 0o600);
225
+ try {
226
+ await handle.appendFile(lines.join("\n") + "\n");
227
+ }
228
+ finally {
229
+ await handle.close();
230
+ }
231
+ }
232
+ state.count = Number(summary.n);
233
+ state.lastOrdinal = Number(summary.last);
234
+ state.maxUpdated = Number(summary.updated);
235
+ state.turnSignature = turnSignature;
236
+ await atomic(stateFile, JSON.stringify(state));
237
+ return file;
238
+ }
239
+ catch {
240
+ return undefined;
241
+ }
242
+ finally {
243
+ history.close();
244
+ }
245
+ }
246
+ /** Codex 0.155 stores a child agent's lifecycle as `subAgentActivity` items
247
+ * with camelCase fields; the rollout shape the child tree parses is the
248
+ * `SubAgentActivity` event with snake_case fields. */
249
+ function subAgentRow(item) {
250
+ if (item.type !== "subAgentActivity")
251
+ return undefined;
252
+ const kind = String(item.kind ?? ""), child = String(item.agentThreadId ?? item.agent_thread_id ?? "");
253
+ if (!child)
254
+ return undefined;
255
+ return { type: "event_msg", payload: { type: "item_completed", item: {
256
+ type: "SubAgentActivity", id: String(item.id ?? ""), kind,
257
+ agent_thread_id: child, agent_path: String(item.agentPath ?? item.agent_path ?? ""),
258
+ } } };
259
+ }
260
+ async function threadMeta(session) {
261
+ const db = await openReadOnly(path.join(codexHome(), "state_5.sqlite"));
262
+ if (!db)
263
+ return {};
264
+ try {
265
+ const row = object(db.prepare("select model, cwd from threads where id = ?").get(session));
266
+ let spawn;
267
+ try {
268
+ // Older stores have no `source` column; a child thread's names its parent there.
269
+ const source = object(db.prepare("select source from threads where id = ?").get(session)).source;
270
+ if (typeof source === "string" && source.startsWith("{")) {
271
+ const parsed = object(object(JSON.parse(source)).subagent).thread_spawn;
272
+ if (parsed && typeof parsed === "object" && Object.keys(parsed).length)
273
+ spawn = parsed;
274
+ }
275
+ }
276
+ catch { /* no source column or plain text */ }
277
+ return { ...(typeof row.model === "string" && row.model ? { model: row.model } : {}), ...(typeof row.cwd === "string" && row.cwd ? { cwd: row.cwd } : {}), ...(spawn ? { spawn } : {}) };
278
+ }
279
+ catch {
280
+ return {};
281
+ }
282
+ finally {
283
+ db.close();
284
+ }
285
+ }
286
+ function finished(item) { return ["completed", "failed", "declined", "error"].includes(String(item.status)) || item.exitCode !== undefined && item.exitCode !== null; }
287
+ function queueKey(session, id) {
288
+ return createHash("sha256").update(`${session}\0${id}`).digest("hex");
289
+ }
290
+ /** A message row, for the two message kinds. */
291
+ function messageRow(item) {
292
+ if (item.type === "userMessage") {
293
+ const text = objects(item.content).filter(b => b.type === "text" && typeof b.text === "string").map(b => String(b.text)).join("\n");
294
+ return text ? { type: "response_item", payload: { type: "message", role: "user", content: [{ type: "input_text", text }] } } : undefined;
295
+ }
296
+ if (item.type === "agentMessage" && typeof item.text === "string" && item.text) {
297
+ return { type: "response_item", payload: { type: "message", role: "assistant", content: [{ type: "output_text", text: item.text }] } };
298
+ }
299
+ return undefined;
300
+ }
301
+ /** Codex 0.155 asks through an agent message with `questions` attached. */
302
+ function questionEvent(item) {
303
+ if (item.type !== "agentMessage" || item.delivery !== "async" || !Array.isArray(item.questions) || !item.questions.length)
304
+ return undefined;
305
+ return { type: "event_msg", payload: { type: "item_completed", item: { type: "AgentMessage", id: String(item.id ?? ""),
306
+ content: [{ type: "Text", text: String(item.text ?? "") }], delivery: "async", questions: objects(item.questions).slice(0, 8) } } };
307
+ }
308
+ /** Codex 0.155 records a queued follow-up question as its own thread item
309
+ * (`question` or `requestUserInput`), not as a delivered async agent message.
310
+ * It sits under the terminal's "Queued follow-up inputs" until alt+up opens
311
+ * it, so the Hook reads its text and options straight from the store. */
312
+ const QUEUED_QUESTION_TYPES = new Set(["question", "requestUserInput"]);
313
+ function isQueuedQuestionItem(item) { return QUEUED_QUESTION_TYPES.has(String(item.type)); }
314
+ function questionAnswered(item) {
315
+ if (item.answers !== undefined && item.answers !== null)
316
+ return true;
317
+ return ["answered", "completed", "resolved", "cancelled", "canceled", "error", "declined"].includes(String(item.status ?? ""));
318
+ }
319
+ function questionTitle(questions) {
320
+ return questions.map(raw => {
321
+ const q = object(raw);
322
+ const text = [q.question, q.title].find(v => typeof v === "string" && v.trim());
323
+ return typeof text === "string" ? text.trim() : "";
324
+ }).filter(Boolean).join("\n\n").slice(0, 4_000);
325
+ }
326
+ function questionOptionLabels(questions) {
327
+ const first = object(questions[0]);
328
+ const raw = first.options;
329
+ if (!Array.isArray(raw))
330
+ return [];
331
+ return raw.map(option => {
332
+ if (typeof option === "string")
333
+ return option.trim();
334
+ const label = object(option).label;
335
+ return typeof label === "string" ? label.trim() : "";
336
+ }).filter(Boolean).slice(0, 12);
337
+ }
338
+ /** The pending queued question as the pane's choice shape: the asking
339
+ * sentence and one numbered option per choice (Codex answers with number
340
+ * keys once alt+up has opened the queue). Undefined when nothing answerable
341
+ * remains. */
342
+ export async function queuedQuestion(session) {
343
+ if (!sessionId.safeParse(session).success)
344
+ return undefined;
345
+ const db = await openReadOnly(path.join(codexHome(), "thread_history_1.sqlite"));
346
+ if (!db)
347
+ return undefined;
348
+ try {
349
+ const rows = objects(db.prepare("select item_json from thread_items where thread_id = ? and item_type in ('question', 'requestUserInput') order by rollout_ordinal desc limit 32").all(session));
350
+ for (const row of rows) {
351
+ let item;
352
+ try {
353
+ item = object(JSON.parse(String(row.item_json)));
354
+ }
355
+ catch {
356
+ continue;
357
+ }
358
+ if (questionAnswered(item))
359
+ continue;
360
+ const questions = objects(item.questions);
361
+ const title = questionTitle(questions);
362
+ if (!title)
363
+ continue;
364
+ const labels = questionOptionLabels(questions);
365
+ return { title, options: labels.map((label, index) => ({ label, key: String(index + 1) })) };
366
+ }
367
+ return undefined;
368
+ }
369
+ catch {
370
+ return undefined;
371
+ }
372
+ finally {
373
+ db.close();
374
+ }
375
+ }
376
+ /** Codex 0.155 code mode stores a generic tool call whose input is JavaScript;
377
+ * whichever key holds it, the Hook projects the source in the rollout reader. */
378
+ function codeModeInput(item) {
379
+ for (const key of ["input", "code", "script"]) {
380
+ const value = item[key];
381
+ if (typeof value === "string")
382
+ return value;
383
+ if (value && typeof value === "object" && ["code", "source", "script"].some(k => typeof object(value)[k] === "string"))
384
+ return value;
385
+ }
386
+ return undefined;
387
+ }
388
+ /** The call row(s) an item starts with; tool inputs, not reasoning. */
389
+ function callRows(item) {
390
+ const id = String(item.id ?? "");
391
+ switch (item.type) {
392
+ case "commandExecution":
393
+ return [{ type: "response_item", payload: { type: "function_call", name: "shell", call_id: id, arguments: JSON.stringify({ command: String(item.command ?? "").slice(0, 4000), ...(typeof item.cwd === "string" ? { workdir: item.cwd } : {}) }) } }];
394
+ case "fileChange":
395
+ return [{ type: "response_item", payload: { type: "function_call", name: "apply_patch", call_id: id, arguments: JSON.stringify({ files: objects(item.changes).slice(0, 50).map(c => ({ path: String(c.path ?? ""), kind: String(object(c.kind).type ?? c.kind ?? "") })) }) } }];
396
+ case "mcpToolCall":
397
+ return [{ type: "response_item", payload: { type: "function_call", name: `mcp__${String(item.server ?? "mcp")}__${String(item.tool ?? "tool")}`, call_id: id, arguments: JSON.stringify(object(item.arguments)) } }];
398
+ case "webSearch":
399
+ return [{ type: "response_item", payload: { type: "function_call", name: "web_search", call_id: id, arguments: JSON.stringify({ query: String(item.query ?? "").slice(0, 2000) }) } }];
400
+ default: {
401
+ const input = codeModeInput(item);
402
+ if (input === undefined)
403
+ return undefined;
404
+ return [{ type: "response_item", payload: { type: "custom_tool_call", name: String(item.name ?? item.tool ?? "exec"), call_id: id, input } }];
405
+ }
406
+ }
407
+ }
408
+ /** The output row once the item finished. */
409
+ function outputRow(item) {
410
+ if (!finished(item))
411
+ return undefined;
412
+ const id = String(item.id ?? "");
413
+ switch (item.type) {
414
+ case "commandExecution": {
415
+ const text = typeof item.aggregatedOutput === "string" ? item.aggregatedOutput.slice(-OUTPUT_TAIL) : "";
416
+ const status = typeof item.exitCode === "number" ? `[exit ${item.exitCode}]` : `[${String(item.status)}]`;
417
+ return { type: "response_item", payload: { type: "function_call_output", call_id: id, output: `${text}${text && !text.endsWith("\n") ? "\n" : ""}${status}` } };
418
+ }
419
+ case "fileChange": {
420
+ const changes = objects(item.changes).slice(0, 50);
421
+ const kind = (c) => { const t = String(object(c.kind).type ?? c.kind ?? "update"); return t === "add" ? "A" : t === "delete" ? "D" : "M"; };
422
+ const files = changes.map(c => ({ path: String(c.path ?? ""), status: kind(c), ...(typeof c.diff === "string" ? { patch: c.diff.slice(0, 200_000) } : {}) }));
423
+ const output = changes.length ? `${changes.length} file(s) changed\n${files.map(f => f.path).join("\n")}` : "0 file(s) changed";
424
+ return { type: "response_item", payload: { type: "function_call_output", call_id: id, output }, ...(files.length ? { phren_changes: { [id]: files } } : {}) };
425
+ }
426
+ case "mcpToolCall": {
427
+ const parts = objects(object(item.result).content).filter(b => b.type === "text" && typeof b.text === "string").map(b => String(b.text));
428
+ const output = parts.length ? parts.join("\n").slice(-OUTPUT_TAIL) : typeof item.error === "string" ? item.error.slice(0, 2000) : String(item.status);
429
+ return { type: "response_item", payload: { type: "function_call_output", call_id: id, output } };
430
+ }
431
+ case "webSearch": {
432
+ const results = objects(item.results).slice(0, 10).map(r => [r.title, r.snippet].filter(v => typeof v === "string" && v).join(": ")).join("\n");
433
+ return { type: "response_item", payload: { type: "function_call_output", call_id: id, output: results || "searched" } };
434
+ }
435
+ default: {
436
+ if (codeModeInput(item) === undefined)
437
+ return undefined;
438
+ const text = [item.aggregatedOutput, item.output, item.result].find(v => typeof v === "string" && v);
439
+ return { type: "response_item", payload: { type: "custom_tool_call_output", call_id: id, output: (text ?? String(item.status ?? "completed")).slice(-OUTPUT_TAIL) } };
440
+ }
441
+ }
442
+ }
@@ -1 +1,8 @@
1
+ import { type Json } from "./protocol.js";
1
2
  export declare function runBridge(args: string[], version: string): Promise<number>;
3
+ /** Doctor's push check, from the running Hook's own capability: only a Hook
4
+ * that loaded apns.json and its key offers `approvalPush`. */
5
+ export declare function approvalPushCheck(helper: Json): {
6
+ configured: boolean;
7
+ warning?: string;
8
+ };
@@ -1,11 +1,44 @@
1
+ import { readFile } from "node:fs/promises";
1
2
  import { serve } from "./server.js";
2
3
  import { dispatch, health } from "./transport.js";
3
4
  import { install, rollback, uninstall } from "./install.js";
4
5
  import { servers } from "./herdr.js";
5
6
  import { agentHook } from "./agent-hooks.js";
6
- import { provider } from "./protocol.js";
7
+ import { object, provider } from "./protocol.js";
8
+ import { apnsSetupSteps } from "./push.js";
9
+ import { AccountUsageReader, captureClaudeUsage } from "./usage.js";
10
+ import { acceptComputer, enrollComputer } from "./computers.js";
11
+ import { ARCHIVE_MAX_FOLDERS, archiveFinishedFanouts, FANOUTS_ARCHIVE_USAGE, parseFanoutArchiveFlags } from "./fanouts.js";
7
12
  export async function runBridge(args, version) {
8
13
  switch (args[0]) {
14
+ case "enroll-computer": {
15
+ if (args.length === 2)
16
+ console.log(await enrollComputer(args[1]));
17
+ else if (args.length === 4 && args[2] === "--accept") {
18
+ await acceptComputer(args[1], await readFile(args[3], "utf8"));
19
+ console.log(`Enrolled ${args[1]} for Phren Hook.`);
20
+ }
21
+ else
22
+ throw new Error("Usage: phren bridge enroll-computer <name> [--accept <public-key-file>]");
23
+ break;
24
+ }
25
+ case "fanouts": {
26
+ if (args[1] !== "archive")
27
+ throw new Error(FANOUTS_ARCHIVE_USAGE);
28
+ const options = parseFanoutArchiveFlags(args.slice(2));
29
+ const dryRun = options.dryRun ?? false;
30
+ const { moved, deleted } = await archiveFinishedFanouts(process.env, options);
31
+ const doing = dryRun ? "Would archive" : "Archived";
32
+ const removal = dryRun ? "would delete" : "deleted";
33
+ console.log(`${doing} ${moved.length} fan-out job(s); ${removal} ${deleted} past the ${ARCHIVE_MAX_FOLDERS}-folder cap.`);
34
+ break;
35
+ }
36
+ case "usage-statusline":
37
+ await captureClaudeUsage(args[1] || "");
38
+ break;
39
+ case "usage":
40
+ console.log(JSON.stringify(await new AccountUsageReader().read(), null, 2));
41
+ break;
9
42
  case "hook":
10
43
  await agentHook(provider.parse(args[1])).catch(() => { });
11
44
  break;
@@ -30,13 +63,25 @@ export async function runBridge(args, version) {
30
63
  break;
31
64
  case "doctor": {
32
65
  const helper = await health(), muxes = await servers();
33
- console.log(JSON.stringify({ ok: muxes.length > 0, helper, herdr: muxes, checks: {
66
+ const push = approvalPushCheck(helper);
67
+ // Chat needs Herdr; a plain project shell or agent over SSH does not.
68
+ console.log(JSON.stringify({ ok: true, helper, herdr: muxes, checks: {
34
69
  privateSocket: true, protocol: true, independentHelper: true,
35
70
  herdrRunning: muxes.length > 0, terminal: "SSH PTY; authorize the Phren device key with pty",
36
- } }, null, 2));
37
- return muxes.length > 0 ? 0 : 1;
71
+ shell: muxes.length > 0 ? "available" : "Herdr is not running: chat is unavailable, project shells and agents still open over SSH",
72
+ approvalPush: push.configured ? "configured" : "not configured",
73
+ }, ...(push.warning ? { warnings: [push.warning] } : {}) }, null, 2));
74
+ if (push.warning)
75
+ console.error(`warning: ${push.warning}`);
76
+ break;
38
77
  }
39
- default: throw new Error("Usage: phren bridge <install|status|doctor|update|rollback|uninstall>");
78
+ default: throw new Error("Usage: phren bridge <install|status|doctor|usage|update|rollback|uninstall|enroll-computer|fanouts archive>");
40
79
  }
41
80
  return 0;
42
81
  }
82
+ /** Doctor's push check, from the running Hook's own capability: only a Hook
83
+ * that loaded apns.json and its key offers `approvalPush`. */
84
+ export function approvalPushCheck(helper) {
85
+ const configured = object(helper.capabilities).approvalPush === "direct-apns";
86
+ return configured ? { configured } : { configured, warning: apnsSetupSteps() };
87
+ }
@@ -0,0 +1,4 @@
1
+ /** Every name this computer answers to: machines.yaml often registers the
2
+ * same Mac as its hostname, the hostname's first label and its Bonjour name.
3
+ * The Hook reports them in /v1/health so a peer can recognize this computer. */
4
+ export declare function localNames(): string[];
@@ -0,0 +1,16 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import { hostname } from "node:os";
3
+ /** Every name this computer answers to: machines.yaml often registers the
4
+ * same Mac as its hostname, the hostname's first label and its Bonjour name.
5
+ * The Hook reports them in /v1/health so a peer can recognize this computer. */
6
+ export function localNames() {
7
+ const host = hostname();
8
+ const names = [host, host.split(".")[0]];
9
+ if (process.platform === "darwin") {
10
+ try {
11
+ names.push(execFileSync("scutil", ["--get", "LocalHostName"], { encoding: "utf8", timeout: 1_000 }).trim());
12
+ }
13
+ catch { /* No Bonjour name set: the hostname forms above still match. */ }
14
+ }
15
+ return [...new Set(names.filter(Boolean))];
16
+ }
@@ -0,0 +1,9 @@
1
+ import { computerName } from "./protocol.js";
2
+ export { computerName };
3
+ export declare const dispatchKeyPath: (root?: string) => string;
4
+ export declare function publicComputerKey(value: string): string;
5
+ export declare function computerKeyLine(name: string, publicKey: string): string;
6
+ /** Never replace a dispatch identity implicitly: every peer enrolled this key. */
7
+ export declare function enrollComputer(name: string, root?: string): Promise<string>;
8
+ /** Accept a public key, rebuilding the restrictions rather than trusting supplied options. */
9
+ export declare function acceptComputer(name: string, input: string, sshDirectory?: string): Promise<void>;