@phren/cli 0.2.15 → 0.3.0

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 (392) 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 +195 -2
  7. package/dist/bridge/agent-hooks.js +1049 -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 +23 -0
  15. package/dist/bridge/code-note.js +51 -0
  16. package/dist/bridge/code-routes.d.ts +151 -0
  17. package/dist/bridge/code-routes.js +442 -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 +125 -0
  33. package/dist/bridge/dispatch-returns.js +283 -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 +210 -0
  37. package/dist/bridge/dispatch.js +286 -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 +28 -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 +61 -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 +54 -0
  96. package/dist/bridge/schedule-watch.js +255 -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 +36 -0
  104. package/dist/bridge/server-pane-routes.js +479 -0
  105. package/dist/bridge/server-routes.d.ts +108 -0
  106. package/dist/bridge/server-routes.js +556 -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 +96 -0
  136. package/dist/bridge/transcript-preview.js +491 -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 +46545 -21051
  146. package/dist/cli/actions.js +14 -1
  147. package/dist/cli/config-policy.js +25 -0
  148. package/dist/cli/config-proactivity.d.ts +3 -1
  149. package/dist/cli/config-proactivity.js +35 -3
  150. package/dist/cli/config.js +4 -1
  151. package/dist/cli/extract.d.ts +0 -8
  152. package/dist/cli/extract.js +4 -7
  153. package/dist/cli/govern.js +5 -2
  154. package/dist/cli/hooks-globs.js +1 -1
  155. package/dist/cli/hooks.d.ts +1 -1
  156. package/dist/cli/hooks.js +9 -7
  157. package/dist/cli/namespaces-projects.js +12 -6
  158. package/dist/cli/namespaces-store.js +37 -6
  159. package/dist/cli/namespaces-tasks.js +1 -1
  160. package/dist/cli/schedules.d.ts +1 -0
  161. package/dist/cli/schedules.js +164 -0
  162. package/dist/cli/session-background.js +1 -1
  163. package/dist/cli/session-git.d.ts +8 -5
  164. package/dist/cli/session-git.js +45 -120
  165. package/dist/cli/session-start.js +3 -1
  166. package/dist/cli/session-stop.js +19 -8
  167. package/dist/cli/team.js +13 -10
  168. package/dist/cli-handlers.d.ts +1 -1
  169. package/dist/cli-handlers.js +8 -4
  170. package/dist/cli-help.d.ts +5 -4
  171. package/dist/cli-help.js +15 -15
  172. package/dist/cli-registry.d.ts +4 -1
  173. package/dist/cli-registry.js +119 -6
  174. package/dist/content/archive.js +2 -2
  175. package/dist/content/citation.d.ts +11 -0
  176. package/dist/content/citation.js +18 -0
  177. package/dist/content/learning.js +2 -0
  178. package/dist/content/summarize.d.ts +14 -15
  179. package/dist/content/summarize.js +60 -5
  180. package/dist/content/validate.d.ts +17 -4
  181. package/dist/content/validate.js +200 -122
  182. package/dist/core/project-registry.d.ts +26 -0
  183. package/dist/core/project-registry.js +573 -0
  184. package/dist/core/project.js +2 -3
  185. package/dist/data/access.d.ts +16 -1
  186. package/dist/data/access.js +31 -3
  187. package/dist/data/tasks.d.ts +18 -3
  188. package/dist/data/tasks.js +8 -7
  189. package/dist/entrypoint.js +44 -10
  190. package/dist/fanout/adapters/claude.d.ts +2 -0
  191. package/dist/fanout/adapters/claude.js +7 -0
  192. package/dist/fanout/adapters/codex.d.ts +2 -0
  193. package/dist/fanout/adapters/codex.js +9 -0
  194. package/dist/fanout/adapters/opencode.d.ts +4 -0
  195. package/dist/fanout/adapters/opencode.js +9 -0
  196. package/dist/fanout/adapters/types.d.ts +21 -0
  197. package/dist/fanout/adapters/types.js +3 -0
  198. package/dist/fanout/command.d.ts +2 -0
  199. package/dist/fanout/command.js +78 -0
  200. package/dist/fanout/launcher.d.ts +27 -0
  201. package/dist/fanout/launcher.js +156 -0
  202. package/dist/fanout/opencode-serve.d.ts +24 -0
  203. package/dist/fanout/opencode-serve.js +191 -0
  204. package/dist/fanout/picker.d.ts +91 -0
  205. package/dist/fanout/picker.js +51 -0
  206. package/dist/fanout/usage.d.ts +5 -0
  207. package/dist/fanout/usage.js +51 -0
  208. package/dist/fanout/watchdog.d.ts +10 -0
  209. package/dist/fanout/watchdog.js +27 -0
  210. package/dist/filenames.d.ts +9 -0
  211. package/dist/filenames.js +11 -0
  212. package/dist/finding/context.js +4 -22
  213. package/dist/generated/memory-ui-graph.browser.js +525 -419
  214. package/dist/governance/policy-constants.d.ts +11 -0
  215. package/dist/governance/policy-constants.js +9 -0
  216. package/dist/governance/policy.d.ts +5 -8
  217. package/dist/governance/policy.js +11 -8
  218. package/dist/graph-core/camera.d.ts +24 -0
  219. package/dist/graph-core/camera.js +18 -0
  220. package/dist/graph-core/index.d.ts +2 -0
  221. package/dist/graph-core/index.js +2 -0
  222. package/dist/graph-core/labels.d.ts +77 -0
  223. package/dist/graph-core/labels.js +124 -0
  224. package/dist/graph-core/model.d.ts +13 -0
  225. package/dist/graph-core/model.js +33 -0
  226. package/dist/graph-core/types.d.ts +2 -0
  227. package/dist/home-paths.d.ts +7 -0
  228. package/dist/home-paths.js +21 -0
  229. package/dist/hooks.d.ts +3 -15
  230. package/dist/hooks.js +14 -1
  231. package/dist/index.js +24 -2
  232. package/dist/init/guard-globals.d.ts +1 -1
  233. package/dist/init/guard-globals.js +4 -4
  234. package/dist/init/init-configure.js +3 -3
  235. package/dist/init/init-uninstall.js +15 -5
  236. package/dist/init/init-walkthrough.js +1 -1
  237. package/dist/init/init.js +26 -6
  238. package/dist/init/management-preset.d.ts +1 -1
  239. package/dist/init/management-preset.js +2 -2
  240. package/dist/init/preferences.js +1 -1
  241. package/dist/init/self-wiring.js +1 -1
  242. package/dist/init/setup.d.ts +3 -26
  243. package/dist/init/setup.js +68 -593
  244. package/dist/init/shared.js +2 -0
  245. package/dist/init/store-gitignore.d.ts +1 -6
  246. package/dist/init/store-gitignore.js +2 -8
  247. package/dist/init/teardown.d.ts +1 -1
  248. package/dist/init/teardown.js +2 -2
  249. package/dist/link/context-imports.d.ts +15 -0
  250. package/dist/link/context-imports.js +101 -0
  251. package/dist/link/context.js +1 -1
  252. package/dist/link/doctor.d.ts +22 -1
  253. package/dist/link/doctor.js +128 -58
  254. package/dist/link/link.js +29 -61
  255. package/dist/link/refresh.js +2 -2
  256. package/dist/link/skills.js +26 -5
  257. package/dist/machine-identity.d.ts +3 -0
  258. package/dist/machine-identity.js +6 -0
  259. package/dist/mcp/profile.d.ts +2 -19
  260. package/dist/mcp/profile.js +64 -22
  261. package/dist/memory-ui-graph.runtime.js +525 -419
  262. package/dist/modules/code-package.d.ts +16 -0
  263. package/dist/modules/code-package.js +160 -0
  264. package/dist/modules/command.d.ts +2 -0
  265. package/dist/modules/command.js +67 -0
  266. package/dist/modules/config.d.ts +4 -0
  267. package/dist/modules/config.js +70 -0
  268. package/dist/modules/manifest.d.ts +41 -0
  269. package/dist/modules/manifest.js +1 -0
  270. package/dist/modules/provision.d.ts +3 -0
  271. package/dist/modules/provision.js +84 -0
  272. package/dist/modules/registry.d.ts +16 -0
  273. package/dist/modules/registry.js +250 -0
  274. package/dist/modules/runtime.d.ts +15 -0
  275. package/dist/modules/runtime.js +59 -0
  276. package/dist/package-metadata.js +10 -2
  277. package/dist/phren-dotenv.js +4 -2
  278. package/dist/phren-paths.d.ts +3 -2
  279. package/dist/phren-paths.js +4 -5
  280. package/dist/profile-store.js +43 -8
  281. package/dist/project-config.d.ts +19 -1
  282. package/dist/project-config.js +29 -3
  283. package/dist/project-topics.d.ts +1 -0
  284. package/dist/project-topics.js +13 -10
  285. package/dist/provider-adapters.js +1 -4
  286. package/dist/query-correlation.js +6 -6
  287. package/dist/session/artifacts.js +5 -5
  288. package/dist/session/checkpoints.js +5 -0
  289. package/dist/session/utils.d.ts +2 -2
  290. package/dist/session/utils.js +6 -6
  291. package/dist/shared/content.d.ts +1 -1
  292. package/dist/shared/content.js +1 -1
  293. package/dist/shared/data-utils.js +1 -1
  294. package/dist/shared/fragment-graph.d.ts +1 -1
  295. package/dist/shared/fragment-graph.js +5 -5
  296. package/dist/shared/index.js +48 -7
  297. package/dist/shared/retrieval.d.ts +18 -3
  298. package/dist/shared/retrieval.js +101 -12
  299. package/dist/shared/search-fallback.js +4 -6
  300. package/dist/shared/sqljs.d.ts +2 -0
  301. package/dist/shared/sqljs.js +4 -2
  302. package/dist/shared.d.ts +0 -1
  303. package/dist/shared.js +0 -1
  304. package/dist/shell/input.d.ts +1 -5
  305. package/dist/shell/input.js +16 -10
  306. package/dist/shell/palette.d.ts +2 -2
  307. package/dist/shell/palette.js +3 -7
  308. package/dist/shell/render.d.ts +3 -1
  309. package/dist/shell/render.js +4 -4
  310. package/dist/shell/shell.js +4 -1
  311. package/dist/shell/types.d.ts +1 -0
  312. package/dist/shell/types.js +4 -0
  313. package/dist/shell/view.d.ts +0 -4
  314. package/dist/shell/view.js +19 -27
  315. package/dist/skill/registry.js +25 -17
  316. package/dist/skill/state.d.ts +3 -0
  317. package/dist/skill/state.js +13 -7
  318. package/dist/status.js +38 -17
  319. package/dist/store-registry.d.ts +44 -18
  320. package/dist/store-registry.js +169 -60
  321. package/dist/store-weight.d.ts +1 -6
  322. package/dist/store-weight.js +4 -2
  323. package/dist/sync/auth-doctor.d.ts +8 -0
  324. package/dist/sync/auth-doctor.js +27 -0
  325. package/dist/sync/auth.d.ts +27 -0
  326. package/dist/sync/auth.js +114 -0
  327. package/dist/sync/conflict-resolve.d.ts +9 -0
  328. package/dist/sync/conflict-resolve.js +146 -0
  329. package/dist/sync/git-state.d.ts +4 -0
  330. package/dist/sync/git-state.js +49 -0
  331. package/dist/sync/outcome.d.ts +34 -0
  332. package/dist/sync/outcome.js +57 -0
  333. package/dist/sync/pull.d.ts +15 -7
  334. package/dist/sync/pull.js +84 -35
  335. package/dist/sync/store-merge.d.ts +29 -0
  336. package/dist/sync/store-merge.js +137 -0
  337. package/dist/sync/task-merge.d.ts +22 -0
  338. package/dist/sync/task-merge.js +158 -0
  339. package/dist/task/github.js +1 -1
  340. package/dist/task/lifecycle.d.ts +5 -0
  341. package/dist/task/lifecycle.js +67 -23
  342. package/dist/terminal-text.d.ts +5 -0
  343. package/dist/terminal-text.js +11 -0
  344. package/dist/test-global-setup.js +7 -0
  345. package/dist/tool-registry.d.ts +1 -1
  346. package/dist/tool-registry.js +3 -1
  347. package/dist/tools/code.d.ts +3 -0
  348. package/dist/tools/code.js +186 -0
  349. package/dist/tools/config.js +8 -0
  350. package/dist/tools/data.js +14 -7
  351. package/dist/tools/dispatch.d.ts +2 -0
  352. package/dist/tools/dispatch.js +66 -0
  353. package/dist/tools/finding.d.ts +11 -0
  354. package/dist/tools/finding.js +180 -123
  355. package/dist/tools/ops.js +5 -2
  356. package/dist/tools/search.js +21 -8
  357. package/dist/tools/session.js +21 -22
  358. package/dist/tools/tasks.js +8 -2
  359. package/dist/tools/types.d.ts +2 -2
  360. package/dist/tools/types.js +2 -2
  361. package/dist/ui/assets.js +1 -1
  362. package/dist/ui/data.js +14 -15
  363. package/dist/ui/deep-void.d.ts +1 -1
  364. package/dist/ui/deep-void.js +0 -1
  365. package/dist/ui/graph-chrome.d.ts +1 -1
  366. package/dist/ui/graph-chrome.js +51 -0
  367. package/dist/ui/page.js +5 -5
  368. package/dist/ui/scripts.js +67 -30
  369. package/dist/ui/server.js +52 -7
  370. package/dist/update.js +22 -11
  371. package/dist/utils-fts.js +1 -0
  372. package/dist/utils-helpers.d.ts +7 -0
  373. package/dist/utils-helpers.js +17 -0
  374. package/dist/utils.d.ts +1 -1
  375. package/dist/utils.js +1 -1
  376. package/package.json +49 -7
  377. package/plugins/opencode/phren-transcript.js +340 -0
  378. package/starter/README.md +4 -4
  379. package/starter/global/{CLAUDE.md → AGENTS.md} +2 -2
  380. package/starter/global/skills/conductor/SKILL.md +106 -0
  381. package/starter/global/skills/fanout/SKILL.md +20 -0
  382. package/starter/global/skills/phren-discover/SKILL.md +6 -6
  383. package/starter/global/skills/phren-init/SKILL.md +4 -4
  384. package/starter/global/skills/phren-sync/SKILL.md +3 -3
  385. package/starter/templates/frontend/reference/README.md +1 -1
  386. package/starter/templates/library/reference/README.md +1 -1
  387. package/starter/templates/monorepo/reference/README.md +1 -1
  388. package/starter/templates/python-project/reference/README.md +1 -1
  389. /package/starter/templates/frontend/{CLAUDE.md → AGENTS.md} +0 -0
  390. /package/starter/templates/library/{CLAUDE.md → AGENTS.md} +0 -0
  391. /package/starter/templates/monorepo/{CLAUDE.md → AGENTS.md} +0 -0
  392. /package/starter/templates/python-project/{CLAUDE.md → AGENTS.md} +0 -0
@@ -0,0 +1,491 @@
1
+ import { constants } from "node:fs";
2
+ import { open } from "node:fs/promises";
3
+ import { codexThreadPreview } from "./codex-threads.js";
4
+ import { readPaneText } from "./pane-text.js";
5
+ import { object, objects } from "./protocol.js";
6
+ import { withTranscriptIndex } from "./transcript-index.js";
7
+ import { stripTerminal } from "../terminal-text.js";
8
+ export const PREVIEW_INTERVAL_MS = 500;
9
+ const MAX_TEXT = 32_768;
10
+ // A JSON-escaped UTF-16 code unit takes at most six bytes, plus metadata.
11
+ const MAX_PREVIEW_BYTES = MAX_TEXT * 6 + 1_024;
12
+ /** Only the last Claude reply after the current prompt is eligible. A missing
13
+ * prompt anchor is deliberately silent: scrollback could belong to an old turn. */
14
+ export function claudePanePreview(rendered, prompt, previous = "") {
15
+ const screen = rendered.split("\n");
16
+ const raw = screen.map(stripTerminal);
17
+ // What the phone shows: the line with Claude's bold as Markdown. Detection
18
+ // below reads the plain line.
19
+ const marked = screen.map(line => claudeBoldMarkdown(line).replace(/[\u2500-\u257f]/g, "").trimEnd());
20
+ // The rule above the input box can carry the session title
21
+ // ("───── Claude sesh ─"); it ends the reply, it is never part of it.
22
+ // A narrow pane leaves the titled rule a single dash ("…title… ─"), so a
23
+ // line that ends in a rule dash right above the input prompt ends it too.
24
+ const lines = raw.map((line, index) => (/[─━═]{3,}/.test(line) && !/^\s*[│┃║]/.test(line))
25
+ || (/[─━═]\s*$/.test(line) && /^\s*[❯>]\s*$/.test(raw[index + 1] ?? "")) ? "❯" : line.replace(/[\u2500-\u257f]/g, "").trimEnd());
26
+ const firstPrompt = prompt.trim().split(/\r?\n/)[0]?.trim();
27
+ if (!firstPrompt)
28
+ return "";
29
+ let start = -1;
30
+ for (let i = 0; i < lines.length; i++) {
31
+ if (!/^\s*[❯>]\s*\S/.test(lines[i]))
32
+ continue;
33
+ const shown = lines[i].replace(/^\s*[❯>]\s*/, "").trim();
34
+ if (shown === firstPrompt || (shown.length >= 12 && firstPrompt.startsWith(shown)))
35
+ start = i + 1;
36
+ }
37
+ // Once anchored, a reply can scroll its prompt off screen. Extend only
38
+ // through a matching text overlap; unrelated terminal lines cannot replace it.
39
+ const scrolled = start < 0;
40
+ if (scrolled && !previous)
41
+ return "";
42
+ const reply = [], shown = [];
43
+ let writing = scrolled;
44
+ const body = lines.slice(Math.max(0, start)), rawBody = raw.slice(Math.max(0, start)), markedBody = marked.slice(Math.max(0, start));
45
+ // A "⏺" block whose next line is a "⎿" result is a tool call, collapsed
46
+ // ("⏺ Running 1 shell command…") or not; it lands as its own entry.
47
+ const toolBlock = (index) => {
48
+ let wrapped = false;
49
+ for (let next = index + 1; next < body.length; next++) {
50
+ if (!body[next].trim())
51
+ continue;
52
+ // A result ("⎿") or a sub-agent tree ("├─ Plan · 0 tool uses") follows a tool call.
53
+ // A narrow pane wraps the call's description ("⏺ Finding retire wording
54
+ // around Power" / "Portal reports"); its "⎿", indented under the call as
55
+ // Claude draws it, comes after the wrap. A new block, the prompt or a
56
+ // blank line after text ends the search.
57
+ if ((wrapped ? /^\s+(?:│\s*)?[⎿├└]/ : /^\s*(?:│\s*)?[⎿├└]/).test(rawBody[next]))
58
+ return true;
59
+ wrapped = true;
60
+ if (/^\s*[⏺●❯>]/.test(body[next]))
61
+ return false;
62
+ if (!body[next + 1]?.trim())
63
+ return false;
64
+ }
65
+ return false;
66
+ };
67
+ for (const [index, line] of body.entries()) {
68
+ if (/^\s*[❯>]/.test(line) || /esc(?:ape)? to interrupt/i.test(line))
69
+ break;
70
+ if (/^\s*[✻✽✶✢✳✦·⠁-⣿]/u.test(line) || parseClaudeSpinnerLine(line))
71
+ continue;
72
+ // Claude Code draws a finished or running tool group as an unbulleted,
73
+ // indented summary under the reply (" Ran 1 shell command", " Called
74
+ // phren, ran 1 shell command", " Running 1 shell command… grep -rn …").
75
+ // It starts a block after a blank line; it and its wrapped command lines
76
+ // are tool activity, which lands as its own entry.
77
+ if (!body[index - 1]?.trim() && claudeToolSummary(line)) {
78
+ writing = false;
79
+ continue;
80
+ }
81
+ // A running tool group ("⏺ Running 2 agents…") and a tool call
82
+ // ("⏺ Bash(ls)", "⏺ phren - search (MCP)(…)") are not reply
83
+ // text; it lands as its own entry a moment later.
84
+ if (/^\s*[⏺●]\s*[\w.:-]+(?: - [\w.:-]+)?(?: \(MCP\))?\(/.test(line) || (/^\s*[⏺●]/.test(line) && toolBlock(index))
85
+ || /^\s*[⏺●]\s*(?:Running|Calling|Reading|Searching|Writing|Editing|Fetching|Updating|Listing|Creating)\b[^.!?]*(?:…|\.\.\.)/.test(line)) {
86
+ writing = false;
87
+ continue;
88
+ }
89
+ if (/^\s*[⏺●]/.test(line)) {
90
+ reply.length = 0;
91
+ shown.length = 0;
92
+ writing = true;
93
+ }
94
+ if (!writing)
95
+ continue;
96
+ const tidy = (value) => value.replace(/^\s*[⏺●]\s?/, "").replace(/[⠁-⣿✻✽✶✢✳]/gu, "");
97
+ const clean = tidy(line);
98
+ if (/^\s*(?:↳|⎿|ctrl\+|shift\+|\? for shortcuts)/i.test(clean) || claudeChrome(clean))
99
+ continue;
100
+ reply.push(clean.replace(/^ {2}/, ""));
101
+ // A rule line has no marked twin: it never reaches here.
102
+ shown.push(tidy(markedBody[index] ?? line).replace(/^ {2}/, ""));
103
+ }
104
+ const text = unwrapTerminalLines(reply, shown).trim().slice(0, MAX_TEXT);
105
+ if (!scrolled)
106
+ return text;
107
+ if (text.startsWith(previous))
108
+ return text;
109
+ const overlap = previous.lastIndexOf(text.split("\n", 1)[0].slice(0, 80));
110
+ return overlap >= 0 && text.startsWith(previous.slice(overlap))
111
+ ? (previous.slice(0, overlap) + text).slice(0, MAX_TEXT) : previous;
112
+ }
113
+ const TOOL_SUMMARY_CLAUSE = String.raw `(?:(?:[Cc]alled|[Cc]alling) [\w.-]+(?: \d+ times?)?|(?:[Rr]an|[Rr]unning|[Rr]ead|[Rr]eading|[Ss]earched|[Ss]earching|[Ww]rote|[Ww]riting|[Ee]dited|[Ee]diting|[Uu]pdated|[Uu]pdating|[Ff]etched|[Ff]etching|[Ll]isted|[Ll]isting|[Cc]reated|[Cc]reating|[Ll]aunched|[Ll]aunching) \d+ [a-z]+(?: [a-z]+)?)`;
114
+ const TOOL_SUMMARY = new RegExp(`^ {1,4}${TOOL_SUMMARY_CLAUSE}(?:, ${TOOL_SUMMARY_CLAUSE})*(?:(?:…|\\.\\.\\.)(?:\\s.*)?)?(?: \\(ctrl\\+o to expand\\))?\\s*$`);
115
+ /** An unbulleted tool-group summary line, e.g. " Read 1 file, ran 1 shell command". */
116
+ export function claudeToolSummary(line) {
117
+ return TOOL_SUMMARY.test(line);
118
+ }
119
+ /**
120
+ * Claude Code's own screen text, never part of a reply: the update and
121
+ * restart notices, status lines it marks ✔ / ✗ / ⚠ / ※, tips, and the
122
+ * context and auto-accept hints drawn around the input box.
123
+ */
124
+ export function claudeChrome(line) {
125
+ const text = line.trim();
126
+ if (!text)
127
+ return false;
128
+ return /^[✔✓✗✘⚠※]\s/.test(text)
129
+ || /\b(?:Update installed|Restart to update|Auto-update failed|Update available|Run \/doctor|Claude Code has been updated)\b/i.test(text)
130
+ || /^(?:Tip|Hint):\s/i.test(text)
131
+ || /^(?:⏵⏵|⏸)\s/.test(text)
132
+ || /\b(?:auto-accept edits|plan mode) (?:on|off)\b/i.test(text)
133
+ || /^Context left until auto-compact\b/i.test(text)
134
+ || /^(?:esc to (?:interrupt|cancel)|press esc)\b/i.test(text);
135
+ }
136
+ /** A block line that starts its own row even inside a paragraph: a list
137
+ * item, heading, quote, table row or code fence. */
138
+ /** No terminal pane Claude draws in is narrower than this. */
139
+ const MIN_WRAP_WIDTH = 40;
140
+ const BLOCK_START = /^\s*(?:[-*+•]\s|\d+[.)]\s|#{1,6}\s|>|\||```|~~~)/;
141
+ /**
142
+ * Undoes the terminal's word wrap. Claude draws a paragraph wrapped to the
143
+ * pane's width, so the phone would show each wrap as a hard break. A line is
144
+ * joined to the next when the next line's first word would not have fitted
145
+ * on it, which is exactly what a soft wrap looks like; the widest line
146
+ * stands in for the pane width, and below 40 columns nothing is joined. Blank lines, block starts and fenced code
147
+ * keep their breaks. `display` is what is joined, line for line: the text
148
+ * with Markdown put back, measured by its plain twin.
149
+ */
150
+ export function unwrapTerminalLines(lines, display = lines) {
151
+ const width = Math.max(0, ...lines.map(line => line.length));
152
+ // Too narrow to be a pane's wrap: short replies keep their own lines.
153
+ if (width < MIN_WRAP_WIDTH)
154
+ return display.join("\n");
155
+ const out = [];
156
+ let fenced = false;
157
+ lines.forEach((line, index) => {
158
+ const fence = /^\s*(?:```|~~~)/.test(line);
159
+ const before = index > 0 ? lines[index - 1] : undefined;
160
+ const firstWord = line.trimStart().split(/\s/, 1)[0] ?? "";
161
+ const wrapped = !fenced && !fence && before !== undefined && out.length > 0
162
+ && before.trim() !== "" && line.trim() !== "" && !BLOCK_START.test(line)
163
+ && before.trimEnd().length + 1 + firstWord.length > width;
164
+ if (wrapped)
165
+ out[out.length - 1] += " " + display[index].trim();
166
+ else
167
+ out.push(display[index]);
168
+ if (fence)
169
+ fenced = !fenced;
170
+ });
171
+ return out.join("\n");
172
+ }
173
+ const SPINNER_LINE = /^\s*[✻✽✶✢✳✦·*⠁-⣿]\s+([A-Z][\p{L}'-]{1,30})(?:…|\.\.\.)\s*\(([^)]*)\)/u;
174
+ function spinnerSeconds(text) {
175
+ const match = /^(?:(\d{1,4})h\s*)?(?:(\d{1,4})m\s*)?(?:(\d{1,5})s)?$/.exec(text.trim());
176
+ if (!match || (!match[1] && !match[2] && !match[3]))
177
+ return undefined;
178
+ return Number(match[1] ?? 0) * 3600 + Number(match[2] ?? 0) * 60 + Number(match[3] ?? 0);
179
+ }
180
+ /** One spinner line, or undefined for anything else. The parenthesis must
181
+ * start with a time or say "esc to interrupt", as Claude's does. */
182
+ export function parseClaudeSpinnerLine(line) {
183
+ const match = SPINNER_LINE.exec(line);
184
+ if (!match)
185
+ return undefined;
186
+ const parts = match[2].split("·").map(part => part.trim()).filter(Boolean);
187
+ if (!/^\d/.test(parts[0] ?? "") && !parts.some(part => /esc to interrupt/i.test(part)))
188
+ return undefined;
189
+ const spinner = { verb: match[1], thinking: false };
190
+ for (const part of parts) {
191
+ const seconds = spinnerSeconds(part);
192
+ const tokens = /^([↑↓])\s*(\d{1,6}(?:[.,]\d{1,3})?)\s*([kKmM]?)\s+tokens?$/.exec(part);
193
+ const thought = /^thought for (.+)$/i.exec(part);
194
+ if (seconds !== undefined && spinner.elapsed === undefined)
195
+ spinner.elapsed = seconds;
196
+ else if (tokens) {
197
+ const scale = /k/i.test(tokens[3]) ? 1_000 : /m/i.test(tokens[3]) ? 1_000_000 : 1;
198
+ const count = Math.round(Number(tokens[2].replace(",", ".")) * scale);
199
+ if (Number.isFinite(count) && count <= 1e9)
200
+ spinner.tokens = { count, direction: tokens[1] === "↑" ? "up" : "down" };
201
+ }
202
+ else if (/^thinking\b/i.test(part))
203
+ spinner.thinking = true;
204
+ else if (thought) {
205
+ const value = spinnerSeconds(thought[1]);
206
+ if (value !== undefined)
207
+ spinner.thoughtFor = value;
208
+ }
209
+ }
210
+ return spinner;
211
+ }
212
+ /** The newest spinner line on screen. */
213
+ export function claudeSpinner(rendered) {
214
+ const lines = stripTerminal(rendered).split("\n");
215
+ for (let i = lines.length - 1; i >= 0; i--) {
216
+ const spinner = parseClaudeSpinnerLine(lines[i]);
217
+ if (spinner)
218
+ return spinner;
219
+ }
220
+ return undefined;
221
+ }
222
+ /** The word Claude's own spinner shows ("✻ Pondering… (12s · esc to interrupt)"). */
223
+ export function claudeSpinnerVerb(rendered) {
224
+ return claudeSpinner(rendered)?.verb;
225
+ }
226
+ export function readPreviewPane(target) {
227
+ // With its styles: Claude's bold becomes Markdown; everything else strips.
228
+ return readPaneText(target.server, target.pane, { method: "agent.read", source: "visible", lines: 80, stripAnsi: false, format: "ansi", timeoutMs: 2_000, what: "Preview pane read" });
229
+ }
230
+ // An SGR sequence (captured) or any other control sequence stripTerminal removes.
231
+ const PANE_CONTROL = /\x1b\[([0-?]*)[ -/]*([@-~])|\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)|\r/g;
232
+ /**
233
+ * One pane line as Markdown bold. Claude draws a reply's **bold** with SGR 1
234
+ * and drops the asterisks, so a plain read loses it and the phone's preview
235
+ * would gain it only when the reply lands. Whitespace stays outside the
236
+ * markers (Markdown does not close `**a **`); other styles are dropped.
237
+ */
238
+ export function claudeBoldMarkdown(line) {
239
+ const runs = [];
240
+ let bold = false, last = 0;
241
+ const take = (text) => {
242
+ if (!text)
243
+ return;
244
+ const previous = runs[runs.length - 1];
245
+ if (previous?.bold === bold)
246
+ previous.text += text;
247
+ else
248
+ runs.push({ text, bold });
249
+ };
250
+ for (const match of line.matchAll(PANE_CONTROL)) {
251
+ take(line.slice(last, match.index));
252
+ last = match.index + match[0].length;
253
+ if (match[2] !== "m")
254
+ continue;
255
+ const params = (match[1] || "0").split(/[;:]/);
256
+ for (let i = 0; i < params.length; i++) {
257
+ const code = Number(params[i] || 0);
258
+ // Extended colors carry their own numbers: 38;5;1 is not bold.
259
+ if (code === 38 || code === 48 || code === 58) {
260
+ i += params[i + 1] === "5" ? 2 : params[i + 1] === "2" ? 4 : 0;
261
+ continue;
262
+ }
263
+ if (code === 1)
264
+ bold = true;
265
+ else if (code === 0 || code === 22)
266
+ bold = false;
267
+ }
268
+ }
269
+ take(line.slice(last));
270
+ return runs.map(({ text, bold }) => {
271
+ const core = text.trim();
272
+ if (!bold || !core)
273
+ return text;
274
+ const lead = text.slice(0, text.length - text.trimStart().length), trail = text.slice(text.trimEnd().length);
275
+ return `${lead}**${core}**${trail}`;
276
+ }).join("");
277
+ }
278
+ /** Older Codex rollouts may carry public text deltas between response items.
279
+ * Keep a bounded raw cursor, since history intentionally filters these out. */
280
+ export class CodexRolloutPreview {
281
+ revision;
282
+ cursor = 0;
283
+ startedAt;
284
+ text = "";
285
+ async read(file) {
286
+ return withTranscriptIndex(file, async (handle, index) => {
287
+ if (this.revision !== index.revision) {
288
+ this.cursor = Math.max(0, index.lines - 2_000);
289
+ this.startedAt = undefined;
290
+ this.text = "";
291
+ }
292
+ const rows = [];
293
+ for await (const row of index.rows(handle, index.lines, Math.max(this.cursor, index.lines - 2_000))) {
294
+ if (!row.bytes)
295
+ continue;
296
+ try {
297
+ rows.push(object(JSON.parse(row.bytes.toString())));
298
+ }
299
+ catch { /* Incomplete or malformed event. */ }
300
+ }
301
+ for (const raw of rows.reverse()) {
302
+ const payload = object(raw.payload), params = object(raw.params);
303
+ if (raw.type === "event_msg" && payload.type === "task_started") {
304
+ const time = payload.started_at;
305
+ this.startedAt = typeof raw.timestamp === "string" ? raw.timestamp
306
+ : typeof time === "number" ? new Date(time > 1e12 ? time : time * 1000).toISOString() : undefined;
307
+ this.text = "";
308
+ }
309
+ else if (raw.type === "event_msg" && ["task_complete", "task_completed", "turn_aborted", "task_aborted", "error"].includes(String(payload.type))) {
310
+ this.startedAt = undefined;
311
+ this.text = "";
312
+ }
313
+ else if (raw.type === "response_item" && payload.type === "message" && payload.role === "assistant")
314
+ this.text = "";
315
+ else if (this.startedAt && ((raw.type === "event_msg" && payload.type === "agent_message_delta" && payload.channel !== "analysis")
316
+ || (raw.method === "item/agentMessage/delta" && params.threadId !== undefined))) {
317
+ const delta = raw.method ? params.delta : payload.delta;
318
+ if (typeof delta === "string")
319
+ this.text = (this.text + delta).slice(0, MAX_TEXT);
320
+ }
321
+ }
322
+ this.cursor = index.lines;
323
+ this.revision = index.revision;
324
+ return this.startedAt && Number.isFinite(Date.parse(this.startedAt)) && this.text ? { turnStartedAt: this.startedAt, text: this.text } : null;
325
+ });
326
+ }
327
+ }
328
+ export async function readDeltaPreview(target, file, rollout) {
329
+ if (target.source === "codex")
330
+ return await codexThreadPreview(target.session)
331
+ ?? (file && rollout ? await rollout.read(file).catch(() => null) : null);
332
+ if (target.source !== "opencode" || !file)
333
+ return null;
334
+ try {
335
+ const handle = await open(file + ".preview.json", constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
336
+ let bytes;
337
+ try {
338
+ const stat = await handle.stat();
339
+ if (!stat.isFile() || stat.size > MAX_PREVIEW_BYTES)
340
+ return null;
341
+ // Bound the read too: the file can grow between stat and read.
342
+ const buffer = Buffer.alloc(MAX_PREVIEW_BYTES + 1);
343
+ const { bytesRead } = await handle.read(buffer, 0, buffer.length, 0);
344
+ if (bytesRead > MAX_PREVIEW_BYTES)
345
+ return null;
346
+ bytes = buffer.subarray(0, bytesRead);
347
+ }
348
+ finally {
349
+ await handle.close();
350
+ }
351
+ const value = object(JSON.parse(bytes.toString("utf8")));
352
+ if (typeof value.turnStartedAt !== "string" || !Number.isFinite(Date.parse(value.turnStartedAt))
353
+ || typeof value.text !== "string" || !value.text || value.text.length > MAX_TEXT)
354
+ return null;
355
+ return { turnStartedAt: value.turnStartedAt, text: value.text };
356
+ }
357
+ catch {
358
+ return null;
359
+ }
360
+ }
361
+ /** Socket-local, ephemeral state. It never writes transcript rows or advances
362
+ * the history cursor. Final rows bypass the text throttle and clear atomically. */
363
+ export class TranscriptPreviewStream {
364
+ target;
365
+ pane;
366
+ delta;
367
+ startedAt;
368
+ prompt = "";
369
+ landed = false;
370
+ ended = false;
371
+ /** Claude's own spinner word for the running turn, sent beside frames as
372
+ * `activityVerb` for older phones. */
373
+ verb;
374
+ /** The whole spinner line for the running turn, sent as `activity`;
375
+ * phones without it ignore the field. */
376
+ activity;
377
+ sentActivity = "";
378
+ lastRead = -Infinity;
379
+ lastSent = -Infinity;
380
+ current = null;
381
+ observedLine = -1;
382
+ wasWorking = false;
383
+ rollout = new CodexRolloutPreview();
384
+ constructor(target, pane = () => readPreviewPane(target), delta = file => readDeltaPreview(target, file, this.rollout)) {
385
+ this.target = target;
386
+ this.pane = pane;
387
+ this.delta = delta;
388
+ }
389
+ observe(entries, reset = false) {
390
+ if (reset) {
391
+ this.observedLine = -1;
392
+ this.startedAt = undefined;
393
+ this.landed = false;
394
+ this.ended = false;
395
+ this.wasWorking = false;
396
+ }
397
+ for (const { raw, line } of entries) {
398
+ if (line <= this.observedLine)
399
+ continue;
400
+ this.observedLine = line;
401
+ if (this.target.source === "codex") {
402
+ // Codex brackets a turn with task_started and task_complete; its
403
+ // delta source is only read between them.
404
+ const payload = object(raw.payload);
405
+ if (raw.type === "event_msg" && payload.type === "task_started")
406
+ this.ended = false;
407
+ else if (raw.type === "response_item" && payload.type === "message" && payload.role === "user")
408
+ this.ended = false;
409
+ else if (raw.type === "event_msg" && ["task_complete", "task_completed", "turn_aborted", "task_aborted"].includes(String(payload.type)))
410
+ this.ended = true;
411
+ continue;
412
+ }
413
+ if (this.target.source !== "claude")
414
+ continue;
415
+ const message = object(raw.message), blocks = objects(message.content);
416
+ if (raw.type === "user" && !raw.phrenQueued && !raw.isMeta && !blocks.some(b => b.type === "tool_result")) {
417
+ const prompt = typeof message.content === "string" ? message.content : blocks.filter(b => b.type === "text").map(b => String(b.text ?? "")).join("\n");
418
+ if (prompt.trim() && typeof raw.timestamp === "string" && Number.isFinite(Date.parse(raw.timestamp))) {
419
+ this.startedAt = raw.timestamp;
420
+ this.prompt = prompt;
421
+ this.landed = false;
422
+ this.ended = false;
423
+ this.wasWorking = false;
424
+ this.verb = undefined;
425
+ this.activity = undefined;
426
+ }
427
+ }
428
+ else if (this.startedAt && ((raw.type === "assistant" && message.stop_reason === "end_turn")
429
+ || (raw.type === "system" && raw.subtype === "turn_duration"))) {
430
+ // The transcript says the turn is over before the shared snapshot
431
+ // (up to 2.5 s old) stops saying "working": stop reading the pane now.
432
+ this.landed = true;
433
+ this.ended = true;
434
+ this.verb = undefined;
435
+ this.activity = undefined;
436
+ }
437
+ else if (this.startedAt && (raw.type === "assistant" || blocks.some(b => b.type === "tool_result")))
438
+ this.landed = true;
439
+ }
440
+ }
441
+ async update(status, file, now) {
442
+ const readAt = now ?? Date.now();
443
+ let next = null;
444
+ if (status === "working") {
445
+ this.wasWorking = true;
446
+ if (this.target.source === "codex" || this.target.source === "opencode") {
447
+ // These harnesses own a delta source. Never scrape their pane, even
448
+ // when the source is temporarily empty or unavailable.
449
+ if (!this.ended)
450
+ next = await this.delta(file);
451
+ }
452
+ else if (this.target.source === "claude" && this.startedAt && !this.ended) {
453
+ if (readAt - this.lastRead < PREVIEW_INTERVAL_MS)
454
+ return undefined;
455
+ this.lastRead = readAt;
456
+ // The reply text stops once a real entry lands; Claude's spinner
457
+ // verb keeps naming the work until the turn ends.
458
+ const pane = await this.pane();
459
+ const text = this.landed ? "" : claudePanePreview(pane, this.prompt, this.current?.turnStartedAt === this.startedAt ? this.current.text : "");
460
+ const spinner = claudeSpinner(pane);
461
+ if (spinner) {
462
+ this.activity = spinner;
463
+ this.verb = spinner.verb;
464
+ }
465
+ if (text)
466
+ next = { turnStartedAt: this.startedAt, text };
467
+ }
468
+ }
469
+ else if (this.target.source === "claude" && this.wasWorking) {
470
+ this.landed = true;
471
+ this.ended = true;
472
+ this.verb = undefined;
473
+ this.activity = undefined;
474
+ }
475
+ const sentAt = now ?? Date.now();
476
+ // The phone ticks the clock itself: only the verb, tokens and thinking
477
+ // state are worth a frame of their own.
478
+ const activity = this.activity ? JSON.stringify({ ...this.activity, elapsed: undefined }) : "";
479
+ const previewChanged = next?.text !== this.current?.text || next?.turnStartedAt !== this.current?.turnStartedAt;
480
+ const activityChanged = activity !== this.sentActivity;
481
+ if (!previewChanged && !activityChanged)
482
+ return undefined;
483
+ if ((next || !previewChanged) && sentAt - this.lastSent < PREVIEW_INTERVAL_MS)
484
+ return undefined;
485
+ this.current = next;
486
+ this.sentActivity = activity;
487
+ if (next || activityChanged)
488
+ this.lastSent = sentAt;
489
+ return { preview: next };
490
+ }
491
+ }
@@ -1,20 +1,83 @@
1
- import { type Json, type Provider } from "./protocol.js";
1
+ import { type Json, type Provider, type Target } from "./protocol.js";
2
+ import { type ChangeLookup } from "./changes.js";
3
+ export { isNarration, unwrapPastedContent } from "./transcript-claude.js";
4
+ export { codeToolCalls, projectCodexRow, type CodeToolCall } from "./transcript-codex.js";
2
5
  export interface Entry {
3
6
  line: number;
4
7
  raw: Json;
5
8
  }
9
+ export interface ChildAgentRelation {
10
+ /** `id` is a parent-scoped public reference; local session and transcript details never leave Hook. */
11
+ id: string;
12
+ session?: string;
13
+ transcript?: string;
14
+ provider: Provider;
15
+ path: string;
16
+ callId: string;
17
+ state: "running" | "completed" | "failed" | "unavailable";
18
+ /** Why a fan-out worker did not finish: `blocked: <type> <pattern>`. */
19
+ reason?: string;
20
+ finishedAt?: string;
21
+ /** Fan-out manifests and Claude child transcripts can name a model. */
22
+ model?: string;
23
+ fanout?: {
24
+ resumable: boolean;
25
+ };
26
+ /** Public checkout labels for fan-outs; full paths remain private. */
27
+ worktreeName?: string;
28
+ branch?: string;
29
+ /** The checkout a fan-out worker owns; parent-checkout children omit it. */
30
+ cwd?: string;
31
+ /** Remote rows carry only routing identities, never a local path. */
32
+ computer?: {
33
+ id: string;
34
+ name: string;
35
+ };
36
+ remote?: {
37
+ target: Target;
38
+ child?: string;
39
+ };
40
+ children: ChildAgentRelation[];
41
+ }
42
+ export interface LocalChildAgentRelation extends ChildAgentRelation {
43
+ session: string;
44
+ transcript: string;
45
+ remote?: undefined;
46
+ }
47
+ /** Provider-neutral child-agent discovery. Codex currently supplies explicit
48
+ * SubAgentActivity links; other providers return no children until their
49
+ * public transcript format exposes an equivalent relationship. */
50
+ export declare function childAgentTree(source: Provider, session: string, depth?: number, seen?: Set<string>, computer?: string): Promise<ChildAgentRelation[]>;
51
+ /** Explicit wire projection prevents a provider's private transcript identity
52
+ * from being returned if relation internals grow later. */
53
+ export declare function publicChildAgents(tree: ChildAgentRelation[]): Json[];
54
+ export declare function childAgent(tree: ChildAgentRelation[], id: string): LocalChildAgentRelation | undefined;
55
+ /**
56
+ * The phren store whose `.runtime/sessions` holds phren-agent event logs.
57
+ * `PHREN_PATH` or the shared `~/.phren` root — the two resolutions the CLI's
58
+ * `findPhrenPath` makes without a working directory, which a service has none
59
+ * of. Kept inline rather than importing phren-paths: that module drags in
60
+ * yaml and the data layer, and this bundle is budgeted for cold start.
61
+ */
62
+ export declare function phrenStoreRoot(env?: NodeJS.ProcessEnv): string;
6
63
  export declare function transcriptPath(source: Provider, session: string): Promise<string>;
64
+ /** Keeps a materialized Codex thread current before a read; a no-op for
65
+ * transcripts the agent writes itself. */
66
+ export declare function refreshTranscript(file: string, source: Provider, session: string): Promise<void>;
7
67
  /** Public conversation/tool events and real usage only. Never export private reasoning. */
8
- export declare function visibleEvent(raw: Json, source: Provider): Json | undefined;
68
+ export declare function visibleEvent(raw: Json, source: Provider, includeSidechain?: boolean, cwd?: string): Json | undefined;
9
69
  /** Parse only the requested page; shared byte indexes make reopening and
10
70
  * backward pagination independent of the amount of already-read history. */
11
71
  export declare class TranscriptReader {
12
72
  readonly file: string;
13
73
  readonly source: Provider;
14
74
  private readonly imageLine?;
75
+ private readonly changes?;
76
+ private readonly includeSidechain;
77
+ private readonly cwd?;
15
78
  private revision?;
16
79
  private nextLine;
17
- constructor(file: string, source: Provider, imageLine?: number | undefined);
80
+ constructor(file: string, source: Provider, imageLine?: number | undefined, changes?: ChangeLookup | undefined, includeSidechain?: boolean, cwd?: string | undefined);
18
81
  read(before?: number, signal?: AbortSignal): Promise<{
19
82
  entries: Entry[];
20
83
  totalLines: number;
@@ -22,5 +85,19 @@ export declare class TranscriptReader {
22
85
  hasMore: boolean;
23
86
  reset: boolean;
24
87
  }>;
88
+ /** Resume a fresh live reader after the last raw line the client retained. */
89
+ readAfter(afterLine: number, signal?: AbortSignal): Promise<{
90
+ entries: Entry[];
91
+ totalLines: number;
92
+ startLine: number;
93
+ hasMore: boolean;
94
+ reset: boolean;
95
+ }>;
96
+ private readPage;
25
97
  }
26
- export declare function historicalImage(file: string, line: number, block: number, source: Provider): Promise<Buffer>;
98
+ /** One embedded image: block `block` of the row's content — or, with
99
+ * `inner`, image `inner` inside that block's tool_result content (what a
100
+ * Read of a PNG returns). For Codex, an output row's array is the content. */
101
+ export declare function historicalImage(file: string, line: number, block: number, source: Provider, inner?: number): Promise<Buffer>;
102
+ /** Derive optional diff scope from local tool-call rows, never phone commands. */
103
+ export declare function conversationNamedPaths(file: string, source: Provider, cwd: string, signal?: AbortSignal): Promise<string[]>;