@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
package/README.md CHANGED
@@ -77,7 +77,7 @@ synthesize?: boolean - Generate a synthesis paragraph from top results usi
77
77
 
78
78
  ### get_project_summary
79
79
 
80
- Returns a project's summary.md content, path to its CLAUDE.md, and a list of indexed files.
80
+ Returns a project's summary.md content, path to its AGENTS.md, and a list of indexed files.
81
81
 
82
82
  ```
83
83
  name: string - Project name (e.g. "my-app", "backend")
@@ -98,7 +98,7 @@ No parameters.
98
98
  5. Builds an in-memory SQLite FTS5 index with Porter stemming
99
99
  6. Serves tools over stdio using the MCP protocol
100
100
 
101
- File types are derived from filenames and directories: `CLAUDE.md` -> "claude", `summary.md` -> "summary", `FINDINGS.md` -> "findings", `tasks.md` -> "task", files under `notes/` -> "notes", files under `reference/` -> "reference", files under `skills/` -> "skill".
101
+ File types are derived from filenames and directories: `AGENTS.md` -> "claude", `summary.md` -> "summary", `FINDINGS.md` -> "findings", `tasks.md` -> "task", files under `notes/` -> "notes", files under `reference/` -> "reference", files under `skills/` -> "skill".
102
102
 
103
103
  ## Development
104
104
 
@@ -0,0 +1,12 @@
1
+ export declare const AGENT_INSTRUCTIONS_FILENAME = "AGENTS.md";
2
+ export declare const LEGACY_AGENT_INSTRUCTIONS_FILENAME = "CLAUDE.md";
3
+ /** Resolve instructions without changing the store. New files always win. */
4
+ export declare function resolveAgentInstructionsPath(scopeDir: string): string | null;
5
+ /**
6
+ * Copy legacy instructions to AGENTS.md once. The legacy source is retained so
7
+ * an interrupted upgrade, older Phren client, or hand-written Claude setup
8
+ * cannot lose data. When both files exist AGENTS.md remains authoritative and
9
+ * neither file is modified.
10
+ */
11
+ export declare function migrateLegacyAgentInstructions(scopeDir: string): boolean;
12
+ export declare function migrateStoreAgentInstructions(phrenPath: string): string[];
@@ -0,0 +1,52 @@
1
+ import * as fs from "fs";
2
+ import * as path from "path";
3
+ import { atomicWriteText, debugLog } from "./shared.js";
4
+ import { errorMessage } from "./utils.js";
5
+ export const AGENT_INSTRUCTIONS_FILENAME = "AGENTS.md";
6
+ export const LEGACY_AGENT_INSTRUCTIONS_FILENAME = "CLAUDE.md";
7
+ /** Resolve instructions without changing the store. New files always win. */
8
+ export function resolveAgentInstructionsPath(scopeDir) {
9
+ const canonical = path.join(scopeDir, AGENT_INSTRUCTIONS_FILENAME);
10
+ if (fs.existsSync(canonical))
11
+ return canonical;
12
+ const legacy = path.join(scopeDir, LEGACY_AGENT_INSTRUCTIONS_FILENAME);
13
+ return fs.existsSync(legacy) ? legacy : null;
14
+ }
15
+ /**
16
+ * Copy legacy instructions to AGENTS.md once. The legacy source is retained so
17
+ * an interrupted upgrade, older Phren client, or hand-written Claude setup
18
+ * cannot lose data. When both files exist AGENTS.md remains authoritative and
19
+ * neither file is modified.
20
+ */
21
+ export function migrateLegacyAgentInstructions(scopeDir) {
22
+ const canonical = path.join(scopeDir, AGENT_INSTRUCTIONS_FILENAME);
23
+ const legacy = path.join(scopeDir, LEGACY_AGENT_INSTRUCTIONS_FILENAME);
24
+ if (fs.existsSync(canonical) || !fs.existsSync(legacy))
25
+ return false;
26
+ try {
27
+ atomicWriteText(canonical, fs.readFileSync(legacy, "utf8"));
28
+ return true;
29
+ }
30
+ catch (err) {
31
+ debugLog(`agent instructions migration failed for ${scopeDir}: ${errorMessage(err)}`);
32
+ return false;
33
+ }
34
+ }
35
+ export function migrateStoreAgentInstructions(phrenPath) {
36
+ const migrated = [];
37
+ let entries;
38
+ try {
39
+ entries = fs.readdirSync(phrenPath, { withFileTypes: true });
40
+ }
41
+ catch {
42
+ return migrated;
43
+ }
44
+ for (const entry of entries) {
45
+ if (!entry.isDirectory() || entry.name.startsWith("."))
46
+ continue;
47
+ const scopeDir = path.join(phrenPath, entry.name);
48
+ if (migrateLegacyAgentInstructions(scopeDir))
49
+ migrated.push(`${entry.name}/${AGENT_INSTRUCTIONS_FILENAME}`);
50
+ }
51
+ return migrated;
52
+ }
@@ -0,0 +1,32 @@
1
+ import { type Json } from "./protocol.js";
2
+ /** Small stores the agent callback socket keeps: the recorded pane binding
3
+ * files, push-notification answer bindings, and overview watch leases. */
4
+ export declare const localSocket: () => string;
5
+ export declare const bindingPath: (server: string, pane: string) => string;
6
+ export declare function recordedSession(server: string, pane: Json, pids: number[]): Promise<string | undefined>;
7
+ export interface PushBinding {
8
+ action: string;
9
+ expiresAt: number;
10
+ }
11
+ export declare class PushBindingStore {
12
+ private now;
13
+ private limit;
14
+ private values;
15
+ constructor(now?: () => number, limit?: number);
16
+ add(binding: string, value: PushBinding): void;
17
+ consume(binding: string): PushBinding | undefined;
18
+ /** The binding's action without spending it: a tap that opens the app. */
19
+ peek(binding: string): PushBinding | undefined;
20
+ dropAction(action: string): void;
21
+ clear(): void;
22
+ get size(): number;
23
+ }
24
+ /** An explicit foreground overview poll renews interest for a bounded interval.
25
+ * A disconnected phone never leaves future terminal prompts waiting forever. */
26
+ export declare class ApprovalWatchLeases {
27
+ private now;
28
+ private servers;
29
+ constructor(now?: () => number);
30
+ renew(server: string): void;
31
+ has(server: string): boolean;
32
+ }
@@ -0,0 +1,67 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { bridgeRoot, object, serverName, sessionId } from "./protocol.js";
4
+ /** Small stores the agent callback socket keeps: the recorded pane binding
5
+ * files, push-notification answer bindings, and overview watch leases. */
6
+ export const localSocket = () => path.join(bridgeRoot(), "agent.sock");
7
+ export const bindingPath = (server, pane) => path.join(bridgeRoot(), "bindings", encodeURIComponent(serverName.parse(server)), encodeURIComponent(pane) + ".json");
8
+ export async function recordedSession(server, pane, pids) {
9
+ try {
10
+ const value = object(JSON.parse(await readFile(bindingPath(server, String(pane.pane_id)), "utf8")));
11
+ if (value.terminal !== pane.terminal_id || value.source !== pane.agent || !Array.isArray(value.pids) || !value.pids.some(p => pids.includes(Number(p))))
12
+ return undefined;
13
+ return sessionId.parse(value.session);
14
+ }
15
+ catch {
16
+ return undefined;
17
+ }
18
+ }
19
+ export class PushBindingStore {
20
+ now;
21
+ limit;
22
+ values = new Map();
23
+ constructor(now = Date.now, limit = 128) {
24
+ this.now = now;
25
+ this.limit = limit;
26
+ }
27
+ add(binding, value) {
28
+ for (const [key, item] of this.values)
29
+ if (item.expiresAt <= this.now())
30
+ this.values.delete(key);
31
+ while (this.values.size >= this.limit)
32
+ this.values.delete(this.values.keys().next().value);
33
+ this.values.set(binding, value);
34
+ }
35
+ consume(binding) {
36
+ const value = this.values.get(binding);
37
+ this.values.delete(binding);
38
+ return value && value.expiresAt > this.now() ? value : undefined;
39
+ }
40
+ /** The binding's action without spending it: a tap that opens the app. */
41
+ peek(binding) {
42
+ const value = this.values.get(binding);
43
+ return value && value.expiresAt > this.now() ? value : undefined;
44
+ }
45
+ dropAction(action) { for (const [key, value] of this.values)
46
+ if (value.action === action)
47
+ this.values.delete(key); }
48
+ clear() { this.values.clear(); }
49
+ get size() { return this.values.size; }
50
+ }
51
+ /** An explicit foreground overview poll renews interest for a bounded interval.
52
+ * A disconnected phone never leaves future terminal prompts waiting forever. */
53
+ export class ApprovalWatchLeases {
54
+ now;
55
+ servers = new Map();
56
+ constructor(now = Date.now) {
57
+ this.now = now;
58
+ }
59
+ renew(server) {
60
+ for (const [key, expiry] of this.servers)
61
+ if (expiry <= this.now())
62
+ this.servers.delete(key);
63
+ if (this.servers.has(server) || this.servers.size < 64)
64
+ this.servers.set(server, this.now() + 25_000);
65
+ }
66
+ has(server) { return (this.servers.get(server) || 0) > this.now(); }
67
+ }
@@ -1,14 +1,205 @@
1
+ import { type ModuleSnapshot } from "../modules/runtime.js";
2
+ import { type ServerResponse } from "node:http";
1
3
  import { type Json, type Provider, type Target } from "./protocol.js";
2
- export declare function recordedSession(server: string, pane: Json, pids: number[]): Promise<string | undefined>;
4
+ import { ToolChanges } from "./changes.js";
5
+ import { ApprovalPushService } from "./push.js";
6
+ import { type TerminalChoice } from "./terminal-choice.js";
7
+ import { ApprovalWatchLeases } from "./agent-hook-stores.js";
8
+ export { permissionPrompt, terminalChoice, visibleTerminalChoice, type TerminalChoice, type TerminalQuestion } from "./terminal-choice.js";
9
+ export { ApprovalWatchLeases, PushBindingStore, recordedSession } from "./agent-hook-stores.js";
10
+ interface Pending {
11
+ target: Target;
12
+ response: ServerResponse;
13
+ tool: string;
14
+ input: unknown;
15
+ message: string;
16
+ title?: string;
17
+ choice?: TerminalChoice;
18
+ expiresAt: string;
19
+ timer: NodeJS.Timeout;
20
+ conductor?: {
21
+ action: "dispatch" | "hand_off";
22
+ project?: string;
23
+ computer?: string;
24
+ };
25
+ }
26
+ /** A conductor `dispatch` or `hand_off` permission ask the Hook can answer
27
+ * itself under a standing grant, or offer the phone two grant-writing answers. */
28
+ export declare function conductorCall(tool: string, input: unknown): Pending["conductor"] | undefined;
29
+ export type DeliveryOutcome = "delivered" | "blocked" | "pending";
3
30
  /** This socket is deliberately separate from the phone's HTTP pipe. Only local
4
31
  * agent callbacks can register identities or create an approval request. */
5
32
  export declare class AgentHooks {
33
+ readonly push: ApprovalPushService;
34
+ private modules?;
35
+ readonly changes: ToolChanges;
6
36
  private pending;
37
+ /** Prompts Phren has typed into a pane, by their text, until the agent that
38
+ * actually receives one reports in through UserPromptSubmit. Herdr writes
39
+ * to a pane, not a conversation; the receiving agent's hook is the only
40
+ * party that knows which conversation consumed the text, so it is the one
41
+ * that can refuse it when that is not the conversation the phone meant. */
42
+ private deliveries;
43
+ /** The permission request a conversation is drawing in its own terminal
44
+ * because nobody was there to hold it: what the phone shows above its
45
+ * answer keys until the pane stops waiting. `dialog` marks a choice parsed
46
+ * from the pane's own numbered lines, whose answers gain an Enter, and
47
+ * `questions` carries a released AskUserQuestion's normalized question set
48
+ * with the index currently being answered. */
49
+ private terminalPrompts;
50
+ /** The last time each pane's terminal lines were read for a dialog, so a
51
+ * status tick reads them at most once per three seconds per pane. */
52
+ private dialogReads;
53
+ /** Panes whose last read terminal line is a password prompt, so the status
54
+ * frame can offer the phone's secret sheet only when one is really asking. */
55
+ private passwords;
56
+ /** Conversations Claude Code is compacting, by target, until the new context
57
+ * starts. The phone shows the state instead of the summary row's text. */
58
+ private compactingSince;
59
+ /** Panes where Phren just typed a bare slash command: the agent is drawing
60
+ * that command's menu, which Herdr reports as an idle agent, so keys are
61
+ * allowed there for a short while to walk and confirm it. The command text
62
+ * and a one-shot confirmation attempt ride with the window. */
63
+ private menus;
7
64
  private watching;
65
+ readonly overview: ApprovalWatchLeases;
8
66
  private server?;
67
+ private pushBindings;
68
+ /** Held asks that were pushed: action -> when the notification expires. */
69
+ private pushedHolds;
70
+ /** Pushed asks whose hold ended with the request left in the terminal. */
71
+ private releasedHolds;
72
+ /** Terminal dialogs pushed to phones: by pane, the dialog last pushed; by
73
+ * action, what an answer from the notification types. */
74
+ private dialogPushes;
75
+ private dialogActions;
76
+ /** opencode permission asks seen on disk, by request id. */
77
+ private opencode;
78
+ private closed;
79
+ private opencodeSweep?;
80
+ private opencodeLive;
81
+ private fanoutLive;
82
+ private fanoutSweeping;
83
+ private opencodeWatcher?;
84
+ private opencodePoll?;
85
+ private opencodeDebounce?;
86
+ /** Fan-out jobs already pushed as blocked, by job id and blocked timestamp. */
87
+ private fanoutSeen;
88
+ private fanoutTimer?;
89
+ private fanoutArchiveTimer?;
90
+ constructor(push?: ApprovalPushService, modules?: ModuleSnapshot | undefined);
91
+ private approvalsDirectory;
92
+ private scheduleOpencodeSweep;
93
+ /** Read every live opencode request file, map it to a target through the
94
+ * recorded bindings or Herdr's explicit opencode session id, and register it
95
+ * for a push and a push-binding answer. A file that vanished or expired is
96
+ * forgotten. */
97
+ sweepOpencodeApprovals(): Promise<void>;
98
+ private readOpencodeApprovals;
99
+ /** A session's exact pane. A recorded binding carries the full target; when
100
+ * there is none, Herdr's explicit session identity names the pane. */
101
+ private resolveTarget;
102
+ /** Push once for each fan-out job whose blocked.json the plugin wrote. */
103
+ private sweepBlockedFanouts;
104
+ /** Move finished fan-out folders older than a day into the archive; one log
105
+ * line records a sweep that moved or deleted anything, and a sweep that
106
+ * fails never takes the Hook down. */
107
+ private sweepFanoutArchive;
9
108
  watch(target: Target): () => void;
109
+ /** Register a prompt about to be typed into `target`'s pane. The returned
110
+ * promise settles "delivered" once that conversation's own hook submits the
111
+ * text, "blocked" if another conversation in the pane tried to, or "pending"
112
+ * after `waitMs`: a busy agent queues typed input and submits it only when
113
+ * its turn ends, so the record outlives the wait (up to ten minutes) and a
114
+ * late submission to the wrong conversation is still refused. */
115
+ expectDelivery(target: Target, text: string, waitMs?: number): Promise<DeliveryOutcome>;
116
+ /** Wait again for a delivery `expectDelivery` already reported pending,
117
+ * after the Hook pressed Enter a second time. */
118
+ awaitLateDelivery(target: Target, text: string, waitMs?: number): Promise<DeliveryOutcome>;
119
+ /** The conversation `target` just submitted `prompt`. Nothing Phren typed
120
+ * matches: a locally typed prompt, always allowed. Otherwise the oldest
121
+ * matching delivery decides: its own conversation consumes it; any other
122
+ * conversation is told to drop it, so the text is never spoken to the
123
+ * wrong agent and the phone can safely send it again. */
124
+ private submitted;
125
+ private rememberTerminalPrompt;
126
+ /** The request the agent is showing in its terminal, if one fell through
127
+ * in the last fifteen minutes; the caller only asks while the pane waits. */
128
+ terminalPrompt(target: Target): Json | undefined;
129
+ clearTerminalPrompt(target: Target): void;
130
+ /** True while the pane's own terminal is reading a password. */
131
+ passwordPrompt(target: Target): boolean;
132
+ /** Claude Code's auto-mode fallback, opencode and Codex draw a numbered
133
+ * dialog in the pane with no PermissionRequest hook behind it. While the pane
134
+ * waits with nothing else to ask, read its last lines (at most once per
135
+ * three seconds per pane) and publish the dialog as a terminal choice; drop
136
+ * it when the pane leaves waiting or the dialog lines vanish. A remembered
137
+ * permission request that is not a dialog keeps the slot untouched. The same
138
+ * read notes whether the terminal is reading a password. */
139
+ syncTerminalDialog(target: Target, active: boolean): Promise<void>;
140
+ /** Resolve a phone option identifier. Real shortcuts retain their key path;
141
+ * keyless rows are reached and verified before returning Enter to the route. */
142
+ dialogAnswerKeys<K extends string>(target: Target, keys: readonly K[]): Promise<(K | "Enter")[]>;
143
+ moveDialogHighlight(target: Target, expected: TerminalChoice, key: string, beforeKeys?: () => Promise<void>): Promise<void>;
144
+ /** Answer one question of a released AskUserQuestion with the option's own
145
+ * digit: send the chosen digit(s), then Tab to advance to the next
146
+ * question or Enter after the last. The stored question index moves with
147
+ * them and a finished set is cleared. Undefined when the prompt is not a
148
+ * question, so an ordinary key falls through to the usual handling. */
149
+ questionAnswerKeys(target: Target, keys: readonly string[]): string[] | undefined;
150
+ private startCompacting;
151
+ private stopCompacting;
152
+ /** True while Claude Code is compacting `target`; a boundary older than ten
153
+ * minutes is stale, so a missed SessionStart cannot pin the state forever. */
154
+ compacting(target: Target): boolean;
155
+ menuOpened(target: Target, command?: string): void;
156
+ menuOpen(target: Target): boolean;
157
+ /** The bare slash command that opened this pane's current menu window. */
158
+ menuCommand(target: Target): string | undefined;
159
+ menuClosed(target: Target): void;
160
+ /** Read what the pane draws, stripping ANSI unless placeholder styling is needed. */
161
+ paneLines(target: Target, stripAnsi?: boolean): Promise<string>;
162
+ /** After the phone walks Codex's /permissions menu onto Full Access, the
163
+ * agent draws a second "Enable full access?" confirmation. Watch the pane's
164
+ * terminal lines for it, answer with its own numbered choice, and only then
165
+ * close the menu window. A confirmation that never arrives within three
166
+ * seconds is left open as the visible prompt, published as the terminal
167
+ * choice the phone draws as a question card. Runs at most once per window. */
168
+ walkMenuConfirmation(target: Target): Promise<{
169
+ menuClosed: boolean;
170
+ waiting?: {
171
+ message: string;
172
+ choice?: TerminalChoice;
173
+ };
174
+ }>;
10
175
  approval(target: Target): Json | undefined;
11
- answer(target: Target, id: string, decision: unknown): Promise<void>;
176
+ private opencodeApproval;
177
+ /** Live fan-out worker asks shown on this parent conversation, oldest first. */
178
+ private fanoutHeld;
179
+ pendingPanes(server: string, state: Json): Set<string>;
180
+ /** Hands the owner's answer to the fan-out launcher waiting on the worker's session. */
181
+ private answerFanout;
182
+ answer(target: Target, id: string, decision: unknown, updatedInput?: unknown): Promise<void>;
183
+ /** A held approval that is really a terminal dialog, answered from the
184
+ * phone with its own keys: let the callback fall back to the terminal at
185
+ * once instead of leaving the card up until the 55-second timer. */
186
+ releaseChoice(target: Target): void;
187
+ answerPush(binding: string, decision: unknown): Promise<void>;
188
+ /** Where a pushed ask lives, without answering it: the phone opens that
189
+ * session's details when the notification itself is tapped. */
190
+ pushTarget(binding: string): Target | undefined;
191
+ /** Every waiting pane on this computer, each Hook tick, whether or not a
192
+ * phone watches: an approval an agent draws as a numbered dialog in its
193
+ * terminal (Claude's fallback prompts, Codex, OpenCode, Copilot) has no
194
+ * hook behind it, so this is the only way it reaches a phone with phren
195
+ * closed. Each dialog is pushed once; a pane that stops waiting drops it. */
196
+ observeWaitingPanes(server: string, panes: Json[], resolve: (pane: Json) => Promise<Target | undefined>): Promise<void>;
197
+ private adoptReleasedHold;
198
+ private dropDialogPush;
199
+ /** Approve picks the dialog's yes/allow row (else its first), Deny its
200
+ * no/deny row (else Escape), typed as the pane's own keys. */
201
+ private answerDialog;
202
+ private dropPushBindings;
12
203
  start(): Promise<void>;
13
204
  close(): void;
14
205
  }