@north-light/cli 0.3.668 → 0.3.670

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 (1139) hide show
  1. package/dist/api/client.d.ts +8 -0
  2. package/dist/api/client.js +3 -3
  3. package/dist/api/contract.d.ts +1 -1
  4. package/dist/api/contract.js +1 -1
  5. package/dist/api/dto/docs.d.ts +1 -1
  6. package/dist/api/dto/imports.d.ts +5 -1
  7. package/dist/api/dto/objects.d.ts +2 -2
  8. package/dist/api/dto/profiles.d.ts +6 -2
  9. package/dist/api/dto/profiles.js +1 -1
  10. package/dist/api/dto/repo-import.d.ts +25 -0
  11. package/dist/api/dto/repo-import.js +0 -0
  12. package/dist/api/routes.d.ts +2 -0
  13. package/dist/api/routes.js +1 -1
  14. package/dist/builtin-memory/crouter-concepts/documents.md +1 -1
  15. package/dist/builtin-pi-packages/pi-crtr-extensions/extensions/claude-plugin-commands.ts +2 -1
  16. package/dist/clients/attach/session/profile-files.js +1 -1
  17. package/dist/clients/attach/viewer.js +479 -479
  18. package/dist/clients/dashboard/app.js +2 -2
  19. package/dist/commands/canvas/share.js +2 -2
  20. package/dist/commands/doc/shared.d.ts +1 -1
  21. package/dist/commands/doc/shared.js +1 -1
  22. package/dist/commands/node-lifecycle-revive.d.ts +10 -0
  23. package/dist/commands/node-lifecycle-revive.js +1 -1
  24. package/dist/commands/pkg/plugin-inspect.js +1 -1
  25. package/dist/commands/profile/list.js +1 -1
  26. package/dist/commands/profile/project.js +1 -1
  27. package/dist/commands/profile/show.js +1 -1
  28. package/dist/commands/sys/panels/profiles-panel.js +1 -1
  29. package/dist/commands/sys/repo-docs.d.ts +1 -0
  30. package/dist/commands/sys/repo-docs.js +2 -0
  31. package/dist/commands/sys/sync-project-guidance.js +5 -5
  32. package/dist/commands/sys.js +1 -1
  33. package/dist/core/broker-client/transport-relay.d.ts +3 -0
  34. package/dist/core/broker-client/transport-relay.js +1 -1
  35. package/dist/core/canvas/db.js +4 -4
  36. package/dist/core/canvas/export-sqlite.js +1 -1
  37. package/dist/core/canvas/schema-pg/021-repo-docs.sql +38 -0
  38. package/dist/core/canvas/schema-version.d.ts +1 -1
  39. package/dist/core/canvas/schema-version.js +1 -1
  40. package/dist/core/checkout-identities.d.ts +15 -0
  41. package/dist/core/checkout-identities.js +3 -0
  42. package/dist/core/graph/bodies-boot-copy.d.ts +1 -1
  43. package/dist/core/graph/bodies-boot-copy.js +1 -1
  44. package/dist/core/graph/custom.js +9 -9
  45. package/dist/core/graph/documents.d.ts +1 -1
  46. package/dist/core/graph/documents.js +11 -11
  47. package/dist/core/graph/events.js +1 -1
  48. package/dist/core/graph/group-invites.d.ts +10 -0
  49. package/dist/core/graph/group-invites.js +1 -0
  50. package/dist/core/graph/groups.d.ts +27 -0
  51. package/dist/core/graph/groups.js +3 -0
  52. package/dist/core/graph/kinds/owner.js +2 -2
  53. package/dist/core/graph/names.d.ts +2 -2
  54. package/dist/core/graph/names.js +10 -10
  55. package/dist/core/graph/objects.d.ts +4 -1
  56. package/dist/core/graph/objects.js +10 -10
  57. package/dist/core/graph/package-publish.js +3 -3
  58. package/dist/core/graph/package-reconcile.js +2 -2
  59. package/dist/core/graph/reader.d.ts +19 -8
  60. package/dist/core/graph/reader.js +3 -3
  61. package/dist/core/graph/repo-sync/exchange.d.ts +0 -11
  62. package/dist/core/graph/repo-sync/exchange.js +1 -2
  63. package/dist/core/graph/repo-sync/identity.d.ts +4 -0
  64. package/dist/core/graph/repo-sync/ref-format.d.ts +0 -29
  65. package/dist/core/graph/repo-sync/ref-format.js +1 -2
  66. package/dist/core/graph/repo-sync/repos.d.ts +12 -2
  67. package/dist/core/graph/repo-sync/repos.js +4 -3
  68. package/dist/core/graph/types.d.ts +2 -2
  69. package/dist/core/human/page-schema.d.ts +1 -1
  70. package/dist/core/import/export/stores.js +4 -1
  71. package/dist/core/import/load/stores.js +2 -2
  72. package/dist/core/peer/stubs.d.ts +1 -1
  73. package/dist/core/peer/stubs.js +1 -1
  74. package/dist/core/permissions/builtin.d.ts +1 -1
  75. package/dist/core/permissions/builtin.js +4 -2
  76. package/dist/core/permissions/ceiling.js +9 -9
  77. package/dist/core/profiles/manifest.d.ts +7 -2
  78. package/dist/core/profiles/manifest.js +1 -1
  79. package/dist/core/profiles/select.js +21 -21
  80. package/dist/core/runtime/bearings-render.js +8 -8
  81. package/dist/core/runtime/broker/bash-job-launch.d.ts +4 -0
  82. package/dist/core/runtime/broker/bash-job-launch.js +1 -1
  83. package/dist/core/runtime/deliver-live.js +1 -1
  84. package/dist/core/runtime/resume-root.d.ts +1 -0
  85. package/dist/core/runtime/resume-root.js +7 -7
  86. package/dist/core/runtime/runner/blaxel/runner.js +2 -2
  87. package/dist/core/runtime/runner/machine/call.js +2 -2
  88. package/dist/core/runtime/runner/machine/executor.d.ts +1 -1
  89. package/dist/core/runtime/runner/machine/ops.d.ts +11 -1
  90. package/dist/core/runtime/runner/machine/ops.js +1 -1
  91. package/dist/core/runtime/runner/types.d.ts +2 -1
  92. package/dist/core/scope.js +1 -1
  93. package/dist/core/scoped-state/db.js +2 -2
  94. package/dist/core/scoped-state/legacy-profiles.js +2 -1
  95. package/dist/core/scoped-state/person-rows.js +6 -3
  96. package/dist/core/scoped-state/schema.d.ts +4 -0
  97. package/dist/core/scoped-state/schema.js +5 -4
  98. package/dist/core/substrate/delivery/deliver.js +2 -2
  99. package/dist/core/substrate/delivery/plan.js +2 -3
  100. package/dist/core/substrate/subject.js +1 -1
  101. package/dist/daemon/api/canvas-host.d.ts +1 -0
  102. package/dist/daemon/api/canvas-host.js +1 -1
  103. package/dist/daemon/api/document-page.js +5 -5
  104. package/dist/daemon/api/handlers/broker-ops.js +1 -1
  105. package/dist/daemon/api/handlers/delivery.js +1 -1
  106. package/dist/daemon/api/handlers/docs.d.ts +1 -12
  107. package/dist/daemon/api/handlers/docs.js +2 -2
  108. package/dist/daemon/api/handlers/memory.js +1 -1
  109. package/dist/daemon/api/handlers/messages.js +2 -2
  110. package/dist/daemon/api/handlers/objects.js +1 -1
  111. package/dist/daemon/api/handlers/profiles.d.ts +1 -1
  112. package/dist/daemon/api/handlers/profiles.js +1 -1
  113. package/dist/daemon/api/handlers/repo-import.d.ts +2 -0
  114. package/dist/daemon/api/handlers/repo-import.js +2 -0
  115. package/dist/daemon/api/handlers/reviews.js +1 -1
  116. package/dist/daemon/api/handlers/shares.js +1 -1
  117. package/dist/daemon/api/operations.js +1 -1
  118. package/dist/daemon/api/reader.js +1 -1
  119. package/dist/daemon/api/repo-plugin.d.ts +12 -0
  120. package/dist/daemon/api/repo-plugin.js +1 -0
  121. package/dist/daemon/api/server.js +1 -1
  122. package/dist/daemon/boot-migrations.js +1 -1
  123. package/dist/daemon/crtrd.js +13 -13
  124. package/dist/daemon/due-sources.d.ts +1 -1
  125. package/dist/daemon/due-sources.js +1 -1
  126. package/dist/daemon/due.js +7 -7
  127. package/dist/daemon/machine-daemon.js +1 -1
  128. package/dist/daemon/reconcilers/group-invite-expiry.d.ts +9 -0
  129. package/dist/daemon/reconcilers/group-invite-expiry.js +1 -0
  130. package/dist/daemon/reconcilers/node-lifecycle/remote-wake.js +2 -1
  131. package/dist/daemon/review/finish.js +1 -1
  132. package/dist/migrations/004-canvas-documents/index.js +2 -2
  133. package/dist/pi-extensions/canvas-structured-output.js +6 -6
  134. package/dist/pi-extensions/canvas-tool-guide.d.ts +3 -1
  135. package/dist/pi-extensions/canvas-tool-guide.js +4 -4
  136. package/docs/concepts/documents.md +1 -1
  137. package/package.json +10 -2
  138. package/packages/crouter-api/dist/api/client.js +1585 -0
  139. package/packages/crouter-api/dist/api/command-manifest/index.js +4 -0
  140. package/packages/crouter-api/dist/api/command-manifest/manifest.js +332 -0
  141. package/packages/crouter-api/dist/api/command-manifest/object-kinds.js +100 -0
  142. package/packages/crouter-api/dist/api/command-manifest/result.js +166 -0
  143. package/packages/crouter-api/dist/api/command-manifest/schema.js +934 -0
  144. package/packages/crouter-api/dist/api/contract.js +57 -0
  145. package/packages/crouter-api/dist/api/dto/analytics.js +3 -0
  146. package/packages/crouter-api/dist/api/dto/attach.js +13 -0
  147. package/packages/crouter-api/dist/api/dto/bash-jobs.js +11 -0
  148. package/packages/crouter-api/dist/api/dto/bash.js +1 -0
  149. package/packages/crouter-api/dist/api/dto/broker-ops.js +6 -0
  150. package/packages/crouter-api/dist/api/dto/broker-signals.js +1 -0
  151. package/packages/crouter-api/dist/api/dto/broker.js +20 -0
  152. package/packages/crouter-api/dist/api/dto/canvas.js +2 -0
  153. package/packages/crouter-api/dist/api/dto/charges.js +4 -0
  154. package/packages/crouter-api/dist/api/dto/chat-inventory.js +11 -0
  155. package/packages/crouter-api/dist/api/dto/common.js +15 -0
  156. package/packages/crouter-api/dist/api/dto/config.js +3 -0
  157. package/packages/crouter-api/dist/api/dto/crons.js +10 -0
  158. package/packages/crouter-api/dist/api/dto/custom-objects.js +1 -0
  159. package/packages/crouter-api/dist/api/dto/delivery.js +7 -0
  160. package/packages/crouter-api/dist/api/dto/docs.js +8 -0
  161. package/packages/crouter-api/dist/api/dto/environments.js +2 -0
  162. package/packages/crouter-api/dist/api/dto/exec.js +1 -0
  163. package/packages/crouter-api/dist/api/dto/execution-start.js +2 -0
  164. package/packages/crouter-api/dist/api/dto/files.js +1 -0
  165. package/packages/crouter-api/dist/api/dto/focus.js +10 -0
  166. package/packages/crouter-api/dist/api/dto/grants.js +1 -0
  167. package/packages/crouter-api/dist/api/dto/health.js +2 -0
  168. package/packages/crouter-api/dist/api/dto/human-requests.js +4 -0
  169. package/packages/crouter-api/dist/api/dto/human.js +4 -0
  170. package/packages/crouter-api/dist/api/dto/imports.js +2 -0
  171. package/packages/crouter-api/dist/api/dto/inbox.js +4 -0
  172. package/packages/crouter-api/dist/api/dto/lifecycle.js +3 -0
  173. package/packages/crouter-api/dist/api/dto/limits.js +2 -0
  174. package/packages/crouter-api/dist/api/dto/mail.js +1 -0
  175. package/packages/crouter-api/dist/api/dto/messages.js +2 -0
  176. package/packages/crouter-api/dist/api/dto/model-config.js +1 -0
  177. package/packages/crouter-api/dist/api/dto/modelauth.js +4 -0
  178. package/packages/crouter-api/dist/api/dto/node-events.js +4 -0
  179. package/packages/crouter-api/dist/api/dto/node-outcomes.js +2 -0
  180. package/packages/crouter-api/dist/api/dto/node-records.js +5 -0
  181. package/packages/crouter-api/dist/api/dto/nodes.js +3 -0
  182. package/packages/crouter-api/dist/api/dto/objects.js +5 -0
  183. package/packages/crouter-api/dist/api/dto/permissions.js +5 -0
  184. package/packages/crouter-api/dist/api/dto/plugins.js +5 -0
  185. package/packages/crouter-api/dist/api/dto/profiles.js +8 -0
  186. package/packages/crouter-api/dist/api/dto/recovery.js +1 -0
  187. package/packages/crouter-api/dist/api/dto/repo-import.js +5 -0
  188. package/packages/crouter-api/dist/api/dto/reports.js +2 -0
  189. package/packages/crouter-api/dist/api/dto/review-comments.js +5 -0
  190. package/packages/crouter-api/dist/api/dto/reviews.js +5 -0
  191. package/packages/crouter-api/dist/api/dto/run-events.js +6 -0
  192. package/packages/crouter-api/dist/api/dto/settings.js +4 -0
  193. package/packages/crouter-api/dist/api/dto/structured-requests.js +5 -0
  194. package/packages/crouter-api/dist/api/dto/subscriptions.js +2 -0
  195. package/packages/crouter-api/dist/api/dto/usage.js +1 -0
  196. package/packages/crouter-api/dist/api/dto/worktree.js +6 -0
  197. package/packages/crouter-api/dist/api/error-codes.js +86 -0
  198. package/packages/crouter-api/dist/api/errors.js +72 -0
  199. package/packages/crouter-api/dist/api/index.js +55 -0
  200. package/packages/crouter-api/dist/api/long-poll.js +67 -0
  201. package/packages/crouter-api/dist/api/node-transport.js +105 -0
  202. package/packages/crouter-api/dist/api/plugin-manifest-schema.js +23 -0
  203. package/packages/crouter-api/dist/api/routes.js +233 -0
  204. package/packages/crouter-api/dist/api/runtime-version.js +50 -0
  205. package/packages/crouter-api/dist/build-root.js +411 -0
  206. package/packages/crouter-api/dist/clients/attach/ansi-cells.js +137 -0
  207. package/packages/crouter-api/dist/clients/attach/chrome/bash-jobs.js +34 -0
  208. package/packages/crouter-api/dist/clients/attach/chrome/canvas-panels.js +267 -0
  209. package/packages/crouter-api/dist/clients/attach/chrome/completion-bell.js +89 -0
  210. package/packages/crouter-api/dist/clients/attach/chrome/cron-wait.js +34 -0
  211. package/packages/crouter-api/dist/clients/attach/chrome/git-info.js +44 -0
  212. package/packages/crouter-api/dist/clients/attach/chrome/header.js +30 -0
  213. package/packages/crouter-api/dist/clients/attach/chrome/inbox-strip.js +219 -0
  214. package/packages/crouter-api/dist/clients/attach/chrome/key-hint.js +16 -0
  215. package/packages/crouter-api/dist/clients/attach/chrome/object-wait.js +24 -0
  216. package/packages/crouter-api/dist/clients/attach/chrome/recap.js +19 -0
  217. package/packages/crouter-api/dist/clients/attach/chrome/review-wait.js +22 -0
  218. package/packages/crouter-api/dist/clients/attach/chrome/roster.js +293 -0
  219. package/packages/crouter-api/dist/clients/attach/chrome/status-line.js +127 -0
  220. package/packages/crouter-api/dist/clients/attach/chrome/ticket-panel.js +261 -0
  221. package/packages/crouter-api/dist/clients/attach/chrome/widgets.js +51 -0
  222. package/packages/crouter-api/dist/clients/attach/command.js +107 -0
  223. package/packages/crouter-api/dist/clients/attach/config.js +275 -0
  224. package/packages/crouter-api/dist/clients/attach/input/capabilities.js +112 -0
  225. package/packages/crouter-api/dist/clients/attach/input/clipboard-image.js +237 -0
  226. package/packages/crouter-api/dist/clients/attach/input/completion-frecency.js +141 -0
  227. package/packages/crouter-api/dist/clients/attach/input/controller.js +383 -0
  228. package/packages/crouter-api/dist/clients/attach/input/overlay-owner.js +199 -0
  229. package/packages/crouter-api/dist/clients/attach/input/ref-autocomplete.js +176 -0
  230. package/packages/crouter-api/dist/clients/attach/input/titled-editor.js +859 -0
  231. package/packages/crouter-api/dist/clients/attach/overlays/auth.js +247 -0
  232. package/packages/crouter-api/dist/clients/attach/overlays/dialogs.js +102 -0
  233. package/packages/crouter-api/dist/clients/attach/overlays/file-review.js +146 -0
  234. package/packages/crouter-api/dist/clients/attach/overlays/graph.js +725 -0
  235. package/packages/crouter-api/dist/clients/attach/overlays/help.js +214 -0
  236. package/packages/crouter-api/dist/clients/attach/overlays/mcp.js +302 -0
  237. package/packages/crouter-api/dist/clients/attach/overlays/pickers.js +163 -0
  238. package/packages/crouter-api/dist/clients/attach/render/activity-slot.js +13 -0
  239. package/packages/crouter-api/dist/clients/attach/render/assistant-message.js +56 -0
  240. package/packages/crouter-api/dist/clients/attach/render/card-presentation.js +232 -0
  241. package/packages/crouter-api/dist/clients/attach/render/chat-view.js +2091 -0
  242. package/packages/crouter-api/dist/clients/attach/render/condensed-history.js +60 -0
  243. package/packages/crouter-api/dist/clients/attach/render/context-message.js +63 -0
  244. package/packages/crouter-api/dist/clients/attach/render/crtr-output.js +721 -0
  245. package/packages/crouter-api/dist/clients/attach/render/diagram.js +111 -0
  246. package/packages/crouter-api/dist/clients/attach/render/doc-links.js +78 -0
  247. package/packages/crouter-api/dist/clients/attach/render/edit-diff.js +304 -0
  248. package/packages/crouter-api/dist/clients/attach/render/glyph-codepoints.js +42 -0
  249. package/packages/crouter-api/dist/clients/attach/render/group-activity.js +276 -0
  250. package/packages/crouter-api/dist/clients/attach/render/group-recap.js +146 -0
  251. package/packages/crouter-api/dist/clients/attach/render/markdown-source.js +279 -0
  252. package/packages/crouter-api/dist/clients/attach/render/measured-container.js +322 -0
  253. package/packages/crouter-api/dist/clients/attach/render/page-block.js +187 -0
  254. package/packages/crouter-api/dist/clients/attach/render/scroll-animation.js +80 -0
  255. package/packages/crouter-api/dist/clients/attach/render/tool-calls.js +350 -0
  256. package/packages/crouter-api/dist/clients/attach/render/transcript-copy.js +81 -0
  257. package/packages/crouter-api/dist/clients/attach/render/transcript-search.js +152 -0
  258. package/packages/crouter-api/dist/clients/attach/render/viewport.js +184 -0
  259. package/packages/crouter-api/dist/clients/attach/session/banner.js +33 -0
  260. package/packages/crouter-api/dist/clients/attach/session/bindings.js +72 -0
  261. package/packages/crouter-api/dist/clients/attach/session/chrome-refresh.js +154 -0
  262. package/packages/crouter-api/dist/clients/attach/session/connection.js +204 -0
  263. package/packages/crouter-api/dist/clients/attach/session/context.js +16 -0
  264. package/packages/crouter-api/dist/clients/attach/session/document-links.js +48 -0
  265. package/packages/crouter-api/dist/clients/attach/session/editor-frame.js +142 -0
  266. package/packages/crouter-api/dist/clients/attach/session/editor-inventory.js +156 -0
  267. package/packages/crouter-api/dist/clients/attach/session/file-links.js +73 -0
  268. package/packages/crouter-api/dist/clients/attach/session/focus-events.js +12 -0
  269. package/packages/crouter-api/dist/clients/attach/session/frame.js +214 -0
  270. package/packages/crouter-api/dist/clients/attach/session/frames.js +203 -0
  271. package/packages/crouter-api/dist/clients/attach/session/identity.js +26 -0
  272. package/packages/crouter-api/dist/clients/attach/session/input-wiring.js +150 -0
  273. package/packages/crouter-api/dist/clients/attach/session/invariant.js +15 -0
  274. package/packages/crouter-api/dist/clients/attach/session/keys.js +77 -0
  275. package/packages/crouter-api/dist/clients/attach/session/layout.js +59 -0
  276. package/packages/crouter-api/dist/clients/attach/session/mouse.js +78 -0
  277. package/packages/crouter-api/dist/clients/attach/session/pane-focus.js +42 -0
  278. package/packages/crouter-api/dist/clients/attach/session/pane-tag.js +112 -0
  279. package/packages/crouter-api/dist/clients/attach/session/pi-assets.js +24 -0
  280. package/packages/crouter-api/dist/clients/attach/session/pi-oauth-flows.js +21 -0
  281. package/packages/crouter-api/dist/clients/attach/session/profile-files.js +208 -0
  282. package/packages/crouter-api/dist/clients/attach/session/readonly-popup.js +25 -0
  283. package/packages/crouter-api/dist/clients/attach/session/reconnect.js +195 -0
  284. package/packages/crouter-api/dist/clients/attach/session/selection.js +108 -0
  285. package/packages/crouter-api/dist/clients/attach/session/state-sync.js +67 -0
  286. package/packages/crouter-api/dist/clients/attach/session/surface-frame.js +73 -0
  287. package/packages/crouter-api/dist/clients/attach/session/surface-host.js +256 -0
  288. package/packages/crouter-api/dist/clients/attach/session/teardown.js +94 -0
  289. package/packages/crouter-api/dist/clients/attach/session/transcript-search.js +151 -0
  290. package/packages/crouter-api/dist/clients/attach/session/whip-achievements.js +145 -0
  291. package/packages/crouter-api/dist/clients/attach/session/whip.js +362 -0
  292. package/packages/crouter-api/dist/clients/attach/slash/dispatch.js +747 -0
  293. package/packages/crouter-api/dist/clients/attach/slash/prompt-preview.js +121 -0
  294. package/packages/crouter-api/dist/clients/attach/viewer.js +881 -0
  295. package/packages/crouter-api/dist/clients/conversation/projection.js +324 -0
  296. package/packages/crouter-api/dist/clients/conversation/submit.js +51 -0
  297. package/packages/crouter-api/dist/clients/dashboard/app.js +439 -0
  298. package/packages/crouter-api/dist/clients/dashboard/model.js +77 -0
  299. package/packages/crouter-api/dist/clients/dashboard/render.js +148 -0
  300. package/packages/crouter-api/dist/clients/inbox/controller.js +791 -0
  301. package/packages/crouter-api/dist/clients/inbox/dto-adapt.js +93 -0
  302. package/packages/crouter-api/dist/clients/inbox/layout.js +9 -0
  303. package/packages/crouter-api/dist/clients/inbox/page-adapter.js +56 -0
  304. package/packages/crouter-api/dist/clients/inbox/resolve.js +35 -0
  305. package/packages/crouter-api/dist/clients/inbox/review/anchors.js +89 -0
  306. package/packages/crouter-api/dist/clients/inbox/review/comments-client.js +103 -0
  307. package/packages/crouter-api/dist/clients/inbox/review/companion-pane.js +109 -0
  308. package/packages/crouter-api/dist/clients/inbox/review/document-surface.js +1268 -0
  309. package/packages/crouter-api/dist/clients/inbox/review/frame.js +309 -0
  310. package/packages/crouter-api/dist/clients/inbox/review/keys.js +133 -0
  311. package/packages/crouter-api/dist/clients/inbox/review/launch.js +170 -0
  312. package/packages/crouter-api/dist/clients/inbox/review/live-source.js +160 -0
  313. package/packages/crouter-api/dist/clients/inbox/review/nvim.js +43 -0
  314. package/packages/crouter-api/dist/clients/inbox/review/remap.js +157 -0
  315. package/packages/crouter-api/dist/clients/inbox/review/review-client.js +123 -0
  316. package/packages/crouter-api/dist/clients/inbox/review/roundtrip.js +41 -0
  317. package/packages/crouter-api/dist/clients/inbox/review/state.js +315 -0
  318. package/packages/crouter-api/dist/clients/inbox/review-adapter.js +43 -0
  319. package/packages/crouter-api/dist/clients/inbox/surface.js +190 -0
  320. package/packages/crouter-api/dist/clients/inbox/tui/ansi.js +321 -0
  321. package/packages/crouter-api/dist/clients/inbox/tui/input.js +392 -0
  322. package/packages/crouter-api/dist/clients/inbox/tui/keys.js +104 -0
  323. package/packages/crouter-api/dist/clients/inbox/tui/page-body.js +69 -0
  324. package/packages/crouter-api/dist/clients/inbox/tui/panel.js +92 -0
  325. package/packages/crouter-api/dist/clients/inbox/tui/render.js +389 -0
  326. package/packages/crouter-api/dist/clients/inbox/tui/slots.js +134 -0
  327. package/packages/crouter-api/dist/clients/inbox/tui/types.js +1 -0
  328. package/packages/crouter-api/dist/clients/inbox/tui.js +91 -0
  329. package/packages/crouter-api/dist/clients/surfaces/host.js +1 -0
  330. package/packages/crouter-api/dist/commands/api-client.js +438 -0
  331. package/packages/crouter-api/dist/commands/attention.js +215 -0
  332. package/packages/crouter-api/dist/commands/canvas/edges.js +41 -0
  333. package/packages/crouter-api/dist/commands/canvas/list.js +79 -0
  334. package/packages/crouter-api/dist/commands/canvas/read.js +95 -0
  335. package/packages/crouter-api/dist/commands/canvas/search.js +49 -0
  336. package/packages/crouter-api/dist/commands/canvas/share.js +80 -0
  337. package/packages/crouter-api/dist/commands/canvas/unwatch.js +42 -0
  338. package/packages/crouter-api/dist/commands/canvas/watch.js +63 -0
  339. package/packages/crouter-api/dist/commands/canvas-analytics/chart.js +124 -0
  340. package/packages/crouter-api/dist/commands/canvas-analytics/drilldown.js +96 -0
  341. package/packages/crouter-api/dist/commands/canvas-analytics/format.js +106 -0
  342. package/packages/crouter-api/dist/commands/canvas-analytics/graph-detail.js +307 -0
  343. package/packages/crouter-api/dist/commands/canvas-analytics/graphs.js +365 -0
  344. package/packages/crouter-api/dist/commands/canvas-analytics/memory.js +211 -0
  345. package/packages/crouter-api/dist/commands/canvas-analytics/overview.js +189 -0
  346. package/packages/crouter-api/dist/commands/canvas-analytics/shell.js +416 -0
  347. package/packages/crouter-api/dist/commands/canvas-analytics/time.js +228 -0
  348. package/packages/crouter-api/dist/commands/canvas-analytics/usage.js +305 -0
  349. package/packages/crouter-api/dist/commands/canvas-analytics/view.js +102 -0
  350. package/packages/crouter-api/dist/commands/canvas-analytics.js +28 -0
  351. package/packages/crouter-api/dist/commands/canvas-browse.js +71 -0
  352. package/packages/crouter-api/dist/commands/canvas-config.js +192 -0
  353. package/packages/crouter-api/dist/commands/canvas-history/grep.js +85 -0
  354. package/packages/crouter-api/dist/commands/canvas-history/read.js +48 -0
  355. package/packages/crouter-api/dist/commands/canvas-history/search.js +99 -0
  356. package/packages/crouter-api/dist/commands/canvas-history/shared.js +135 -0
  357. package/packages/crouter-api/dist/commands/canvas-history/stats.js +68 -0
  358. package/packages/crouter-api/dist/commands/canvas-history.js +29 -0
  359. package/packages/crouter-api/dist/commands/canvas-issue.js +148 -0
  360. package/packages/crouter-api/dist/commands/canvas-prune.js +111 -0
  361. package/packages/crouter-api/dist/commands/canvas-roster.js +69 -0
  362. package/packages/crouter-api/dist/commands/canvas-snapshot.js +34 -0
  363. package/packages/crouter-api/dist/commands/canvas-use.js +61 -0
  364. package/packages/crouter-api/dist/commands/canvas.js +57 -0
  365. package/packages/crouter-api/dist/commands/chord.js +242 -0
  366. package/packages/crouter-api/dist/commands/cron.js +541 -0
  367. package/packages/crouter-api/dist/commands/custom-object/ack.js +30 -0
  368. package/packages/crouter-api/dist/commands/custom-object/publish.js +39 -0
  369. package/packages/crouter-api/dist/commands/custom-object/receive.js +69 -0
  370. package/packages/crouter-api/dist/commands/custom-object/register.js +69 -0
  371. package/packages/crouter-api/dist/commands/custom-object/shared.js +14 -0
  372. package/packages/crouter-api/dist/commands/custom-object/unregister.js +26 -0
  373. package/packages/crouter-api/dist/commands/custom-object.js +21 -0
  374. package/packages/crouter-api/dist/commands/dashboard.js +86 -0
  375. package/packages/crouter-api/dist/commands/doc/delete.js +30 -0
  376. package/packages/crouter-api/dist/commands/doc/edit.js +83 -0
  377. package/packages/crouter-api/dist/commands/doc/history.js +38 -0
  378. package/packages/crouter-api/dist/commands/doc/lint.js +36 -0
  379. package/packages/crouter-api/dist/commands/doc/list.js +19 -0
  380. package/packages/crouter-api/dist/commands/doc/move.js +37 -0
  381. package/packages/crouter-api/dist/commands/doc/read.js +19 -0
  382. package/packages/crouter-api/dist/commands/doc/replace-blocks.js +40 -0
  383. package/packages/crouter-api/dist/commands/doc/shared.js +156 -0
  384. package/packages/crouter-api/dist/commands/doc/write.js +53 -0
  385. package/packages/crouter-api/dist/commands/doc.js +27 -0
  386. package/packages/crouter-api/dist/commands/human/components.js +78 -0
  387. package/packages/crouter-api/dist/commands/human/feedback.js +112 -0
  388. package/packages/crouter-api/dist/commands/human/prompts.js +326 -0
  389. package/packages/crouter-api/dist/commands/human/queue.js +191 -0
  390. package/packages/crouter-api/dist/commands/human/request.js +266 -0
  391. package/packages/crouter-api/dist/commands/human/review.js +288 -0
  392. package/packages/crouter-api/dist/commands/human/shared.js +67 -0
  393. package/packages/crouter-api/dist/commands/human.js +63 -0
  394. package/packages/crouter-api/dist/commands/node/bash.js +395 -0
  395. package/packages/crouter-api/dist/commands/node/create.js +363 -0
  396. package/packages/crouter-api/dist/commands/node/inspect.js +288 -0
  397. package/packages/crouter-api/dist/commands/node/lifecycle.js +577 -0
  398. package/packages/crouter-api/dist/commands/node/message.js +170 -0
  399. package/packages/crouter-api/dist/commands/node/outcome.js +133 -0
  400. package/packages/crouter-api/dist/commands/node/pyramid.js +79 -0
  401. package/packages/crouter-api/dist/commands/node/subscription.js +78 -0
  402. package/packages/crouter-api/dist/commands/node/wait.js +165 -0
  403. package/packages/crouter-api/dist/commands/node-context.js +145 -0
  404. package/packages/crouter-api/dist/commands/node-lifecycle-revive.js +224 -0
  405. package/packages/crouter-api/dist/commands/node-snapshot.js +37 -0
  406. package/packages/crouter-api/dist/commands/node-transcript.js +59 -0
  407. package/packages/crouter-api/dist/commands/node-worktree.js +138 -0
  408. package/packages/crouter-api/dist/commands/node.js +29 -0
  409. package/packages/crouter-api/dist/commands/person-settings.js +23 -0
  410. package/packages/crouter-api/dist/commands/pkg/app-installs.js +125 -0
  411. package/packages/crouter-api/dist/commands/pkg/browse/actions.js +198 -0
  412. package/packages/crouter-api/dist/commands/pkg/browse/catalog.js +461 -0
  413. package/packages/crouter-api/dist/commands/pkg/browse/command-view.js +217 -0
  414. package/packages/crouter-api/dist/commands/pkg/browse/detail-panel.js +402 -0
  415. package/packages/crouter-api/dist/commands/pkg/browse/doc-view.js +84 -0
  416. package/packages/crouter-api/dist/commands/pkg/browse/list-panel.js +168 -0
  417. package/packages/crouter-api/dist/commands/pkg/browse/model.js +36 -0
  418. package/packages/crouter-api/dist/commands/pkg/browse/shell.js +640 -0
  419. package/packages/crouter-api/dist/commands/pkg/browse.js +27 -0
  420. package/packages/crouter-api/dist/commands/pkg/market-inspect.js +145 -0
  421. package/packages/crouter-api/dist/commands/pkg/market-manage.js +340 -0
  422. package/packages/crouter-api/dist/commands/pkg/market.js +14 -0
  423. package/packages/crouter-api/dist/commands/pkg/plugin-env.js +65 -0
  424. package/packages/crouter-api/dist/commands/pkg/plugin-inspect.js +178 -0
  425. package/packages/crouter-api/dist/commands/pkg/plugin-manage.js +1039 -0
  426. package/packages/crouter-api/dist/commands/pkg/plugin.js +14 -0
  427. package/packages/crouter-api/dist/commands/pkg/shared.js +62 -0
  428. package/packages/crouter-api/dist/commands/pkg.js +21 -0
  429. package/packages/crouter-api/dist/commands/profile/daemon-profiles.js +38 -0
  430. package/packages/crouter-api/dist/commands/profile/default.js +183 -0
  431. package/packages/crouter-api/dist/commands/profile/delete.js +66 -0
  432. package/packages/crouter-api/dist/commands/profile/env.js +188 -0
  433. package/packages/crouter-api/dist/commands/profile/environment.js +88 -0
  434. package/packages/crouter-api/dist/commands/profile/kind.js +27 -0
  435. package/packages/crouter-api/dist/commands/profile/list.js +45 -0
  436. package/packages/crouter-api/dist/commands/profile/meta.js +65 -0
  437. package/packages/crouter-api/dist/commands/profile/new.js +107 -0
  438. package/packages/crouter-api/dist/commands/profile/pause.js +59 -0
  439. package/packages/crouter-api/dist/commands/profile/project.js +146 -0
  440. package/packages/crouter-api/dist/commands/profile/rename.js +41 -0
  441. package/packages/crouter-api/dist/commands/profile/show.js +55 -0
  442. package/packages/crouter-api/dist/commands/profile.js +36 -0
  443. package/packages/crouter-api/dist/commands/push.js +357 -0
  444. package/packages/crouter-api/dist/commands/revive.js +183 -0
  445. package/packages/crouter-api/dist/commands/surface/node/cycle.js +83 -0
  446. package/packages/crouter-api/dist/commands/surface/node/focus.js +60 -0
  447. package/packages/crouter-api/dist/commands/surface/node/id.js +38 -0
  448. package/packages/crouter-api/dist/commands/surface/node/pin.js +42 -0
  449. package/packages/crouter-api/dist/commands/surface/node/placement.js +49 -0
  450. package/packages/crouter-api/dist/commands/surface-dashboard.js +138 -0
  451. package/packages/crouter-api/dist/commands/surface-edit.js +157 -0
  452. package/packages/crouter-api/dist/commands/surface-inbox.js +98 -0
  453. package/packages/crouter-api/dist/commands/surface-inspect.js +41 -0
  454. package/packages/crouter-api/dist/commands/surface-node.js +19 -0
  455. package/packages/crouter-api/dist/commands/surface-reload.js +129 -0
  456. package/packages/crouter-api/dist/commands/surface-tmux-spread.js +214 -0
  457. package/packages/crouter-api/dist/commands/surface.js +29 -0
  458. package/packages/crouter-api/dist/commands/sys/branch.js +19 -0
  459. package/packages/crouter-api/dist/commands/sys/config.js +353 -0
  460. package/packages/crouter-api/dist/commands/sys/connect.js +185 -0
  461. package/packages/crouter-api/dist/commands/sys/context/admin/actions.js +89 -0
  462. package/packages/crouter-api/dist/commands/sys/context/admin/detail-panel.js +233 -0
  463. package/packages/crouter-api/dist/commands/sys/context/admin/docs-panel.js +185 -0
  464. package/packages/crouter-api/dist/commands/sys/context/admin/list-view.js +170 -0
  465. package/packages/crouter-api/dist/commands/sys/context/admin/model.js +179 -0
  466. package/packages/crouter-api/dist/commands/sys/context/admin/rail-panel.js +229 -0
  467. package/packages/crouter-api/dist/commands/sys/context/admin/read-view.js +172 -0
  468. package/packages/crouter-api/dist/commands/sys/context/admin/shell.js +870 -0
  469. package/packages/crouter-api/dist/commands/sys/context/admin.js +148 -0
  470. package/packages/crouter-api/dist/commands/sys/context/doc.js +126 -0
  471. package/packages/crouter-api/dist/commands/sys/context/expose.js +66 -0
  472. package/packages/crouter-api/dist/commands/sys/context/prompt-review.js +244 -0
  473. package/packages/crouter-api/dist/commands/sys/context/resolve.js +326 -0
  474. package/packages/crouter-api/dist/commands/sys/context/sysprompt.js +95 -0
  475. package/packages/crouter-api/dist/commands/sys/context.js +21 -0
  476. package/packages/crouter-api/dist/commands/sys/daemon.js +351 -0
  477. package/packages/crouter-api/dist/commands/sys/db.js +69 -0
  478. package/packages/crouter-api/dist/commands/sys/desktop.js +201 -0
  479. package/packages/crouter-api/dist/commands/sys/doctor.js +633 -0
  480. package/packages/crouter-api/dist/commands/sys/env.js +39 -0
  481. package/packages/crouter-api/dist/commands/sys/feedback.js +228 -0
  482. package/packages/crouter-api/dist/commands/sys/import/move.js +393 -0
  483. package/packages/crouter-api/dist/commands/sys/import/resume.js +23 -0
  484. package/packages/crouter-api/dist/commands/sys/import/start.js +92 -0
  485. package/packages/crouter-api/dist/commands/sys/join.js +85 -0
  486. package/packages/crouter-api/dist/commands/sys/limits.js +133 -0
  487. package/packages/crouter-api/dist/commands/sys/logs.js +129 -0
  488. package/packages/crouter-api/dist/commands/sys/machine/rotate.js +49 -0
  489. package/packages/crouter-api/dist/commands/sys/migrate.js +79 -0
  490. package/packages/crouter-api/dist/commands/sys/panels/broker-limits-panel.js +110 -0
  491. package/packages/crouter-api/dist/commands/sys/panels/dependencies-panel.js +80 -0
  492. package/packages/crouter-api/dist/commands/sys/panels/keybindings-panel.js +703 -0
  493. package/packages/crouter-api/dist/commands/sys/panels/models-panel.js +1160 -0
  494. package/packages/crouter-api/dist/commands/sys/panels/plugin-env-panel.js +70 -0
  495. package/packages/crouter-api/dist/commands/sys/panels/plugins-panel.js +87 -0
  496. package/packages/crouter-api/dist/commands/sys/panels/prefs-panel.js +97 -0
  497. package/packages/crouter-api/dist/commands/sys/panels/profiles-panel.js +656 -0
  498. package/packages/crouter-api/dist/commands/sys/panels/provider-panel.js +534 -0
  499. package/packages/crouter-api/dist/commands/sys/panels/terminal-panel.js +67 -0
  500. package/packages/crouter-api/dist/commands/sys/provider-login.js +99 -0
  501. package/packages/crouter-api/dist/commands/sys/repo-docs.js +96 -0
  502. package/packages/crouter-api/dist/commands/sys/retry-delivery.js +33 -0
  503. package/packages/crouter-api/dist/commands/sys/settings-shell.js +400 -0
  504. package/packages/crouter-api/dist/commands/sys/settings.js +46 -0
  505. package/packages/crouter-api/dist/commands/sys/setup-core.js +890 -0
  506. package/packages/crouter-api/dist/commands/sys/setup-settings-runner.js +15 -0
  507. package/packages/crouter-api/dist/commands/sys/setup-wizard.js +351 -0
  508. package/packages/crouter-api/dist/commands/sys/setup.js +41 -0
  509. package/packages/crouter-api/dist/commands/sys/shared.js +81 -0
  510. package/packages/crouter-api/dist/commands/sys/signin.js +149 -0
  511. package/packages/crouter-api/dist/commands/sys/spaces.js +22 -0
  512. package/packages/crouter-api/dist/commands/sys/spend.js +144 -0
  513. package/packages/crouter-api/dist/commands/sys/support/prepare.js +239 -0
  514. package/packages/crouter-api/dist/commands/sys/support/submit.js +524 -0
  515. package/packages/crouter-api/dist/commands/sys/support.js +18 -0
  516. package/packages/crouter-api/dist/commands/sys/sync-deps.js +445 -0
  517. package/packages/crouter-api/dist/commands/sys/sync-project-guidance.js +320 -0
  518. package/packages/crouter-api/dist/commands/sys/sync-shared.js +139 -0
  519. package/packages/crouter-api/dist/commands/sys/sync-skills.js +297 -0
  520. package/packages/crouter-api/dist/commands/sys/sync.js +17 -0
  521. package/packages/crouter-api/dist/commands/sys/terminal-option.js +542 -0
  522. package/packages/crouter-api/dist/commands/sys/tutorial/branch.js +15 -0
  523. package/packages/crouter-api/dist/commands/sys/tutorial/lessons.js +107 -0
  524. package/packages/crouter-api/dist/commands/sys/tutorial/scenario.js +431 -0
  525. package/packages/crouter-api/dist/commands/sys/tutorial/tracks.js +96 -0
  526. package/packages/crouter-api/dist/commands/sys/update.js +157 -0
  527. package/packages/crouter-api/dist/commands/sys/worktrees.js +53 -0
  528. package/packages/crouter-api/dist/commands/sys.js +32 -0
  529. package/packages/crouter-api/dist/core/activity-signal.js +38 -0
  530. package/packages/crouter-api/dist/core/asset-root.js +18 -0
  531. package/packages/crouter-api/dist/core/async-array.js +48 -0
  532. package/packages/crouter-api/dist/core/auth-file.js +89 -0
  533. package/packages/crouter-api/dist/core/auth-interaction.js +94 -0
  534. package/packages/crouter-api/dist/core/bash-guard.js +527 -0
  535. package/packages/crouter-api/dist/core/bash-job-supervisor.js +157 -0
  536. package/packages/crouter-api/dist/core/bash-jobs.js +460 -0
  537. package/packages/crouter-api/dist/core/blobs/directory.js +264 -0
  538. package/packages/crouter-api/dist/core/blobs/fault.js +6 -0
  539. package/packages/crouter-api/dist/core/blobs/index.js +30 -0
  540. package/packages/crouter-api/dist/core/blobs/r2.js +169 -0
  541. package/packages/crouter-api/dist/core/broker-client/client.js +184 -0
  542. package/packages/crouter-api/dist/core/broker-client/index.js +14 -0
  543. package/packages/crouter-api/dist/core/broker-client/transport-relay.js +186 -0
  544. package/packages/crouter-api/dist/core/broker-client/transport-socket.js +187 -0
  545. package/packages/crouter-api/dist/core/broker-client/transport.js +40 -0
  546. package/packages/crouter-api/dist/core/canvas/app-run.js +4 -0
  547. package/packages/crouter-api/dist/core/canvas/attention.js +47 -0
  548. package/packages/crouter-api/dist/core/canvas/boot-id.js +26 -0
  549. package/packages/crouter-api/dist/core/canvas/browse/app.js +1050 -0
  550. package/packages/crouter-api/dist/core/canvas/browse/model.js +477 -0
  551. package/packages/crouter-api/dist/core/canvas/browse/pins.js +29 -0
  552. package/packages/crouter-api/dist/core/canvas/browse/render.js +1058 -0
  553. package/packages/crouter-api/dist/core/canvas/canvas.js +1225 -0
  554. package/packages/crouter-api/dist/core/canvas/crons.js +541 -0
  555. package/packages/crouter-api/dist/core/canvas/daemon-actions.js +98 -0
  556. package/packages/crouter-api/dist/core/canvas/db.js +429 -0
  557. package/packages/crouter-api/dist/core/canvas/deliveries.js +398 -0
  558. package/packages/crouter-api/dist/core/canvas/delivery-contract.js +30 -0
  559. package/packages/crouter-api/dist/core/canvas/executions.js +279 -0
  560. package/packages/crouter-api/dist/core/canvas/extensions.js +90 -0
  561. package/packages/crouter-api/dist/core/canvas/focuses.js +82 -0
  562. package/packages/crouter-api/dist/core/canvas/history.js +480 -0
  563. package/packages/crouter-api/dist/core/canvas/index.js +16 -0
  564. package/packages/crouter-api/dist/core/canvas/install-id.js +64 -0
  565. package/packages/crouter-api/dist/core/canvas/labels.js +43 -0
  566. package/packages/crouter-api/dist/core/canvas/legacy-person.js +4 -0
  567. package/packages/crouter-api/dist/core/canvas/memory-reads.js +37 -0
  568. package/packages/crouter-api/dist/core/canvas/meta-file.js +89 -0
  569. package/packages/crouter-api/dist/core/canvas/nav-render.js +224 -0
  570. package/packages/crouter-api/dist/core/canvas/node-agent-paths.js +30 -0
  571. package/packages/crouter-api/dist/core/canvas/node-order.js +37 -0
  572. package/packages/crouter-api/dist/core/canvas/node-recap.js +62 -0
  573. package/packages/crouter-api/dist/core/canvas/node-tokens.js +53 -0
  574. package/packages/crouter-api/dist/core/canvas/outcome-actions.js +71 -0
  575. package/packages/crouter-api/dist/core/canvas/paths.js +167 -0
  576. package/packages/crouter-api/dist/core/canvas/person-state.js +41 -0
  577. package/packages/crouter-api/dist/core/canvas/person.js +251 -0
  578. package/packages/crouter-api/dist/core/canvas/pid.js +977 -0
  579. package/packages/crouter-api/dist/core/canvas/reconciler-leases.js +40 -0
  580. package/packages/crouter-api/dist/core/canvas/recovery.js +715 -0
  581. package/packages/crouter-api/dist/core/canvas/remote-canvas-source.js +290 -0
  582. package/packages/crouter-api/dist/core/canvas/remote-transport.js +57 -0
  583. package/packages/crouter-api/dist/core/canvas/render-source.js +518 -0
  584. package/packages/crouter-api/dist/core/canvas/schema-chain.js +110 -0
  585. package/packages/crouter-api/dist/core/canvas/schema-version.js +58 -0
  586. package/packages/crouter-api/dist/core/canvas/sessions.js +128 -0
  587. package/packages/crouter-api/dist/core/canvas/source.js +57 -0
  588. package/packages/crouter-api/dist/core/canvas/status-glyph.js +132 -0
  589. package/packages/crouter-api/dist/core/canvas/structured-requests.js +176 -0
  590. package/packages/crouter-api/dist/core/canvas/telemetry.js +35 -0
  591. package/packages/crouter-api/dist/core/canvas/tree.js +128 -0
  592. package/packages/crouter-api/dist/core/canvas/types.js +6 -0
  593. package/packages/crouter-api/dist/core/canvas/waits.js +113 -0
  594. package/packages/crouter-api/dist/core/canvas/worktrees.js +97 -0
  595. package/packages/crouter-api/dist/core/checkout-identities.js +88 -0
  596. package/packages/crouter-api/dist/core/clipboard-text.js +57 -0
  597. package/packages/crouter-api/dist/core/command-hooks/artifact.js +145 -0
  598. package/packages/crouter-api/dist/core/command-hooks/catalog.js +38 -0
  599. package/packages/crouter-api/dist/core/command-hooks/compose.js +101 -0
  600. package/packages/crouter-api/dist/core/command-hooks/discovery.js +246 -0
  601. package/packages/crouter-api/dist/core/command-hooks/help.js +18 -0
  602. package/packages/crouter-api/dist/core/command-hooks/lifecycle-catalog.js +9 -0
  603. package/packages/crouter-api/dist/core/command-hooks/lifecycle-create.js +51 -0
  604. package/packages/crouter-api/dist/core/command-hooks/report.js +28 -0
  605. package/packages/crouter-api/dist/core/command-hooks/schema.js +157 -0
  606. package/packages/crouter-api/dist/core/command-hooks/transport/exec-invoke.js +315 -0
  607. package/packages/crouter-api/dist/core/command-hooks/transport/exec-lifecycle.js +248 -0
  608. package/packages/crouter-api/dist/core/command-hooks/transport/plan.js +30 -0
  609. package/packages/crouter-api/dist/core/command-manifests/registry.js +118 -0
  610. package/packages/crouter-api/dist/core/command-plugins/bundle.js +604 -0
  611. package/packages/crouter-api/dist/core/command-plugins/caller-header.js +15 -0
  612. package/packages/crouter-api/dist/core/command-plugins/compose.js +243 -0
  613. package/packages/crouter-api/dist/core/command-plugins/discovery.js +240 -0
  614. package/packages/crouter-api/dist/core/command-plugins/endpoint.js +60 -0
  615. package/packages/crouter-api/dist/core/command-plugins/extensions.js +166 -0
  616. package/packages/crouter-api/dist/core/command-plugins/help-addenda.js +55 -0
  617. package/packages/crouter-api/dist/core/command-plugins/presence.js +36 -0
  618. package/packages/crouter-api/dist/core/command-plugins/transport/exec-invoke.js +138 -0
  619. package/packages/crouter-api/dist/core/command-plugins/transport/http-fetch.js +68 -0
  620. package/packages/crouter-api/dist/core/command-plugins/transport/http-invoke.js +333 -0
  621. package/packages/crouter-api/dist/core/command-plugins/transport/http-plan.js +349 -0
  622. package/packages/crouter-api/dist/core/command-plugins/transport/sign.js +115 -0
  623. package/packages/crouter-api/dist/core/command.js +848 -0
  624. package/packages/crouter-api/dist/core/config.js +1154 -0
  625. package/packages/crouter-api/dist/core/conversation-store/client.js +111 -0
  626. package/packages/crouter-api/dist/core/conversation-store/index.js +62 -0
  627. package/packages/crouter-api/dist/core/conversation-store/patch.js +192 -0
  628. package/packages/crouter-api/dist/core/conversation-store/repair.js +84 -0
  629. package/packages/crouter-api/dist/core/conversation-store/row-store.js +365 -0
  630. package/packages/crouter-api/dist/core/directory/issuer.js +15 -0
  631. package/packages/crouter-api/dist/core/directory/join-lock.js +61 -0
  632. package/packages/crouter-api/dist/core/directory/join.js +218 -0
  633. package/packages/crouter-api/dist/core/directory/person-credential.js +220 -0
  634. package/packages/crouter-api/dist/core/directory/reach.js +19 -0
  635. package/packages/crouter-api/dist/core/document-lines.js +6 -0
  636. package/packages/crouter-api/dist/core/editor-resolver.js +77 -0
  637. package/packages/crouter-api/dist/core/env-name.js +25 -0
  638. package/packages/crouter-api/dist/core/environment-recipe.js +59 -0
  639. package/packages/crouter-api/dist/core/environments.js +59 -0
  640. package/packages/crouter-api/dist/core/errors.js +90 -0
  641. package/packages/crouter-api/dist/core/events/emit.js +44 -0
  642. package/packages/crouter-api/dist/core/events/envelope.js +84 -0
  643. package/packages/crouter-api/dist/core/events/errors.js +69 -0
  644. package/packages/crouter-api/dist/core/events/operation-id.js +24 -0
  645. package/packages/crouter-api/dist/core/events/outbound.js +92 -0
  646. package/packages/crouter-api/dist/core/events/read.js +625 -0
  647. package/packages/crouter-api/dist/core/events/serialize.js +199 -0
  648. package/packages/crouter-api/dist/core/events/source.js +31 -0
  649. package/packages/crouter-api/dist/core/events/types.js +11 -0
  650. package/packages/crouter-api/dist/core/exclusive-lock.js +197 -0
  651. package/packages/crouter-api/dist/core/fault-classifier.js +101 -0
  652. package/packages/crouter-api/dist/core/feed/feed.js +190 -0
  653. package/packages/crouter-api/dist/core/feed/inbox.js +93 -0
  654. package/packages/crouter-api/dist/core/feed/messages.js +219 -0
  655. package/packages/crouter-api/dist/core/feed/reports.js +58 -0
  656. package/packages/crouter-api/dist/core/frontmatter.js +35 -0
  657. package/packages/crouter-api/dist/core/fs-utils.js +263 -0
  658. package/packages/crouter-api/dist/core/git.js +103 -0
  659. package/packages/crouter-api/dist/core/grants/cover.js +66 -0
  660. package/packages/crouter-api/dist/core/grants/hosted-endpoint.js +70 -0
  661. package/packages/crouter-api/dist/core/grants/local.js +26 -0
  662. package/packages/crouter-api/dist/core/grants/mirror.js +464 -0
  663. package/packages/crouter-api/dist/core/grants/on-sync.js +163 -0
  664. package/packages/crouter-api/dist/core/grants/sandboxes.js +24 -0
  665. package/packages/crouter-api/dist/core/grants/sync.js +216 -0
  666. package/packages/crouter-api/dist/core/grants/terminal.js +25 -0
  667. package/packages/crouter-api/dist/core/graph/access.js +37 -0
  668. package/packages/crouter-api/dist/core/graph/bodies.js +68 -0
  669. package/packages/crouter-api/dist/core/graph/custom.js +298 -0
  670. package/packages/crouter-api/dist/core/graph/deletion.js +115 -0
  671. package/packages/crouter-api/dist/core/graph/documents.js +675 -0
  672. package/packages/crouter-api/dist/core/graph/edges.js +83 -0
  673. package/packages/crouter-api/dist/core/graph/events.js +432 -0
  674. package/packages/crouter-api/dist/core/graph/exposures.js +164 -0
  675. package/packages/crouter-api/dist/core/graph/jobs.js +184 -0
  676. package/packages/crouter-api/dist/core/graph/kinds/action.js +20 -0
  677. package/packages/crouter-api/dist/core/graph/kinds/custom.js +25 -0
  678. package/packages/crouter-api/dist/core/graph/kinds/document.js +132 -0
  679. package/packages/crouter-api/dist/core/graph/kinds/dto.js +20 -0
  680. package/packages/crouter-api/dist/core/graph/kinds/environment.js +21 -0
  681. package/packages/crouter-api/dist/core/graph/kinds/job.js +24 -0
  682. package/packages/crouter-api/dist/core/graph/kinds/kind.js +15 -0
  683. package/packages/crouter-api/dist/core/graph/kinds/live-read.js +11 -0
  684. package/packages/crouter-api/dist/core/graph/kinds/node.js +87 -0
  685. package/packages/crouter-api/dist/core/graph/kinds/owner.js +26 -0
  686. package/packages/crouter-api/dist/core/graph/kinds/registry.js +58 -0
  687. package/packages/crouter-api/dist/core/graph/kinds/render.js +17 -0
  688. package/packages/crouter-api/dist/core/graph/names.js +239 -0
  689. package/packages/crouter-api/dist/core/graph/objects.js +292 -0
  690. package/packages/crouter-api/dist/core/graph/package-docs.js +148 -0
  691. package/packages/crouter-api/dist/core/graph/package-files.js +146 -0
  692. package/packages/crouter-api/dist/core/graph/package-publish.js +158 -0
  693. package/packages/crouter-api/dist/core/graph/package-reconcile.js +99 -0
  694. package/packages/crouter-api/dist/core/graph/reader.js +284 -0
  695. package/packages/crouter-api/dist/core/graph/receiver-url.js +83 -0
  696. package/packages/crouter-api/dist/core/graph/receivers.js +66 -0
  697. package/packages/crouter-api/dist/core/graph/repo-sync/identity.js +147 -0
  698. package/packages/crouter-api/dist/core/graph/repo-sync/repos.js +94 -0
  699. package/packages/crouter-api/dist/core/graph/rules.js +144 -0
  700. package/packages/crouter-api/dist/core/graph/types.js +10 -0
  701. package/packages/crouter-api/dist/core/graph/watches.js +223 -0
  702. package/packages/crouter-api/dist/core/help.js +445 -0
  703. package/packages/crouter-api/dist/core/human/action-binding.js +41 -0
  704. package/packages/crouter-api/dist/core/human/answer-text.js +100 -0
  705. package/packages/crouter-api/dist/core/human/answer.js +119 -0
  706. package/packages/crouter-api/dist/core/human/completion.js +27 -0
  707. package/packages/crouter-api/dist/core/human/component-docs.js +442 -0
  708. package/packages/crouter-api/dist/core/human/convention.js +75 -0
  709. package/packages/crouter-api/dist/core/human/feedback-companion.js +92 -0
  710. package/packages/crouter-api/dist/core/human/feedback.js +88 -0
  711. package/packages/crouter-api/dist/core/human/page-authoring.js +19 -0
  712. package/packages/crouter-api/dist/core/human/page-catalog.js +172 -0
  713. package/packages/crouter-api/dist/core/human/page-errors.js +14 -0
  714. package/packages/crouter-api/dist/core/human/page-eval.js +125 -0
  715. package/packages/crouter-api/dist/core/human/page-html-markdown.js +260 -0
  716. package/packages/crouter-api/dist/core/human/page-markdown.js +295 -0
  717. package/packages/crouter-api/dist/core/human/page-schema.js +381 -0
  718. package/packages/crouter-api/dist/core/human/page.js +251 -0
  719. package/packages/crouter-api/dist/core/human/request-files.js +54 -0
  720. package/packages/crouter-api/dist/core/human/requests.js +647 -0
  721. package/packages/crouter-api/dist/core/human/root.js +11 -0
  722. package/packages/crouter-api/dist/core/human/summary.js +5 -0
  723. package/packages/crouter-api/dist/core/human/tickets.js +175 -0
  724. package/packages/crouter-api/dist/core/human/types.js +1 -0
  725. package/packages/crouter-api/dist/core/human/visible-paths.js +74 -0
  726. package/packages/crouter-api/dist/core/human-actions.js +101 -0
  727. package/packages/crouter-api/dist/core/import/bundle/blob-keys.js +25 -0
  728. package/packages/crouter-api/dist/core/import/bundle/layout.js +111 -0
  729. package/packages/crouter-api/dist/core/import/export/archive.js +22 -0
  730. package/packages/crouter-api/dist/core/import/export/cloud.js +164 -0
  731. package/packages/crouter-api/dist/core/import/export/dump.js +245 -0
  732. package/packages/crouter-api/dist/core/import/export/files.js +169 -0
  733. package/packages/crouter-api/dist/core/import/export/inline.js +15 -0
  734. package/packages/crouter-api/dist/core/import/export/source.js +5 -0
  735. package/packages/crouter-api/dist/core/import/export/stores.js +73 -0
  736. package/packages/crouter-api/dist/core/import/load/catalog.js +70 -0
  737. package/packages/crouter-api/dist/core/import/load/copy.js +132 -0
  738. package/packages/crouter-api/dist/core/import/load/prepare.js +211 -0
  739. package/packages/crouter-api/dist/core/import/load/rewrite.js +310 -0
  740. package/packages/crouter-api/dist/core/import/load/stage.js +99 -0
  741. package/packages/crouter-api/dist/core/inspector/chrome.js +14 -0
  742. package/packages/crouter-api/dist/core/inspector/contract.js +1 -0
  743. package/packages/crouter-api/dist/core/inspector/core.js +296 -0
  744. package/packages/crouter-api/dist/core/inspector/host.js +538 -0
  745. package/packages/crouter-api/dist/core/inspector/model.js +225 -0
  746. package/packages/crouter-api/dist/core/inspector/text.js +45 -0
  747. package/packages/crouter-api/dist/core/inspector/transport.js +36 -0
  748. package/packages/crouter-api/dist/core/inspector/tui.js +295 -0
  749. package/packages/crouter-api/dist/core/installed-plugins.js +82 -0
  750. package/packages/crouter-api/dist/core/io.js +470 -0
  751. package/packages/crouter-api/dist/core/keybindings/attach-control.js +42 -0
  752. package/packages/crouter-api/dist/core/keybindings/background-bash.js +33 -0
  753. package/packages/crouter-api/dist/core/keybindings/catalog.js +288 -0
  754. package/packages/crouter-api/dist/core/keybindings/inbox.js +25 -0
  755. package/packages/crouter-api/dist/core/keybindings/index.js +7 -0
  756. package/packages/crouter-api/dist/core/keybindings/match.js +146 -0
  757. package/packages/crouter-api/dist/core/keybindings/persistence.js +49 -0
  758. package/packages/crouter-api/dist/core/keybindings/resolve.js +348 -0
  759. package/packages/crouter-api/dist/core/keybindings/types.js +1 -0
  760. package/packages/crouter-api/dist/core/layout-migrate/index.js +523 -0
  761. package/packages/crouter-api/dist/core/layout-migrate/paths.js +118 -0
  762. package/packages/crouter-api/dist/core/layout-migrate/stored-paths.js +424 -0
  763. package/packages/crouter-api/dist/core/layout-migrate/stores.js +543 -0
  764. package/packages/crouter-api/dist/core/layout.js +143 -0
  765. package/packages/crouter-api/dist/core/ledger/account.js +13 -0
  766. package/packages/crouter-api/dist/core/ledger/charges.js +44 -0
  767. package/packages/crouter-api/dist/core/ledger/check.js +40 -0
  768. package/packages/crouter-api/dist/core/ledger/chunks.js +43 -0
  769. package/packages/crouter-api/dist/core/ledger/index.js +10 -0
  770. package/packages/crouter-api/dist/core/ledger/infra-allowance.js +31 -0
  771. package/packages/crouter-api/dist/core/ledger/limits.js +35 -0
  772. package/packages/crouter-api/dist/core/ledger/months.js +19 -0
  773. package/packages/crouter-api/dist/core/ledger/payer.js +14 -0
  774. package/packages/crouter-api/dist/core/ledger/rates.js +64 -0
  775. package/packages/crouter-api/dist/core/ledger/read.js +194 -0
  776. package/packages/crouter-api/dist/core/ledger/totals.js +34 -0
  777. package/packages/crouter-api/dist/core/ledger/types.js +2 -0
  778. package/packages/crouter-api/dist/core/llm/app-rungs.js +64 -0
  779. package/packages/crouter-api/dist/core/llm/body-limits.js +7 -0
  780. package/packages/crouter-api/dist/core/llm/owner-candidates.js +79 -0
  781. package/packages/crouter-api/dist/core/llm/refusal.js +22 -0
  782. package/packages/crouter-api/dist/core/llm/run.js +558 -0
  783. package/packages/crouter-api/dist/core/locked-file.js +121 -0
  784. package/packages/crouter-api/dist/core/log.js +91 -0
  785. package/packages/crouter-api/dist/core/managed-providers.js +61 -0
  786. package/packages/crouter-api/dist/core/manifest-stale.js +39 -0
  787. package/packages/crouter-api/dist/core/manifest.js +37 -0
  788. package/packages/crouter-api/dist/core/model-auth/api-credential-store.js +49 -0
  789. package/packages/crouter-api/dist/core/model-auth/daemon-login.js +156 -0
  790. package/packages/crouter-api/dist/core/model-auth/readiness.js +83 -0
  791. package/packages/crouter-api/dist/core/model-routes-pool.js +57 -0
  792. package/packages/crouter-api/dist/core/model-routes.js +212 -0
  793. package/packages/crouter-api/dist/core/northlight/previews.js +87 -0
  794. package/packages/crouter-api/dist/core/nvim-launch.js +45 -0
  795. package/packages/crouter-api/dist/core/output.js +99 -0
  796. package/packages/crouter-api/dist/core/packages/eligibility.js +34 -0
  797. package/packages/crouter-api/dist/core/packages/launch-kinds.js +20 -0
  798. package/packages/crouter-api/dist/core/packages/source-url.js +17 -0
  799. package/packages/crouter-api/dist/core/pagination.js +88 -0
  800. package/packages/crouter-api/dist/core/peer/client.js +168 -0
  801. package/packages/crouter-api/dist/core/peer/directory.js +193 -0
  802. package/packages/crouter-api/dist/core/peer/envelope.js +98 -0
  803. package/packages/crouter-api/dist/core/peer/names.js +8 -0
  804. package/packages/crouter-api/dist/core/peer/outbox-store.js +84 -0
  805. package/packages/crouter-api/dist/core/peer/receiver.js +54 -0
  806. package/packages/crouter-api/dist/core/peer/stubs.js +208 -0
  807. package/packages/crouter-api/dist/core/peer/token.js +30 -0
  808. package/packages/crouter-api/dist/core/peer/version.js +23 -0
  809. package/packages/crouter-api/dist/core/permissions/builtin.js +29 -0
  810. package/packages/crouter-api/dist/core/permissions/ceiling.js +332 -0
  811. package/packages/crouter-api/dist/core/permissions/compile.js +175 -0
  812. package/packages/crouter-api/dist/core/permissions/errors.js +13 -0
  813. package/packages/crouter-api/dist/core/permissions/evaluator.js +98 -0
  814. package/packages/crouter-api/dist/core/permissions/facts.js +102 -0
  815. package/packages/crouter-api/dist/core/permissions/schema-parser.js +151 -0
  816. package/packages/crouter-api/dist/core/permissions/schemas.js +83 -0
  817. package/packages/crouter-api/dist/core/permissions/sql.js +31 -0
  818. package/packages/crouter-api/dist/core/plugin-app.js +58 -0
  819. package/packages/crouter-api/dist/core/plugin-env.js +30 -0
  820. package/packages/crouter-api/dist/core/plugin-extensions.js +191 -0
  821. package/packages/crouter-api/dist/core/plugin-objects-manifest.js +86 -0
  822. package/packages/crouter-api/dist/core/plugin-quarantine.js +70 -0
  823. package/packages/crouter-api/dist/core/plugin-swap-lock.js +31 -0
  824. package/packages/crouter-api/dist/core/pool-credential-store.js +116 -0
  825. package/packages/crouter-api/dist/core/predicate.js +191 -0
  826. package/packages/crouter-api/dist/core/preview-registry.js +403 -0
  827. package/packages/crouter-api/dist/core/preview-result-path.js +26 -0
  828. package/packages/crouter-api/dist/core/profiles/default-binding.js +29 -0
  829. package/packages/crouter-api/dist/core/profiles/deletion-reservation.js +42 -0
  830. package/packages/crouter-api/dist/core/profiles/fuzzy-match.js +92 -0
  831. package/packages/crouter-api/dist/core/profiles/manifest.js +574 -0
  832. package/packages/crouter-api/dist/core/profiles/select.js +740 -0
  833. package/packages/crouter-api/dist/core/provider-credential.js +17 -0
  834. package/packages/crouter-api/dist/core/provider-error-recognition.js +82 -0
  835. package/packages/crouter-api/dist/core/provider-failure.js +157 -0
  836. package/packages/crouter-api/dist/core/provider-management.js +9 -0
  837. package/packages/crouter-api/dist/core/providers/approval.js +146 -0
  838. package/packages/crouter-api/dist/core/providers/audit.js +52 -0
  839. package/packages/crouter-api/dist/core/providers/bundles.js +643 -0
  840. package/packages/crouter-api/dist/core/providers/call.js +497 -0
  841. package/packages/crouter-api/dist/core/providers/description.js +1 -0
  842. package/packages/crouter-api/dist/core/providers/device-libs.js +202 -0
  843. package/packages/crouter-api/dist/core/providers/device.js +95 -0
  844. package/packages/crouter-api/dist/core/providers/errors.js +136 -0
  845. package/packages/crouter-api/dist/core/providers/files.js +390 -0
  846. package/packages/crouter-api/dist/core/providers/inflight.js +14 -0
  847. package/packages/crouter-api/dist/core/providers/mint.js +219 -0
  848. package/packages/crouter-api/dist/core/providers/receipts.js +61 -0
  849. package/packages/crouter-api/dist/core/providers/request.js +173 -0
  850. package/packages/crouter-api/dist/core/providers/roots.js +118 -0
  851. package/packages/crouter-api/dist/core/providers/token-cache.js +203 -0
  852. package/packages/crouter-api/dist/core/rate-limit-scope.js +64 -0
  853. package/packages/crouter-api/dist/core/remote-canvas-target.js +30 -0
  854. package/packages/crouter-api/dist/core/render.js +146 -0
  855. package/packages/crouter-api/dist/core/resolver.js +111 -0
  856. package/packages/crouter-api/dist/core/review/comments.js +296 -0
  857. package/packages/crouter-api/dist/core/review/companion.js +211 -0
  858. package/packages/crouter-api/dist/core/review/signal.js +12 -0
  859. package/packages/crouter-api/dist/core/review/store.js +178 -0
  860. package/packages/crouter-api/dist/core/review/types.js +23 -0
  861. package/packages/crouter-api/dist/core/runs/activity.js +57 -0
  862. package/packages/crouter-api/dist/core/runs/events.js +179 -0
  863. package/packages/crouter-api/dist/core/runs/initial-input.js +27 -0
  864. package/packages/crouter-api/dist/core/runs/operations.js +793 -0
  865. package/packages/crouter-api/dist/core/runs/questions.js +151 -0
  866. package/packages/crouter-api/dist/core/runtime/banner.js +53 -0
  867. package/packages/crouter-api/dist/core/runtime/bearings-render.js +273 -0
  868. package/packages/crouter-api/dist/core/runtime/bearings.js +199 -0
  869. package/packages/crouter-api/dist/core/runtime/bin-contributions.js +186 -0
  870. package/packages/crouter-api/dist/core/runtime/blaxel-environment.js +17 -0
  871. package/packages/crouter-api/dist/core/runtime/branded-host.js +485 -0
  872. package/packages/crouter-api/dist/core/runtime/broker/attachments-fetch.js +20 -0
  873. package/packages/crouter-api/dist/core/runtime/broker/bash-job-launch.js +65 -0
  874. package/packages/crouter-api/dist/core/runtime/broker/daemon-ops.js +232 -0
  875. package/packages/crouter-api/dist/core/runtime/broker/model-adapter.js +431 -0
  876. package/packages/crouter-api/dist/core/runtime/broker/node-token.js +16 -0
  877. package/packages/crouter-api/dist/core/runtime/broker/read-ops.js +173 -0
  878. package/packages/crouter-api/dist/core/runtime/broker/signal-stream.js +149 -0
  879. package/packages/crouter-api/dist/core/runtime/broker/turn-cause.js +44 -0
  880. package/packages/crouter-api/dist/core/runtime/broker-protocol.js +152 -0
  881. package/packages/crouter-api/dist/core/runtime/broker-request.js +86 -0
  882. package/packages/crouter-api/dist/core/runtime/broker-sdk.js +130 -0
  883. package/packages/crouter-api/dist/core/runtime/canvas-extensions.js +100 -0
  884. package/packages/crouter-api/dist/core/runtime/close.js +266 -0
  885. package/packages/crouter-api/dist/core/runtime/command-expansion.js +104 -0
  886. package/packages/crouter-api/dist/core/runtime/command-surface.js +117 -0
  887. package/packages/crouter-api/dist/core/runtime/crtr-theme.js +146 -0
  888. package/packages/crouter-api/dist/core/runtime/deliver-live.js +84 -0
  889. package/packages/crouter-api/dist/core/runtime/fault-recovery.js +83 -0
  890. package/packages/crouter-api/dist/core/runtime/fault.js +17 -0
  891. package/packages/crouter-api/dist/core/runtime/fleet.js +75 -0
  892. package/packages/crouter-api/dist/core/runtime/focus-viewer.js +151 -0
  893. package/packages/crouter-api/dist/core/runtime/front-door-env.js +16 -0
  894. package/packages/crouter-api/dist/core/runtime/headless-pi.js +176 -0
  895. package/packages/crouter-api/dist/core/runtime/host.js +701 -0
  896. package/packages/crouter-api/dist/core/runtime/interactive-deliver.js +51 -0
  897. package/packages/crouter-api/dist/core/runtime/invocation.js +10 -0
  898. package/packages/crouter-api/dist/core/runtime/kickoff.js +263 -0
  899. package/packages/crouter-api/dist/core/runtime/launch-prompt.js +13 -0
  900. package/packages/crouter-api/dist/core/runtime/launch-target.js +87 -0
  901. package/packages/crouter-api/dist/core/runtime/launch.js +505 -0
  902. package/packages/crouter-api/dist/core/runtime/ledger.js +55 -0
  903. package/packages/crouter-api/dist/core/runtime/lifecycle.js +283 -0
  904. package/packages/crouter-api/dist/core/runtime/managed-provider-cooling.js +62 -0
  905. package/packages/crouter-api/dist/core/runtime/memory-admission.js +68 -0
  906. package/packages/crouter-api/dist/core/runtime/model-registry.js +13 -0
  907. package/packages/crouter-api/dist/core/runtime/model-selection.js +135 -0
  908. package/packages/crouter-api/dist/core/runtime/model-swap.js +75 -0
  909. package/packages/crouter-api/dist/core/runtime/naming.js +300 -0
  910. package/packages/crouter-api/dist/core/runtime/nerd-font.js +162 -0
  911. package/packages/crouter-api/dist/core/runtime/nodes.js +506 -0
  912. package/packages/crouter-api/dist/core/runtime/outcome-document.js +86 -0
  913. package/packages/crouter-api/dist/core/runtime/output-result.js +32 -0
  914. package/packages/crouter-api/dist/core/runtime/output-schema-refs.js +100 -0
  915. package/packages/crouter-api/dist/core/runtime/package-health.js +100 -0
  916. package/packages/crouter-api/dist/core/runtime/persona.js +54 -0
  917. package/packages/crouter-api/dist/core/runtime/pi-cli.js +65 -0
  918. package/packages/crouter-api/dist/core/runtime/pi-vendored.js +63 -0
  919. package/packages/crouter-api/dist/core/runtime/placement-tmux.js +81 -0
  920. package/packages/crouter-api/dist/core/runtime/placement.js +418 -0
  921. package/packages/crouter-api/dist/core/runtime/progress-bar.js +50 -0
  922. package/packages/crouter-api/dist/core/runtime/provider-credential-gate.js +48 -0
  923. package/packages/crouter-api/dist/core/runtime/recovery-hold.js +46 -0
  924. package/packages/crouter-api/dist/core/runtime/reopen.js +160 -0
  925. package/packages/crouter-api/dist/core/runtime/revive.js +748 -0
  926. package/packages/crouter-api/dist/core/runtime/roadmap.js +86 -0
  927. package/packages/crouter-api/dist/core/runtime/runner/blaxel/client.js +140 -0
  928. package/packages/crouter-api/dist/core/runtime/runner/blaxel/image-build.js +233 -0
  929. package/packages/crouter-api/dist/core/runtime/runner/delete-sandboxes.js +24 -0
  930. package/packages/crouter-api/dist/core/runtime/runner/index.js +37 -0
  931. package/packages/crouter-api/dist/core/runtime/runner/machine/call.js +94 -0
  932. package/packages/crouter-api/dist/core/runtime/runner/machine/environment.js +7 -0
  933. package/packages/crouter-api/dist/core/runtime/runner/machine/ops.js +42 -0
  934. package/packages/crouter-api/dist/core/runtime/runner/machine/runner.js +90 -0
  935. package/packages/crouter-api/dist/core/runtime/runner/process.js +70 -0
  936. package/packages/crouter-api/dist/core/runtime/runner/types.js +16 -0
  937. package/packages/crouter-api/dist/core/runtime/session-branch.js +16 -0
  938. package/packages/crouter-api/dist/core/runtime/session-cycles.js +110 -0
  939. package/packages/crouter-api/dist/core/runtime/session-list-cache.js +302 -0
  940. package/packages/crouter-api/dist/core/runtime/session-visibility.js +99 -0
  941. package/packages/crouter-api/dist/core/runtime/setup-marker.js +46 -0
  942. package/packages/crouter-api/dist/core/runtime/situational-context.js +54 -0
  943. package/packages/crouter-api/dist/core/runtime/situational-live.js +41 -0
  944. package/packages/crouter-api/dist/core/runtime/spawn-env-rows.js +15 -0
  945. package/packages/crouter-api/dist/core/runtime/spawn-env.js +260 -0
  946. package/packages/crouter-api/dist/core/runtime/spawn.js +717 -0
  947. package/packages/crouter-api/dist/core/runtime/stamp/protocol.js +113 -0
  948. package/packages/crouter-api/dist/core/runtime/start-check.js +43 -0
  949. package/packages/crouter-api/dist/core/runtime/stop-guard.js +150 -0
  950. package/packages/crouter-api/dist/core/runtime/structured-output.js +112 -0
  951. package/packages/crouter-api/dist/core/runtime/surface-bg.js +85 -0
  952. package/packages/crouter-api/dist/core/runtime/tmux-bindings.js +743 -0
  953. package/packages/crouter-api/dist/core/runtime/tmux-chrome.js +5 -0
  954. package/packages/crouter-api/dist/core/runtime/tmux-driver.js +713 -0
  955. package/packages/crouter-api/dist/core/runtime/unsandboxed.js +18 -0
  956. package/packages/crouter-api/dist/core/runtime/view-socket.js +195 -0
  957. package/packages/crouter-api/dist/core/runtime/warm-pool.js +479 -0
  958. package/packages/crouter-api/dist/core/scope.js +184 -0
  959. package/packages/crouter-api/dist/core/scoped-state/db.js +271 -0
  960. package/packages/crouter-api/dist/core/scoped-state/legacy-profiles.js +65 -0
  961. package/packages/crouter-api/dist/core/scoped-state/migrate.js +332 -0
  962. package/packages/crouter-api/dist/core/scoped-state/paths.js +27 -0
  963. package/packages/crouter-api/dist/core/scoped-state/person-rows.js +185 -0
  964. package/packages/crouter-api/dist/core/scoped-state/person-store.js +116 -0
  965. package/packages/crouter-api/dist/core/scoped-state/schema.js +52 -0
  966. package/packages/crouter-api/dist/core/scopes.js +48 -0
  967. package/packages/crouter-api/dist/core/secrets/env-rows.js +40 -0
  968. package/packages/crouter-api/dist/core/secrets/environment-owner.js +31 -0
  969. package/packages/crouter-api/dist/core/secrets/environment-secrets.js +14 -0
  970. package/packages/crouter-api/dist/core/secrets/index.js +2 -0
  971. package/packages/crouter-api/dist/core/secrets/key.js +33 -0
  972. package/packages/crouter-api/dist/core/secrets/seal.js +43 -0
  973. package/packages/crouter-api/dist/core/secrets.js +147 -0
  974. package/packages/crouter-api/dist/core/self-update.js +77 -0
  975. package/packages/crouter-api/dist/core/session-model/session-state.js +180 -0
  976. package/packages/crouter-api/dist/core/shell-segments.js +169 -0
  977. package/packages/crouter-api/dist/core/spaces/cache-env.js +15 -0
  978. package/packages/crouter-api/dist/core/spaces/file-root.js +68 -0
  979. package/packages/crouter-api/dist/core/spaces/mounts.js +126 -0
  980. package/packages/crouter-api/dist/core/spaces/open-beneath.js +581 -0
  981. package/packages/crouter-api/dist/core/spaces/permissions.js +77 -0
  982. package/packages/crouter-api/dist/core/spaces/process.js +172 -0
  983. package/packages/crouter-api/dist/core/spaces/runtime-home.js +8 -0
  984. package/packages/crouter-api/dist/core/spaces/space.js +58 -0
  985. package/packages/crouter-api/dist/core/spaces/stop.js +138 -0
  986. package/packages/crouter-api/dist/core/spaces/users.js +43 -0
  987. package/packages/crouter-api/dist/core/sqlite-statements.js +17 -0
  988. package/packages/crouter-api/dist/core/statements.js +81 -0
  989. package/packages/crouter-api/dist/core/storage/attachments.js +141 -0
  990. package/packages/crouter-api/dist/core/storage/caller-file.js +84 -0
  991. package/packages/crouter-api/dist/core/storage/client.js +220 -0
  992. package/packages/crouter-api/dist/core/storage/media-types.js +22 -0
  993. package/packages/crouter-api/dist/core/storage/purge.js +55 -0
  994. package/packages/crouter-api/dist/core/storage/tables.js +129 -0
  995. package/packages/crouter-api/dist/core/subscription-state.js +449 -0
  996. package/packages/crouter-api/dist/core/substrate/delivery/corpus.js +206 -0
  997. package/packages/crouter-api/dist/core/substrate/delivery/deliver.js +336 -0
  998. package/packages/crouter-api/dist/core/substrate/delivery/listings.js +75 -0
  999. package/packages/crouter-api/dist/core/substrate/delivery/match.js +146 -0
  1000. package/packages/crouter-api/dist/core/substrate/delivery/plan.js +130 -0
  1001. package/packages/crouter-api/dist/core/substrate/delivery/render-boot.js +330 -0
  1002. package/packages/crouter-api/dist/core/substrate/delivery/render-event.js +186 -0
  1003. package/packages/crouter-api/dist/core/substrate/delivery/sub-persona-menu.js +24 -0
  1004. package/packages/crouter-api/dist/core/substrate/delivery/types.js +1 -0
  1005. package/packages/crouter-api/dist/core/substrate/gate-explain.js +397 -0
  1006. package/packages/crouter-api/dist/core/substrate/schema.js +81 -0
  1007. package/packages/crouter-api/dist/core/substrate/subject-fields.js +39 -0
  1008. package/packages/crouter-api/dist/core/substrate/subject.js +60 -0
  1009. package/packages/crouter-api/dist/core/termrender/code-doc.js +92 -0
  1010. package/packages/crouter-api/dist/core/termrender/display.js +56 -0
  1011. package/packages/crouter-api/dist/core/termrender/termrender.js +719 -0
  1012. package/packages/crouter-api/dist/core/termrender/version.js +1 -0
  1013. package/packages/crouter-api/dist/core/timing.js +94 -0
  1014. package/packages/crouter-api/dist/core/tui/draw.js +378 -0
  1015. package/packages/crouter-api/dist/core/tui/fuzzy.js +38 -0
  1016. package/packages/crouter-api/dist/core/tui/markdown.js +407 -0
  1017. package/packages/crouter-api/dist/core/tui/page-host.js +74 -0
  1018. package/packages/crouter-api/dist/core/tui/panel.js +142 -0
  1019. package/packages/crouter-api/dist/core/tui/terminal.js +100 -0
  1020. package/packages/crouter-api/dist/core/user-settings.js +478 -0
  1021. package/packages/crouter-api/dist/core/wake.js +296 -0
  1022. package/packages/crouter-api/dist/core/worktree-close.js +251 -0
  1023. package/packages/crouter-api/dist/core/worktree-containment.js +48 -0
  1024. package/packages/crouter-api/dist/core/worktree-landing.js +56 -0
  1025. package/packages/crouter-api/dist/core/worktree-machine.js +92 -0
  1026. package/packages/crouter-api/dist/core/worktree-mutation-async.js +385 -0
  1027. package/packages/crouter-api/dist/core/worktree-remove.js +84 -0
  1028. package/packages/crouter-api/dist/core/worktree.js +909 -0
  1029. package/packages/crouter-api/dist/daemon/api/deferred-head.js +117 -0
  1030. package/packages/crouter-api/dist/daemon/api/environment-of.js +64 -0
  1031. package/packages/crouter-api/dist/daemon/api/handlers/bash-jobs.js +341 -0
  1032. package/packages/crouter-api/dist/daemon/api/handlers/broker-recovery.js +266 -0
  1033. package/packages/crouter-api/dist/daemon/api/handlers/git-credential.js +64 -0
  1034. package/packages/crouter-api/dist/daemon/api/handlers/providers.js +284 -0
  1035. package/packages/crouter-api/dist/daemon/api/handlers/validate.js +58 -0
  1036. package/packages/crouter-api/dist/daemon/api/map.js +768 -0
  1037. package/packages/crouter-api/dist/daemon/api/operations.js +316 -0
  1038. package/packages/crouter-api/dist/daemon/api/principal.js +147 -0
  1039. package/packages/crouter-api/dist/daemon/api/reader.js +125 -0
  1040. package/packages/crouter-api/dist/daemon/api/router.js +542 -0
  1041. package/packages/crouter-api/dist/daemon/api/sync-notice.js +46 -0
  1042. package/packages/crouter-api/dist/daemon/api/viewer-presence.js +100 -0
  1043. package/packages/crouter-api/dist/daemon/broker-signals/bus.js +203 -0
  1044. package/packages/crouter-api/dist/daemon/companion-retire.js +44 -0
  1045. package/packages/crouter-api/dist/daemon/control.js +22 -0
  1046. package/packages/crouter-api/dist/daemon/cron/authority.js +101 -0
  1047. package/packages/crouter-api/dist/daemon/cron/live-runs.js +66 -0
  1048. package/packages/crouter-api/dist/daemon/cron/run-socket.js +170 -0
  1049. package/packages/crouter-api/dist/daemon/drain.js +76 -0
  1050. package/packages/crouter-api/dist/daemon/http-dispatcher.js +37 -0
  1051. package/packages/crouter-api/dist/daemon/human/finish.js +178 -0
  1052. package/packages/crouter-api/dist/daemon/human/settle.js +103 -0
  1053. package/packages/crouter-api/dist/daemon/machine-link/config.js +63 -0
  1054. package/packages/crouter-api/dist/daemon/machine-link/credential.js +24 -0
  1055. package/packages/crouter-api/dist/daemon/machine-link/forward.js +181 -0
  1056. package/packages/crouter-api/dist/daemon/machine-link/frames.js +29 -0
  1057. package/packages/crouter-api/dist/daemon/machine-link/holder.js +317 -0
  1058. package/packages/crouter-api/dist/daemon/machine-link/move-notify.js +15 -0
  1059. package/packages/crouter-api/dist/daemon/manage.js +736 -0
  1060. package/packages/crouter-api/dist/daemon/park-activity.js +33 -0
  1061. package/packages/crouter-api/dist/daemon/park-pending.js +76 -0
  1062. package/packages/crouter-api/dist/daemon/pidfile.js +37 -0
  1063. package/packages/crouter-api/dist/daemon/postgres/binary.js +193 -0
  1064. package/packages/crouter-api/dist/daemon/postgres/cluster.js +111 -0
  1065. package/packages/crouter-api/dist/daemon/postgres/pins.js +16 -0
  1066. package/packages/crouter-api/dist/daemon/postgres/supervisor.js +177 -0
  1067. package/packages/crouter-api/dist/daemon/readiness.js +37 -0
  1068. package/packages/crouter-api/dist/daemon/reconcilers/broker-supervision.js +846 -0
  1069. package/packages/crouter-api/dist/daemon/reconcilers/ledger-sandbox.js +249 -0
  1070. package/packages/crouter-api/dist/daemon/reconcilers/live-obligation.js +125 -0
  1071. package/packages/crouter-api/dist/daemon/reconcilers/node-lifecycle/launch-failure.js +8 -0
  1072. package/packages/crouter-api/dist/daemon/reconcilers/node-lifecycle/node-person.js +40 -0
  1073. package/packages/crouter-api/dist/daemon/reconcilers/node-lifecycle/remote-wake.js +151 -0
  1074. package/packages/crouter-api/dist/daemon/reconcilers/node-lifecycle/respawn-policy.js +59 -0
  1075. package/packages/crouter-api/dist/daemon/reconcilers/recipe-image.js +196 -0
  1076. package/packages/crouter-api/dist/daemon/reconcilers/throttled-lane.js +63 -0
  1077. package/packages/crouter-api/dist/daemon/runs/append-section.js +135 -0
  1078. package/packages/crouter-api/dist/daemon/runs/observer.js +441 -0
  1079. package/packages/crouter-api/dist/daemon/runs/view-transport.js +81 -0
  1080. package/packages/crouter-api/dist/daemon/startup-policy.js +1 -0
  1081. package/packages/crouter-api/dist/daemon/structured-requests/sidecar.js +5 -0
  1082. package/packages/crouter-api/dist/hook-authoring.js +447 -0
  1083. package/packages/crouter-api/dist/hook-process.js +34 -0
  1084. package/packages/crouter-api/dist/launcher/client.js +52 -0
  1085. package/packages/crouter-api/dist/launcher/limits/policy.js +142 -0
  1086. package/packages/crouter-api/dist/launcher/limits/settings.js +94 -0
  1087. package/packages/crouter-api/dist/launcher/spec.js +10 -0
  1088. package/packages/crouter-api/dist/migrations/004-canvas-documents/apply.js +113 -0
  1089. package/packages/crouter-api/dist/migrations/004-canvas-documents/fields.js +52 -0
  1090. package/packages/crouter-api/dist/migrations/004-canvas-documents/index.js +89 -0
  1091. package/packages/crouter-api/dist/migrations/004-canvas-documents/legacy/discover.js +251 -0
  1092. package/packages/crouter-api/dist/migrations/004-canvas-documents/legacy/history.js +37 -0
  1093. package/packages/crouter-api/dist/migrations/004-canvas-documents/legacy/nested.js +37 -0
  1094. package/packages/crouter-api/dist/migrations/004-canvas-documents/legacy/parse.js +24 -0
  1095. package/packages/crouter-api/dist/migrations/004-canvas-documents/legacy/types.js +3 -0
  1096. package/packages/crouter-api/dist/migrations/004-canvas-documents/plan.js +410 -0
  1097. package/packages/crouter-api/dist/migrations/004-canvas-documents/pointers.js +95 -0
  1098. package/packages/crouter-api/dist/migrations/activation.js +46 -0
  1099. package/packages/crouter-api/dist/native/linux.js +20 -0
  1100. package/packages/crouter-api/dist/shared/crtr-version.js +18 -0
  1101. package/packages/crouter-api/dist/shared/env.js +335 -0
  1102. package/packages/crouter-api/dist/shared/generated-context.js +240 -0
  1103. package/packages/crouter-api/dist/shared/inbox-entry-body.js +124 -0
  1104. package/packages/crouter-api/dist/shared/inline-ref-grammar.js +99 -0
  1105. package/packages/crouter-api/dist/shared/predicates.js +4 -0
  1106. package/packages/crouter-api/dist/shared/shell-quote.js +5 -0
  1107. package/packages/crouter-api/dist/shared/strip-cd-prefix.js +13 -0
  1108. package/packages/crouter-api/dist/shared/tool-groups.js +64 -0
  1109. package/packages/crouter-api/dist/shared/traceparent.js +28 -0
  1110. package/packages/crouter-api/dist/shared/turn-replies.js +71 -0
  1111. package/packages/crouter-api/dist/shared/working-activity.js +27 -0
  1112. package/packages/crouter-api/dist/types.js +193 -0
  1113. package/packages/crouter-api/package.json +49 -0
  1114. package/packages/crouter-identity/package.json +1 -1
  1115. package/packages/crouter-plugin/dist/approval.js +12 -0
  1116. package/packages/crouter-plugin/dist/bundle.js +203 -0
  1117. package/packages/crouter-plugin/dist/caller.js +23 -0
  1118. package/packages/crouter-plugin/dist/client/index.js +338 -0
  1119. package/packages/crouter-plugin/dist/compare.js +314 -0
  1120. package/packages/crouter-plugin/dist/define.js +531 -0
  1121. package/packages/crouter-plugin/dist/errors.js +150 -0
  1122. package/packages/crouter-plugin/dist/fields.js +83 -0
  1123. package/packages/crouter-plugin/dist/index.js +15 -0
  1124. package/packages/crouter-plugin/dist/manifest.js +111 -0
  1125. package/packages/crouter-plugin/dist/node.js +153 -0
  1126. package/packages/crouter-plugin/dist/params.js +85 -0
  1127. package/packages/crouter-plugin/dist/receipts.js +234 -0
  1128. package/packages/crouter-plugin/dist/serve.js +630 -0
  1129. package/packages/crouter-plugin/dist/verify.js +84 -0
  1130. package/packages/crouter-plugin/dist/watchable.js +14 -0
  1131. package/packages/crouter-plugin/package.json +42 -0
  1132. package/runtime.lock.json +14 -13
  1133. package/scripts/sandbox-bootstrap.sh +4 -0
  1134. package/dist/core/graph/repo-sync/index.d.ts +0 -4
  1135. package/dist/core/graph/repo-sync/index.js +0 -1
  1136. package/dist/core/graph/repo-sync/mirror.d.ts +0 -30
  1137. package/dist/core/graph/repo-sync/mirror.js +0 -6
  1138. package/dist/core/graph/repo-sync/sync.d.ts +0 -40
  1139. package/dist/core/graph/repo-sync/sync.js +0 -2
@@ -0,0 +1,2091 @@
1
+ // render/chat-view.ts — the render half of `crtr surface attach`.
2
+ //
3
+ // A direct port of pi's `InteractiveMode.handleEvent()`
4
+ // (interactive-mode.js:2169-2462) + its rebuild path
5
+ // (`addMessageToChat`/`renderSessionContext`, :2483-2648) that DRIVES pi's own
6
+ // exported TUI components rather than reimplementing them. The viewer never
7
+ // spawns pi and never opens the session — it only consumes the relayed
8
+ // `AgentSessionEvent` stream + the `welcome` snapshot over `view.sock`.
9
+ //
10
+ // Ownership boundary: ChatView owns the chat scroll `Container` it is handed.
11
+ // Its activity state (working spinner, compaction/retry indicators) is signaled
12
+ // to the viewer-owned fixed slot when one is supplied. It does NOT own the
13
+ // editor, the footer, or the terminal title — those are chrome laid out by the
14
+ // attach command. Events that only affect that chrome
15
+ // (queue_update / session_info_changed / thinking_level_changed) are forwarded
16
+ // to the optional `onFooterEvent` sink instead of rendered here.
17
+ //
18
+ // Custom-tool rendering: extensions run in the broker, so the viewer generally
19
+ // has no extension `ToolDefinition`. The viewer supplies native renderers only
20
+ // for crouter-owned message/tool types it understands; other extension
21
+ // `renderCall`/`renderResult` hooks degrade to the default ToolExecutionComponent
22
+ // path while builtin tools, diffs, and partial-result streaming keep working.
23
+ import { Container, Loader, Spacer, Text } from '@earendil-works/pi-tui';
24
+ import { AssistantMessageComponent, BashExecutionComponent, BranchSummaryMessageComponent, CompactionSummaryMessageComponent, CustomMessageComponent, parseSkillBlock, SkillInvocationMessageComponent, ToolExecutionComponent, UserMessageComponent, } from '@earendil-works/pi-coding-agent';
25
+ import { attachMarkdownTheme } from '../config.js';
26
+ import { ContextMessageComponent } from './context-message.js';
27
+ import { presentationFor } from './card-presentation.js';
28
+ import { detectInlinePageResult, PageBlockComponent } from './page-block.js';
29
+ import { CRTR_OUTPUT_CUSTOM_TYPE, CrtrOutputMessageComponent, createCrtrBashToolDefinition, } from './crtr-output.js';
30
+ import { CRTR_CYCLE_DIVIDER_CUSTOM_TYPE, endedByAbort } from '../../../core/runtime/session-cycles.js';
31
+ import { isHumanWordsEntry, parseCard } from '../../../shared/generated-context.js';
32
+ import { assistantVisibleText, isGroupBoundaryKind, isTrueUserMessage, } from '../../../shared/tool-groups.js';
33
+ import { messageKey, normalizeTurnReplyRecord, START_TURN_KEY, turnReplyText, } from '../../../shared/turn-replies.js';
34
+ import { isCycleDivider } from './condensed-history.js';
35
+ import { transformDiagramFences } from './diagram.js';
36
+ import { styleAttachAgentMarkdown, styleAttachMarkdownSource, styleAttachMessageMarkdown, styleAttachSummaryMarkdown, } from './markdown-source.js';
37
+ import { createCrtrEditToolDefinition } from './edit-diff.js';
38
+ import { GroupActivityRecorder } from './group-activity.js';
39
+ import { GroupRecapComponent } from './group-recap.js';
40
+ import { FoldedToolCallController, bashCallBackgroundHintLines, createCrtrPlainBashToolDefinition, createCrtrReadToolDefinition, createCrtrWriteToolDefinition, } from './tool-calls.js';
41
+ import { ringCompletionBell } from '../chrome/completion-bell.js';
42
+ import { extractFilePaths } from '../../../core/human/visible-paths.js';
43
+ import { extractDocRefs } from './doc-links.js';
44
+ import { keepWhenCondensed, liveRegionStart } from './condensed-history.js';
45
+ import { ViewerAssistantMessageComponent } from './assistant-message.js';
46
+ import { CompositeViewportSource, MeasuredContainer, } from './measured-container.js';
47
+ import { readConfig } from '../../../core/config.js';
48
+ import { DEFAULT_CONDENSED_HISTORY, DEFAULT_LIVE_CYCLES, DEFAULT_VERBOSITY, VERBOSITY_LEVELS } from '../../../types.js';
49
+ import { applySnapshot as projectSnapshot, applyToolGroupSummary as projectToolGroupSummary, applyWorkingActivity as projectWorkingActivity, bashEnd as projectBashEnd, bashOutput as projectBashOutput, bashStart as projectBashStart, initialConvState, reduce as projectEvent, } from '../../conversation/projection.js';
50
+ /** Theme-derived chrome colors (spinner / dim / error) are supplied by the
51
+ * attach command via `ChatViewOptions.palette` (built from the live theme in
52
+ * config.ts). pi does not re-export the raw `theme` instance, so standalone
53
+ * ChatViews receive the same semantic ANSI fallback palette. The message components
54
+ * use the attach Markdown theme, which preserves the user's pi theme while making
55
+ * fenced code visually distinct. */
56
+ const defaultDimStyle = (s) => `\x1b[2m${s}\x1b[22m`;
57
+ /** How many catch-up messages `applySnapshot` builds between event-loop yields.
58
+ * Keeps large non-streaming snapshots from monopolizing the main thread so
59
+ * queued keystrokes are serviced during construction. */
60
+ const SNAPSHOT_YIELD_EVERY = 50;
61
+ /** The user's `live_cycles` setting — how many trailing refresh-yield cycles the
62
+ * transcript renders at full fidelity. Read per ChatView (i.e. per attach), so
63
+ * `crtr sys config set live_cycles --value N` takes effect on the next attach
64
+ * without a daemon restart. A missing/unreadable config falls back to the
65
+ * shipped default. */
66
+ function readLiveCycles() {
67
+ try {
68
+ return readConfig('user').live_cycles;
69
+ }
70
+ catch {
71
+ return DEFAULT_LIVE_CYCLES;
72
+ }
73
+ }
74
+ /** The user's `condensed_history` setting — which messages of an already-condensed
75
+ * cycle still render (the cycle dividers always do). Read per attach, like
76
+ * `live_cycles`. */
77
+ function readCondensedHistory() {
78
+ try {
79
+ return readConfig('user').condensed_history;
80
+ }
81
+ catch {
82
+ return DEFAULT_CONDENSED_HISTORY;
83
+ }
84
+ }
85
+ /** The user's `verbosity` setting — the level every viewer starts at. Ctrl+O and
86
+ * Ctrl+Shift+O move the open viewer only and never write it back. */
87
+ function readVerbosity() {
88
+ try {
89
+ return readConfig('user').verbosity;
90
+ }
91
+ catch {
92
+ return DEFAULT_VERBOSITY;
93
+ }
94
+ }
95
+ /** Whether folded tool recaps list their actual activity or use compact counts.
96
+ * The detailed form is the default; each attach reads its own presentation choice. */
97
+ function readDetailedToolRecaps() {
98
+ try {
99
+ return readConfig('user').detailed_tool_recaps;
100
+ }
101
+ catch {
102
+ return true;
103
+ }
104
+ }
105
+ /** A component supports the Ctrl+O global tool-output toggle. Mirrors pi's
106
+ * `isExpandable` duck-type (interactive-mode.js): any rendered child carrying a
107
+ * `setExpanded(boolean)` method — tool executions, custom/compaction/branch/skill
108
+ * message components — participates; everything else (the status container, plain
109
+ * text, assistant/user bubbles) is skipped. */
110
+ function isExpandable(obj) {
111
+ return (typeof obj === 'object' &&
112
+ obj !== null &&
113
+ 'setExpanded' in obj &&
114
+ typeof obj.setExpanded === 'function');
115
+ }
116
+ /** Every SGR escape, for measuring a line's visible content. */
117
+ const ANSI_RE = /\x1b\[[0-9;]*m/g;
118
+ /** Same match, with the SGR parameter list captured for rewriting. */
119
+ const SGR_PARAMS_RE = /\x1b\[([0-9;]*)m/g;
120
+ /** Drop every background-color SGR parameter from a line, keeping foreground and
121
+ * text styles. The minimized fold is a dense index of what ran, so the tool's
122
+ * pending/success/error background band (pi paints it across the full pane width)
123
+ * reads as noise there — one call per line, unhighlighted. `0` (full reset) is
124
+ * kept: it clears the background too, and nothing follows it to re-set one. */
125
+ function stripBackground(line) {
126
+ return line.replace(SGR_PARAMS_RE, (_whole, params) => {
127
+ const parts = params.split(';');
128
+ const kept = [];
129
+ for (let i = 0; i < parts.length; i++) {
130
+ const code = Number(parts[i] === '' ? 0 : parts[i]);
131
+ // Extended colors (`38` foreground, `48` background, `58` underline):
132
+ // consume the full sequence atomically so an RGB channel in the 40-47 or
133
+ // 100-107 range is not mistaken for a standalone background code.
134
+ if (code === 38 || code === 48 || code === 58) {
135
+ const mode = Number(parts[i + 1]);
136
+ const end = i + (mode === 5 ? 2 : mode === 2 ? 4 : 1);
137
+ if (code !== 48)
138
+ kept.push(...parts.slice(i, end + 1));
139
+ i = end;
140
+ continue;
141
+ }
142
+ // Standard (40-47) and bright (100-107) backgrounds. `49` (reset to the
143
+ // default background) is KEPT — it is the thing we want, and dropping it
144
+ // would let a neighbouring row's background bleed into this line.
145
+ if ((code >= 40 && code <= 47) || (code >= 100 && code <= 107))
146
+ continue;
147
+ kept.push(String(code));
148
+ }
149
+ return kept.length > 0 ? `\x1b[${kept.join(';')}m` : '';
150
+ });
151
+ }
152
+ /** Sender sections of an inbox card body; `parseCard` already read their entries.
153
+ * Whatever remains is other content riding the same digest. */
154
+ const INBOX_SENDER_SECTIONS = /<from\b[^>]*>[\s\S]*?<\/from>/g;
155
+ /** A tool component that can fold itself down to its CALL. pi's `ToolExecutionComponent`
156
+ * only knows expanded/collapsed, so each crtr-owned definition receives a local fold
157
+ * controller and captures the compact call component it renders. Folded render paints
158
+ * that captured call directly, dropping result and Box chrome while letting a wrapped
159
+ * path keep its natural rows. Tools without a crtr definition remain in full. */
160
+ /** A one-line separator that appears only while its adjacent tool group is
161
+ * folded. It stays in the transcript so toggling folded tools reflows the same
162
+ * message/tool boundary without rebuilding the chat. */
163
+ class FoldedToolSeparator extends Spacer {
164
+ folded = false;
165
+ separatesToolGroup = false;
166
+ setFolded(folded) {
167
+ this.folded = folded;
168
+ this.refresh();
169
+ }
170
+ setSeparatesToolGroup(separatesToolGroup) {
171
+ this.separatesToolGroup = separatesToolGroup;
172
+ this.refresh();
173
+ }
174
+ refresh() {
175
+ this.setLines(this.folded && this.separatesToolGroup ? 1 : 0);
176
+ }
177
+ }
178
+ /** The dim row under a consolidated reply that stands for the folded working. */
179
+ class WorkingRow extends Container {
180
+ label = new Text('', 1, 0);
181
+ constructor() {
182
+ super();
183
+ this.addChild(new Spacer(1));
184
+ this.addChild(this.label);
185
+ }
186
+ setLabel(label) {
187
+ this.label.setText(label);
188
+ }
189
+ }
190
+ function plural(count, singular, pluralForm) {
191
+ return `${count} ${count === 1 ? singular : pluralForm}`;
192
+ }
193
+ class MinimizableToolComponent extends ToolExecutionComponent {
194
+ /** Bound by ChatView at append time; pi's base component does not expose it. */
195
+ activityCallId;
196
+ minimized = false;
197
+ expandedState = false;
198
+ foldController;
199
+ resultObserver;
200
+ /** A foldable definition owns its folded call component; it may also observe
201
+ * results before the imported shell renders them. */
202
+ setToolView(foldController, resultObserver) {
203
+ this.foldController = foldController;
204
+ this.resultObserver = resultObserver;
205
+ }
206
+ updateResult(...args) {
207
+ this.resultObserver?.(args[0], args[1] ?? false);
208
+ // The clock stays in the model's persisted result and copyable transcript,
209
+ // but need not consume a visible row in the human's tool card.
210
+ const result = args[0];
211
+ const content = result.content;
212
+ if (Array.isArray(content) && /^elapsed \d+(?:h \d+)?m \d+s(?:\n|$)/.test(content.at(-1)?.text ?? '')) {
213
+ super.updateResult({ ...result, content: content.slice(0, -1) }, args[1]);
214
+ }
215
+ else {
216
+ super.updateResult(...args);
217
+ }
218
+ }
219
+ setExpanded(expanded) {
220
+ this.expandedState = expanded;
221
+ super.setExpanded(expanded);
222
+ }
223
+ /** Flip the local fold state, then use the imported component's public
224
+ * expansion setter to rebuild its call renderer at the current setting. */
225
+ setMinimized(minimized) {
226
+ if (!this.foldController || this.minimized === minimized)
227
+ return;
228
+ this.minimized = minimized;
229
+ this.foldController.setFolded(minimized);
230
+ super.setExpanded(this.expandedState);
231
+ }
232
+ render(width) {
233
+ // The backgrounding row is appended HERE, by the component that owns the
234
+ // whole tool block, so it renders after the block's highlighted band ends
235
+ // instead of inside it. It is empty unless this is a bash call still running
236
+ // past the threshold.
237
+ if (!this.minimized) {
238
+ return [...super.render(width), ...bashCallBackgroundHintLines(this.foldController?.callComponent(), width)];
239
+ }
240
+ const call = this.foldController?.callComponent();
241
+ if (!call)
242
+ return super.render(width);
243
+ // trimEnd drops right-hand padding, which only existed to carry the
244
+ // background band these lines no longer paint.
245
+ return call.render(width)
246
+ .filter((line) => line.replace(ANSI_RE, '').trim().length > 0)
247
+ .map((line) => stripBackground(line).trimEnd());
248
+ }
249
+ }
250
+ const defaultErrorStyle = (s) => `\x1b[31m${s}\x1b[39m`;
251
+ const defaultAttachPalette = {
252
+ accent: (s) => `\x1b[33m${s}\x1b[39m`,
253
+ active: (s) => `\x1b[36m${s}\x1b[39m`,
254
+ info: (s) => `\x1b[34m${s}\x1b[39m`,
255
+ muted: defaultDimStyle,
256
+ faint: defaultDimStyle,
257
+ border: (s) => s,
258
+ surface: (s) => s,
259
+ bold: (s) => `\x1b[1m${s}\x1b[22m`,
260
+ error: defaultErrorStyle,
261
+ warning: (s) => `\x1b[33m${s}\x1b[39m`,
262
+ diffAdded: (s) => `\x1b[32m${s}\x1b[39m`,
263
+ diffRemoved: (s) => `\x1b[91m${s}\x1b[39m`,
264
+ bashMode: (s) => `\x1b[32m${s}\x1b[39m`,
265
+ bashModeAlt: (s) => `\x1b[92m${s}\x1b[39m`,
266
+ };
267
+ export class ChatView {
268
+ tui;
269
+ /** The chat scroll area handed in by the attach command. */
270
+ container;
271
+ /** Settled history is cached independently from the live status area so picker
272
+ * navigation does not re-render a long conversation on every key repeat. */
273
+ historyContainer = new MeasuredContainer();
274
+ /** Standalone ChatViews render activity inline; the attach viewer supplies
275
+ * `onActivityChange`, so its transcript excludes this container. */
276
+ statusContainer = new MeasuredContainer();
277
+ /** Optional banner, above history and status in the viewport's flat source. */
278
+ bannerContainer;
279
+ transcript;
280
+ /** Where `append()` puts a component. Normally `historyContainer`; retargeted to
281
+ * a nested container while condensed history is being built, so the same
282
+ * message-rendering path serves both regions. */
283
+ appendTarget = this.historyContainer;
284
+ /** Inline page blocks placed in this transcript, by page id — one block per
285
+ * page, so a `--replace` revision refreshes the block already on screen. */
286
+ pageBlocks = new Map();
287
+ /** The person's inbox answers in the live region, each with its leading
288
+ * spacer. Summary mode hides them with the settled pages they answer. */
289
+ inboxAnswers = new Set();
290
+ inlinePageBlocks;
291
+ pageOpenHint;
292
+ backgroundBashHint;
293
+ /** Trailing cycles kept at full fidelity (config `live_cycles`). */
294
+ liveCycles;
295
+ /** Messages kept from a condensed cycle (config `condensed_history`). */
296
+ condensedHistory;
297
+ cwd;
298
+ showImages;
299
+ imageWidthCells;
300
+ hideThinking;
301
+ hiddenThinkingLabel;
302
+ /** The viewer's verbosity level (Ctrl+O more, Ctrl+Shift+O less). Every
303
+ * display choice below derives from it. */
304
+ level;
305
+ detailedToolRecaps = readDetailedToolRecaps();
306
+ /** Groups exist only while building/rendering the full-fidelity live region. */
307
+ groups = [];
308
+ openGroup;
309
+ /** Turns are always built in the live region, so the viewer can move into
310
+ * and out of Replies only at any time; other levels hide their reply rows. */
311
+ turnReplies = new Map();
312
+ turns = [];
313
+ openReplyTurn;
314
+ /** The turn the live region opens in when it begins mid-turn (the condensed
315
+ * region held its person's message), else the pre-message `start` turn. */
316
+ carriedTurn = { key: START_TURN_KEY, prose: [] };
317
+ /** >0 while appending components that never join a turn (the person's
318
+ * message, turn chrome, errors, condensed history). */
319
+ outsideTurns = 0;
320
+ /** Components the turn fold currently hides. */
321
+ turnHidden = new Set();
322
+ /** Both forms of condensed history, when it exists; one is hidden per level. */
323
+ condensedBlocks = {};
324
+ /** The newest turn's reply text, which `/copy` takes at Replies only. */
325
+ lastReplyText;
326
+ groupSummaries = new Map();
327
+ /** Node id → display name for every node spawned in this transcript, so a
328
+ * later group's finish notice can name the child rather than its id. */
329
+ nodeRoster = new Map();
330
+ streamingWasGroupMember = false;
331
+ onFooterEvent;
332
+ /** Viewer hook that places activity in its fixed slot, when available. */
333
+ onActivityChange;
334
+ /** Theme-derived colorizers for the activity/status area. */
335
+ spinnerStyle;
336
+ dimStyle;
337
+ errorStyle;
338
+ /** Palette shared with recap rows that render outside pi tool callbacks. */
339
+ recapPalette;
340
+ /** Bold accent for the expanded crtr-context label. */
341
+ labelStyle = (s) => `\x1b[1m${s}\x1b[22m`;
342
+ /** Viewer-local Markdown projection, handed to pi's message components so
343
+ * THEY apply it at render time with the exact content width. The viewer keeps
344
+ * no projected copy: the components hold canonical source, and each
345
+ * transformer reads live viewer state on every call. Diagrams apply only to
346
+ * assistant-authored Markdown. */
347
+ markdownTransformers = [
348
+ (markdown, { messageType, availableWidth }) => (messageType === 'assistant' ? transformDiagramFences(markdown, availableWidth) : markdown),
349
+ (markdown, { messageType }) => (messageType === 'user' ? styleAttachMarkdownSource(markdown) : styleAttachAgentMarkdown(markdown)),
350
+ ];
351
+ /** The assistant message component currently being streamed (between
352
+ * message_start and message_end for an assistant turn). */
353
+ streamingComponent;
354
+ /** The separator immediately after the live assistant component. It becomes
355
+ * visible when that response has visible prose or thinking and folded tools. */
356
+ streamingToolSeparator;
357
+ /** Content classes for each separator, so Ctrl+T can add/remove thinking gaps
358
+ * without rebuilding the transcript. */
359
+ foldedToolSeparatorContents = new Map();
360
+ /** Tool-call id → its execution component, for the duration of the call. */
361
+ pendingTools = new Map();
362
+ /** The `!` bash component currently streaming (between bash_start and bash_end). */
363
+ bashComponent;
364
+ /** The single active activity loader (working/compaction/retry), if any. */
365
+ activityLoader;
366
+ /** The shared broker transcript state; this renderer projects it into pi TUI
367
+ * components while retaining terminal-only folding and virtualization. */
368
+ projection = initialConvState();
369
+ /** Broker-selected normal label for this turn; compaction/retry temporarily
370
+ * replace it and restore it when the run remains active. */
371
+ workingActivity = this.projection.workingActivity;
372
+ runActive = false;
373
+ // -- Single-writer snapshot ordering -------------------------------------
374
+ // A non-streaming catch-up yields to the event loop mid-build (so queued stdin
375
+ // drains), which opens a window where later broker frames could otherwise
376
+ // mutate a half-rebuilt transcript. These three fields make the ChatView a
377
+ // single ordered writer: applySnapshot is the only thing that mutates the
378
+ // view while a build is in flight, live frames are deferred and replayed in
379
+ // wire order once it finishes, and a newer welcome always supersedes an older
380
+ // build. See applySnapshot / deferIfBuilding.
381
+ /** True while applySnapshot is mid-build; live broker frames defer instead of
382
+ * mutating the partially-rebuilt view. */
383
+ applyingSnapshot = false;
384
+ /** Bumped on every applySnapshot. A build suspended at a yield compares this
385
+ * after resuming and abandons itself when a newer welcome has bumped it, so
386
+ * the newest welcome wins and stale state never overwrites the live view. */
387
+ snapshotGeneration = 0;
388
+ /** Live frames captured during an in-flight build (bound closures that re-run
389
+ * the original entry point), replayed in order when the build completes and
390
+ * dropped when a newer welcome supersedes the build. */
391
+ deferredFrames = [];
392
+ /** Text of the most recent assistant message, kept current from the welcome
393
+ * snapshot AND the live event stream so `/copy` (getLastAssistantText) works
394
+ * whether the message arrived before or after attach. */
395
+ lastAssistantText;
396
+ /** Existing file paths found anywhere in the rendered transcript, newest first. */
397
+ transcriptFilePaths = [];
398
+ /** `[[ref]]` document references from the transcript, newest first. */
399
+ transcriptDocRefs = [];
400
+ /** Canonical copyable transcript blocks, in their rendered visual order. */
401
+ copyBlockRecords = [];
402
+ copyIndex = new Map();
403
+ /** Registrations made while building condensed history are collapsed onto its
404
+ * outer container once that container becomes a top-level viewport block. */
405
+ condensedCopyBlocks = new WeakMap();
406
+ constructor(tui, container, opts = {}) {
407
+ this.tui = tui;
408
+ this.container = container;
409
+ this.cwd = opts.cwd ?? process.cwd();
410
+ this.showImages = opts.showImages ?? true;
411
+ this.imageWidthCells = opts.imageWidthCells ?? 60;
412
+ this.hideThinking = opts.hideThinking ?? false;
413
+ this.hiddenThinkingLabel = opts.hiddenThinkingLabel ?? 'Thinking...';
414
+ this.level = opts.verbosity ?? readVerbosity();
415
+ this.liveCycles = opts.liveCycles ?? readLiveCycles();
416
+ this.condensedHistory = opts.condensedHistory ?? readCondensedHistory();
417
+ this.onFooterEvent = opts.onFooterEvent;
418
+ this.onActivityChange = opts.onActivityChange;
419
+ this.inlinePageBlocks = opts.inlinePageBlocks ?? false;
420
+ this.pageOpenHint = opts.pageOpenHint ?? (() => 'crtr human list');
421
+ this.backgroundBashHint = opts.backgroundBashHint ?? (() => null);
422
+ this.recapPalette = opts.palette ?? defaultAttachPalette;
423
+ this.spinnerStyle = this.recapPalette.active;
424
+ this.dimStyle = this.recapPalette.muted;
425
+ this.errorStyle = this.recapPalette.error;
426
+ // Banner sits above history and OUTSIDE it, so resetChat() (which clears only
427
+ // historyContainer) never wipes it — it persists across every welcome snapshot.
428
+ if (opts.banner && opts.banner.length > 0) {
429
+ const banner = new MeasuredContainer();
430
+ banner.addChild(new Spacer(1));
431
+ for (const line of opts.banner)
432
+ banner.addChild(new Text(line, 1, 0));
433
+ banner.addChild(new Spacer(1));
434
+ this.bannerContainer = banner;
435
+ this.container.addChild(banner);
436
+ }
437
+ this.container.addChild(this.historyContainer);
438
+ if (!this.onActivityChange)
439
+ this.container.addChild(this.statusContainer);
440
+ this.transcript = new CompositeViewportSource([
441
+ ...(this.bannerContainer ? [this.bannerContainer] : []),
442
+ this.historyContainer,
443
+ ...(this.onActivityChange ? [] : [this.statusContainer]),
444
+ ]);
445
+ }
446
+ /** The transcript as one flat ordered block list for the viewport. */
447
+ transcriptSource() {
448
+ return this.transcript;
449
+ }
450
+ // Catch-up: render the welcome snapshot, then live events resume.
451
+ /** Render the full message history from a `welcome` snapshot. Ports pi's
452
+ * `renderSessionContext` (interactive-mode.js:2553): assistant messages spawn
453
+ * tool-execution components matched to their toolResult messages; everything
454
+ * else routes through `addMessageToChat`. The TUI's differential renderer +
455
+ * reflow-on-resize is automatic — no scrollback reconstruction needed. */
456
+ async applySnapshot(snapshot) {
457
+ // Open a new build generation. Any older build still suspended at a yield
458
+ // abandons itself when it resumes (generation check below), and live frames
459
+ // that were deferred against the transcript we are about to discard are
460
+ // dropped — a newer welcome always wins.
461
+ const generation = ++this.snapshotGeneration;
462
+ this.applyingSnapshot = true;
463
+ this.deferredFrames.length = 0;
464
+ this.resetChat();
465
+ this.projection = projectSnapshot(snapshot, this.projection);
466
+ this.workingActivity = this.projection.workingActivity;
467
+ this.runActive = this.projection.isStreaming;
468
+ this.seedToolGroupSummaries(this.projection.toolGroupSummaryDetails);
469
+ this.turnReplies.clear();
470
+ for (const [key, reply] of Object.entries(normalizeTurnReplyRecord(snapshot.turnReplies)))
471
+ this.turnReplies.set(key, reply);
472
+ const renderedPendingTools = new Map();
473
+ const messages = this.projection.messages;
474
+ const lastIndex = messages.length - 1;
475
+ // Cycles older than the trailing `live_cycles` are condensed into one nested
476
+ // container before the live region is built. It retains only configured prose
477
+ // and cycle seams, avoiding old tool components while still reflowing on pane
478
+ // resize. `liveStart` is 0 until the node has yielded past the configured
479
+ // window, so a fresh node renders at full fidelity. Both forms are built —
480
+ // one reply per turn for Replies only, the kept messages for every other
481
+ // level — so a level change only swaps which one is hidden.
482
+ const liveStart = liveRegionStart(messages, this.liveCycles);
483
+ if (liveStart > 0) {
484
+ for (const form of ['turns', 'messages']) {
485
+ const condensed = await this.buildCondensedBlock(messages.slice(0, liveStart), generation, form);
486
+ if (generation !== this.snapshotGeneration)
487
+ return;
488
+ if (condensed)
489
+ this.appendCondensedBlock(condensed, form);
490
+ }
491
+ }
492
+ for (let i = liveStart; i < messages.length; i++) {
493
+ // Yield to the event loop every SNAPSHOT_YIELD_EVERY messages so queued
494
+ // stdin drains (keystrokes are handled instead of bursting after a long
495
+ // catch-up) while a big transcript constructs. Skipped for a STREAMING
496
+ // snapshot: its in-flight tail + pending tools must be bound before any
497
+ // relayed message_update/message_end lands, so it builds synchronously
498
+ // (no await → no broker frame can interleave and freeze the live bubble).
499
+ if (!this.projection.isStreaming &&
500
+ i > liveStart &&
501
+ (i - liveStart) % SNAPSHOT_YIELD_EVERY === 0) {
502
+ await new Promise((resolve) => setImmediate(resolve));
503
+ // A newer welcome arrived while we were suspended — abandon this stale
504
+ // build without touching the view (or the gate) it no longer owns.
505
+ if (generation !== this.snapshotGeneration)
506
+ return;
507
+ }
508
+ const message = messages[i];
509
+ if (message.role === 'assistant') {
510
+ // Keep the `/copy` source current from the catch-up transcript too, not
511
+ // only the live stream (you usually attach AFTER the last reply landed).
512
+ const text = assistantVisibleText(message);
513
+ if (text.trim()) {
514
+ this.lastAssistantText = text;
515
+ this.pushTranscriptText(text);
516
+ }
517
+ // If the snapshot caught an IN-FLIGHT assistant turn (state.isStreaming
518
+ // and this is the trailing, non-terminal assistant message), bind it as
519
+ // the live streaming component so the relayed message_update/message_end
520
+ // frames that follow `welcome` land on it. Otherwise the in-flight
521
+ // message would freeze at its snapshot value until the next turn — the
522
+ // common case, since you typically attach to a node that is working.
523
+ const isStreamingTail = i === lastIndex &&
524
+ this.projection.isStreaming &&
525
+ message.stopReason !== 'aborted' &&
526
+ message.stopReason !== 'error';
527
+ const hasProse = assistantVisibleText(message).trim() !== '';
528
+ const toolCalls = this.assistantToolCalls(message);
529
+ const endedWithFailure = message.stopReason === 'aborted' || message.stopReason === 'error';
530
+ const terminalErrorMessage = endedByAbort(message) ? 'Interrupted' : (message.errorMessage ?? 'Error');
531
+ // A terminal assistant failure remains visible as its own boundary. Settle
532
+ // any interrupted calls so the completed span before it can still recap.
533
+ if (endedWithFailure) {
534
+ for (const component of renderedPendingTools.values()) {
535
+ const result = { content: [{ type: 'text', text: terminalErrorMessage }], isError: true };
536
+ component.updateResult(result);
537
+ this.registerCopyBlock(component, 'tool', terminalErrorMessage);
538
+ this.settleGroupTool(component, result, true);
539
+ }
540
+ renderedPendingTools.clear();
541
+ }
542
+ if (hasProse || endedWithFailure)
543
+ this.closeOpenGroup();
544
+ let separator;
545
+ if (isStreamingTail) {
546
+ this.streamingComponent = new ViewerAssistantMessageComponent(undefined, this.hideThinking, attachMarkdownTheme(), this.hiddenThinkingLabel, this.markdownTransformers);
547
+ this.appendAssistantPart(this.streamingComponent, !hasProse);
548
+ this.registerCopyBlock(this.streamingComponent, 'assistant', '');
549
+ this.streamingWasGroupMember = !hasProse;
550
+ this.streamingComponent.updateContent(message);
551
+ this.registerCopyBlock(this.streamingComponent, 'assistant', assistantVisibleText(message));
552
+ separator = this.streamingToolSeparator = this.appendAssistantSeparator(!hasProse);
553
+ }
554
+ else {
555
+ separator = this.appendAssistantMessage(message, !hasProse && !endedWithFailure);
556
+ }
557
+ if (separator)
558
+ this.setAssistantSeparatorContent(separator, message);
559
+ for (const content of toolCalls) {
560
+ this.pushTranscriptValue(content.arguments);
561
+ const component = this.appendToolComponent(content.name, content.id, content.arguments);
562
+ // (isStreamingTail is never aborted/error, so its tools fall through to
563
+ // renderedPendingTools → pendingTools, where live tool events find them.)
564
+ if (message.stopReason === 'aborted' || message.stopReason === 'error') {
565
+ component.updateResult({ content: [{ type: 'text', text: terminalErrorMessage }], isError: true });
566
+ this.registerCopyBlock(component, 'tool', terminalErrorMessage);
567
+ this.settleGroupTool(component, { content: [{ type: 'text', text: terminalErrorMessage }], isError: true }, true);
568
+ }
569
+ else {
570
+ renderedPendingTools.set(content.id, component);
571
+ }
572
+ }
573
+ if (endedWithFailure)
574
+ this.closeOpenGroup();
575
+ if (!isStreamingTail && !endedWithFailure)
576
+ this.recordTurnProse(message, false);
577
+ }
578
+ else if (message.role === 'toolResult') {
579
+ this.pushTranscriptText(this.userMessageText(message));
580
+ const component = renderedPendingTools.get(message.toolCallId);
581
+ if (component) {
582
+ component.updateResult(message);
583
+ this.registerCopyBlock(component, 'tool', this.toolResultText(message));
584
+ this.historyContainer.markDirty(component);
585
+ this.settleGroupTool(component, message, message.isError === true);
586
+ renderedPendingTools.delete(message.toolCallId);
587
+ this.maybeAppendPageBlock(message);
588
+ }
589
+ }
590
+ else {
591
+ this.addMessageToChat(message);
592
+ }
593
+ }
594
+ for (const [id, component] of renderedPendingTools) {
595
+ this.pendingTools.set(id, component);
596
+ }
597
+ for (const turn of this.turns)
598
+ this.refreshTurn(turn);
599
+ // A rebuild constructs fresh components, which are born unfolded; re-apply the
600
+ // setting so a reconnect/welcome does not silently unfold the transcript.
601
+ this.applyToolDisplay();
602
+ // If we attached mid-turn, the `agent_start` that spins up the working loader
603
+ // already fired before we connected — restore it from the snapshot's streaming
604
+ // state so an actively-working node shows the spinner right away.
605
+ if (this.projection.isStreaming)
606
+ this.setActivity(this.makeLoader(this.workingActivity));
607
+ this.tui.requestRender();
608
+ // Build complete and still current (a mismatch would have returned above):
609
+ // open the gate and replay, in wire order, any live frames that arrived
610
+ // during construction so they land on the finished transcript.
611
+ this.applyingSnapshot = false;
612
+ this.replayDeferredFrames();
613
+ }
614
+ /**
615
+ * Build the condensed form of the already-finished cycles as a nested component
616
+ * container, or return undefined when nothing survives condensation.
617
+ *
618
+ * Reuses `addMessageToChat` by retargeting `append()` at the nested container, so
619
+ * condensed history uses the same renderer as live history with tool traffic
620
+ * filtered out. The outer history cache keeps stable-width frames cheap, while
621
+ * preserving the components lets pane-width changes reflow their content. The
622
+ * build yields on the live cadence and abandons itself when a newer welcome
623
+ * supersedes this generation.
624
+ */
625
+ async buildCondensedBlock(messages, generation, form) {
626
+ const condensed = new Container();
627
+ const previousTarget = this.appendTarget;
628
+ const copyBlocks = [];
629
+ this.appendTarget = condensed;
630
+ this.condensedCopyBlocks.set(condensed, copyBlocks);
631
+ try {
632
+ if (form === 'turns') {
633
+ if (!(await this.buildCondensedTurns(messages, generation)))
634
+ return undefined;
635
+ return condensed.children.length > 0 ? { component: condensed, copyBlocks } : undefined;
636
+ }
637
+ let built = 0;
638
+ for (const message of messages) {
639
+ if (!keepWhenCondensed(message, this.condensedHistory))
640
+ continue;
641
+ if (built > 0 && built % SNAPSHOT_YIELD_EVERY === 0) {
642
+ await new Promise((resolve) => setImmediate(resolve));
643
+ if (generation !== this.snapshotGeneration)
644
+ return undefined;
645
+ }
646
+ built++;
647
+ // Condensed prose still feeds the @-path picker; `lastAssistantText` (the
648
+ // `/copy` source) deliberately does not — the live region always holds the
649
+ // newest reply.
650
+ this.pushTranscriptText(this.userMessageText(message));
651
+ this.addMessageToChat(message);
652
+ }
653
+ }
654
+ finally {
655
+ this.appendTarget = previousTarget;
656
+ this.condensedCopyBlocks.delete(condensed);
657
+ }
658
+ return condensed.children.length > 0 ? { component: condensed, copyBlocks } : undefined;
659
+ }
660
+ /** Replies only in condensed history: each finished turn renders as
661
+ * the person's message, its reply, then any cycle dividers it spanned. A turn
662
+ * still open at the end continues into the live region, so it is carried there
663
+ * instead of rendered. Returns false when a newer welcome superseded the build. */
664
+ async buildCondensedTurns(messages, generation) {
665
+ const turns = [{ key: START_TURN_KEY, prose: [], dividers: [] }];
666
+ for (const message of messages) {
667
+ const turn = turns.at(-1);
668
+ if (isTrueUserMessage(message)) {
669
+ turns.push({ key: messageKey(message) ?? `local-${turns.length}`, user: message, prose: [], dividers: [] });
670
+ }
671
+ else if (isCycleDivider(message)) {
672
+ turn.dividers.push(message);
673
+ }
674
+ else if (message.role === 'assistant' && message.stopReason !== 'aborted' && message.stopReason !== 'error') {
675
+ const text = assistantVisibleText(message).trim();
676
+ const key = messageKey(message);
677
+ if (text !== '' && key !== undefined)
678
+ turn.prose.push({ key, text });
679
+ }
680
+ }
681
+ const last = turns.pop();
682
+ let built = 0;
683
+ const render = async (turn, withReply) => {
684
+ if (built > 0 && built % SNAPSHOT_YIELD_EVERY === 0) {
685
+ await new Promise((resolve) => setImmediate(resolve));
686
+ if (generation !== this.snapshotGeneration)
687
+ return false;
688
+ }
689
+ built++;
690
+ if (turn.user !== undefined) {
691
+ this.pushTranscriptText(this.userMessageText(turn.user));
692
+ this.addMessageToChat(turn.user);
693
+ }
694
+ const text = withReply ? turnReplyText(turn.prose, this.turnReplies.get(turn.key)) : '';
695
+ if (text !== '') {
696
+ const component = new ViewerAssistantMessageComponent(undefined, this.hideThinking, attachMarkdownTheme(), this.hiddenThinkingLabel, this.markdownTransformers);
697
+ component.updateContent(this.replyMessage(text));
698
+ this.append(component);
699
+ this.registerCopyBlock(component, 'assistant', text);
700
+ }
701
+ for (const divider of turn.dividers)
702
+ this.addMessageToChat(divider);
703
+ return true;
704
+ };
705
+ for (const turn of turns)
706
+ if (!(await render(turn, true)))
707
+ return false;
708
+ // The open turn: its person's message (and any dividers so far) stay here,
709
+ // its reply joins the live region where its working continues.
710
+ if (!(await render(last, false)))
711
+ return false;
712
+ this.carriedTurn = { key: last.key, prose: last.prose };
713
+ return true;
714
+ }
715
+ /** Defer a live broker frame when a snapshot build is in flight. Returns true
716
+ * (and enqueues the replay closure) while building so the caller returns
717
+ * without mutating the half-rebuilt view; false when the caller may proceed.
718
+ * This is the single-writer gate every live-frame entry point passes through. */
719
+ deferIfBuilding(replay) {
720
+ if (!this.applyingSnapshot)
721
+ return false;
722
+ this.deferredFrames.push(replay);
723
+ return true;
724
+ }
725
+ /** Replay deferred live frames in wire order. The gate is already open, so each
726
+ * closure re-enters its entry point and dispatches immediately. */
727
+ replayDeferredFrames() {
728
+ const frames = this.deferredFrames.splice(0);
729
+ for (const replay of frames)
730
+ replay();
731
+ }
732
+ /** Apply the broker's random choice for a newly received user message. */
733
+ setWorkingActivity(activity) {
734
+ if (this.deferIfBuilding(() => this.setWorkingActivity(activity)))
735
+ return;
736
+ const wasShowingWorkingActivity = this.projection.activity === this.workingActivity;
737
+ this.projection = projectWorkingActivity(this.projection, activity);
738
+ this.workingActivity = this.projection.workingActivity;
739
+ if (this.runActive && wasShowingWorkingActivity)
740
+ this.setActivity(this.makeLoader(this.workingActivity));
741
+ }
742
+ /** Clear live turn state after the broker reports completion or the viewer observes dormancy. */
743
+ settleRun() {
744
+ this.runActive = false;
745
+ for (const component of this.pendingTools.values())
746
+ this.settleGroupTool(component);
747
+ if (this.streamingComponent) {
748
+ this.historyContainer.removeChild(this.streamingComponent);
749
+ for (const turn of this.turns)
750
+ turn.members.delete(this.streamingComponent);
751
+ this.turnHidden.delete(this.streamingComponent);
752
+ this.unregisterCopyBlock(this.streamingComponent);
753
+ this.streamingComponent = undefined;
754
+ }
755
+ this.streamingToolSeparator = undefined;
756
+ this.pendingTools.clear();
757
+ if (this.openReplyTurn)
758
+ this.refreshWorkingRow(this.openReplyTurn);
759
+ this.applyToolDisplay();
760
+ this.setActivity(undefined);
761
+ this.settleBashComponent();
762
+ }
763
+ /** Stop any spinning activity loader. A one-shot `crtr surface attach` process lets its
764
+ * timers die with the process, but if T7 reuses a ChatView across reconnects in
765
+ * one process it should call this on detach to avoid a leaked interval. */
766
+ dispose() {
767
+ this.settleRun();
768
+ }
769
+ // Global display toggles (Ctrl+O / Ctrl+T), driven by the input controller.
770
+ // Pure client-side render state — no broker round-trip — ported from pi's
771
+ // `setToolsExpanded` / `toggleThinkingBlockVisibility`.
772
+ /** Ctrl+O: one level more detail; from Full it wraps to Replies only. */
773
+ moreDetail() {
774
+ const index = VERBOSITY_LEVELS.indexOf(this.level);
775
+ this.setLevel(VERBOSITY_LEVELS[(index + 1) % VERBOSITY_LEVELS.length]);
776
+ return { level: this.level, atEnd: this.level === VERBOSITY_LEVELS.at(-1) };
777
+ }
778
+ /** Ctrl+Shift+O: one level less detail; stops at Replies only. */
779
+ lessDetail() {
780
+ const index = VERBOSITY_LEVELS.indexOf(this.level);
781
+ this.setLevel(VERBOSITY_LEVELS[Math.max(0, index - 1)]);
782
+ return { level: this.level, atEnd: this.level === VERBOSITY_LEVELS[0] };
783
+ }
784
+ setLevel(level) {
785
+ this.level = level;
786
+ for (const turn of this.turns)
787
+ this.refreshTurn(turn);
788
+ this.applyToolDisplay();
789
+ }
790
+ /** Replies only: one rewritten reply per message the person sends. */
791
+ repliesOnly() {
792
+ return this.level === 'replies';
793
+ }
794
+ /** Every settled tool call folds to its single call line (Replies only through Tool calls). */
795
+ foldsSettledTools() {
796
+ return VERBOSITY_LEVELS.indexOf(this.level) <= VERBOSITY_LEVELS.indexOf('tools');
797
+ }
798
+ /** A settled tool group collapses onto its broker summary (Replies only and Messages + summaries). */
799
+ showsGroupSummaries() {
800
+ return VERBOSITY_LEVELS.indexOf(this.level) <= VERBOSITY_LEVELS.indexOf('summaries');
801
+ }
802
+ /** pi's tool-output expansion, untruncated at Full only. */
803
+ toolOutputExpanded() {
804
+ return this.level === 'full';
805
+ }
806
+ /** Push both display settings onto every rendered component. A tool call still in
807
+ * flight is never hidden or minimized. Only a settled group with a broker-known
808
+ * summary collapses; incomplete/failed generation leaves its folded call lines. */
809
+ applyToolDisplay() {
810
+ const inFlight = new Set(this.pendingTools.values());
811
+ for (const group of this.groups)
812
+ for (const tool of group.inFlight)
813
+ inFlight.add(tool);
814
+ for (const child of this.historyContainer.children) {
815
+ if (child instanceof MinimizableToolComponent)
816
+ child.setMinimized(this.foldsSettledTools() && !inFlight.has(child));
817
+ if (isExpandable(child))
818
+ child.setExpanded(this.toolOutputExpanded());
819
+ }
820
+ // The turn fold composes with group folding: a group sets its members'
821
+ // combined state itself; every other folded member is set here, and a
822
+ // member the fold released is shown again.
823
+ const turnFolded = this.turnFoldedComponents(inFlight);
824
+ const groupOwned = new Set();
825
+ for (const group of this.groups) {
826
+ this.applyGroupDisplay(group, turnFolded);
827
+ groupOwned.add(group.recap);
828
+ for (const member of group.members)
829
+ groupOwned.add(member);
830
+ }
831
+ for (const component of this.turnHidden) {
832
+ if (!turnFolded.has(component) && !groupOwned.has(component))
833
+ this.historyContainer.setHidden(component, false);
834
+ }
835
+ for (const component of turnFolded) {
836
+ if (!groupOwned.has(component) && !this.historyContainer.hiddenChildren.has(component))
837
+ this.historyContainer.setHidden(component, true);
838
+ }
839
+ this.turnHidden = turnFolded;
840
+ for (const form of ['turns', 'messages']) {
841
+ const block = this.condensedBlocks[form];
842
+ if (block)
843
+ this.historyContainer.setHidden(block, (form === 'turns') !== this.repliesOnly());
844
+ }
845
+ this.applyInboxExchangeDisplay();
846
+ this.updateFoldedToolSeparators(inFlight);
847
+ this.historyContainer.markDirty();
848
+ this.tui.requestRender();
849
+ }
850
+ /** Replies only and Messages + summaries hide the back-and-forth with the
851
+ * person: every settled inline page and every answer they gave from their
852
+ * inbox. A page still awaiting an answer stays on screen. */
853
+ hidesInboxExchange() {
854
+ return this.showsGroupSummaries();
855
+ }
856
+ applyInboxExchangeDisplay() {
857
+ const hide = this.hidesInboxExchange();
858
+ for (const component of this.inboxAnswers)
859
+ this.historyContainer.setHidden(component, hide);
860
+ for (const block of this.pageBlocks.values())
861
+ this.historyContainer.setHidden(block, hide && block.settled);
862
+ }
863
+ /** A broker rewrite landed for one turn. Stored first: it may precede the
864
+ * turn's events, and snapshot rebuilds defer it through the writer gate. */
865
+ applyTurnReply(key, reply) {
866
+ if (this.deferIfBuilding(() => this.applyTurnReply(key, reply)))
867
+ return;
868
+ this.turnReplies.set(key, reply);
869
+ for (const turn of this.turns)
870
+ if (turn.key === key)
871
+ this.refreshTurn(turn);
872
+ this.tui.requestRender();
873
+ }
874
+ /** Every turn member the fold hides right now. The live turn keeps what is
875
+ * still in motion — the streaming message and in-flight tools — visible
876
+ * below its working row. */
877
+ turnFoldedComponents(inFlight) {
878
+ const folded = new Set();
879
+ if (!this.repliesOnly())
880
+ return folded;
881
+ for (const turn of this.turns) {
882
+ const live = turn === this.openReplyTurn;
883
+ for (const member of turn.members) {
884
+ if (live && (member === this.streamingComponent
885
+ || member === this.streamingToolSeparator
886
+ || member === this.bashComponent
887
+ || inFlight.has(member)))
888
+ continue;
889
+ folded.add(member);
890
+ }
891
+ }
892
+ return folded;
893
+ }
894
+ beginTurn(key, prose = []) {
895
+ const reply = new ViewerAssistantMessageComponent(undefined, this.hideThinking, attachMarkdownTheme(), this.hiddenThinkingLabel, this.markdownTransformers);
896
+ const working = new WorkingRow();
897
+ this.outsideTurns++;
898
+ try {
899
+ // The fold row sits between the person's message and the reply: what
900
+ // was asked, what was done, then the answer.
901
+ this.append(working);
902
+ this.append(reply);
903
+ }
904
+ finally {
905
+ this.outsideTurns--;
906
+ }
907
+ this.registerCopyBlock(reply, 'assistant', '');
908
+ const turn = { key, reply, working, members: new Set(), prose };
909
+ this.turns.push(turn);
910
+ this.openReplyTurn = turn;
911
+ this.refreshTurn(turn);
912
+ return turn;
913
+ }
914
+ /** Whether an append in progress lands in the live region, where every
915
+ * component joins a turn. */
916
+ consolidatingHere() {
917
+ return this.appendTarget === this.historyContainer;
918
+ }
919
+ currentTurn() {
920
+ return this.openReplyTurn ?? this.beginTurn(this.carriedTurn.key, [...this.carriedTurn.prose]);
921
+ }
922
+ /** A settled assistant message with prose becomes part of its turn's reply. */
923
+ recordTurnProse(message, refresh) {
924
+ if (!this.consolidatingHere() || message.role !== 'assistant')
925
+ return;
926
+ if (message.stopReason === 'aborted' || message.stopReason === 'error')
927
+ return;
928
+ const text = assistantVisibleText(message).trim();
929
+ const key = messageKey(message);
930
+ if (text === '' || key === undefined)
931
+ return;
932
+ const turn = this.currentTurn();
933
+ if (turn.prose.some((item) => item.key === key))
934
+ return;
935
+ turn.prose.push({ key, text });
936
+ if (refresh)
937
+ this.refreshTurn(turn);
938
+ }
939
+ /** Re-render one turn's reply from its prose and the broker's latest rewrite. */
940
+ refreshTurn(turn) {
941
+ const text = turnReplyText(turn.prose, this.turnReplies.get(turn.key));
942
+ turn.reply.updateContent(this.replyMessage(text));
943
+ this.historyContainer.setHidden(turn.reply, text === '' || !this.repliesOnly());
944
+ this.historyContainer.markDirty(turn.reply);
945
+ this.registerCopyBlock(turn.reply, 'assistant', text);
946
+ if (text !== '' && turn === this.turns.at(-1))
947
+ this.lastReplyText = text;
948
+ this.refreshWorkingRow(turn);
949
+ }
950
+ refreshWorkingRow(turn) {
951
+ let tools = 0;
952
+ let cards = 0;
953
+ for (const member of turn.members) {
954
+ if (member instanceof MinimizableToolComponent)
955
+ tools++;
956
+ else if (member instanceof ContextMessageComponent || member instanceof CustomMessageComponent || member instanceof CrtrOutputMessageComponent)
957
+ cards++;
958
+ }
959
+ const messages = turn.prose.length;
960
+ // A lone prose message with nothing else IS the reply; there is no working.
961
+ const hasWorking = tools > 0 || cards > 0 || messages > 1;
962
+ const parts = [
963
+ messages > 0 ? plural(messages, 'message', 'messages') : undefined,
964
+ tools > 0 ? plural(tools, 'tool call', 'tool calls') : undefined,
965
+ cards > 0 ? plural(cards, 'card', 'cards') : undefined,
966
+ ].filter((part) => part !== undefined);
967
+ // "working" only while the agent is running in this turn; a settled turn
968
+ // just names what the fold holds.
969
+ const live = this.runActive && turn === this.openReplyTurn;
970
+ turn.working.setLabel(this.dimStyle(`▸ ${live ? 'working — ' : ''}${parts.join(' · ')}`));
971
+ this.historyContainer.setHidden(turn.working, !hasWorking || !this.repliesOnly());
972
+ this.historyContainer.markDirty(turn.working);
973
+ }
974
+ replyMessage(text) {
975
+ return { role: 'assistant', content: text === '' ? [] : [{ type: 'text', text }], stopReason: 'stop' };
976
+ }
977
+ /** Ctrl+T / app.thinking.toggle — flip thinking-block visibility and apply it to
978
+ * every assistant message (the in-flight streaming bubble is itself a child of
979
+ * the container, so the loop covers it too). Returns the new HIDDEN state. */
980
+ toggleThinking() {
981
+ this.hideThinking = !this.hideThinking;
982
+ for (const child of this.historyContainer.children) {
983
+ if (child instanceof AssistantMessageComponent)
984
+ child.setHideThinkingBlock(this.hideThinking);
985
+ }
986
+ for (const [separator, content] of this.foldedToolSeparatorContents) {
987
+ separator.setSeparatesToolGroup(content.hasText || (!this.hideThinking && content.hasThinking));
988
+ }
989
+ this.historyContainer.markDirty();
990
+ this.tui.requestRender();
991
+ return this.hideThinking;
992
+ }
993
+ // Live stream: the 15-of-17-case handleEvent port (turn_start/turn_end no-op,
994
+ // exactly as interactive pi falls through default for those two).
995
+ handleEvent(event) {
996
+ // Order behind an in-flight catch-up: a live turn that starts while a large
997
+ // welcome is still building is replayed after it, never interleaved into it.
998
+ if (this.deferIfBuilding(() => this.handleEvent(event)))
999
+ return;
1000
+ this.projection = projectEvent(this.projection, event);
1001
+ switch (event.type) {
1002
+ case 'agent_start': {
1003
+ this.runActive = this.projection.isStreaming;
1004
+ for (const component of this.pendingTools.values())
1005
+ this.settleGroupTool(component);
1006
+ this.pendingTools.clear();
1007
+ if (this.openReplyTurn)
1008
+ this.refreshWorkingRow(this.openReplyTurn);
1009
+ this.setActivity(this.makeLoader(this.workingActivity));
1010
+ break;
1011
+ }
1012
+ case 'agent_end': {
1013
+ this.settleRun();
1014
+ // The node you're watching just finished its turn and handed control
1015
+ // back — ring the completion bell (the Claude-Code Stop-hook ding).
1016
+ // Best-effort/detached; gated on the `completion_bell` config setting.
1017
+ // Only ever reached inside a live viewer pane, so a headless/background
1018
+ // node (no ChatView) is always silent.
1019
+ ringCompletionBell();
1020
+ break;
1021
+ }
1022
+ // The whole run has truly settled (after any recovery/continuations). This
1023
+ // is the broker's canonical turn-over signal and is always relayed, so use
1024
+ // it as a safety net to clear a lingering activity loader: a missed or
1025
+ // abnormal `agent_end` would otherwise leave a dormant, between-wakes node
1026
+ // showing a frozen `Working…` spinner. No bell here — `agent_end` already
1027
+ // rang it on the normal path; this only cleans up display state.
1028
+ case 'agent_settled': {
1029
+ this.settleRun();
1030
+ break;
1031
+ }
1032
+ case 'message_start': {
1033
+ if (event.message.role === 'custom' || event.message.role === 'user') {
1034
+ this.addMessageToChat(event.message);
1035
+ // A card that joined a folded turn hides at once.
1036
+ if (this.openReplyTurn)
1037
+ this.refreshWorkingRow(this.openReplyTurn);
1038
+ this.applyToolDisplay();
1039
+ }
1040
+ else if (event.message.role === 'assistant') {
1041
+ const hasProse = assistantVisibleText(event.message).trim() !== '';
1042
+ if (hasProse)
1043
+ this.closeOpenGroup();
1044
+ this.streamingComponent = new ViewerAssistantMessageComponent(undefined, this.hideThinking, attachMarkdownTheme(), this.hiddenThinkingLabel, this.markdownTransformers);
1045
+ this.streamingWasGroupMember = !hasProse;
1046
+ this.appendAssistantPart(this.streamingComponent, !hasProse);
1047
+ this.registerCopyBlock(this.streamingComponent, 'assistant', '');
1048
+ this.streamingComponent.updateContent(event.message);
1049
+ this.registerCopyBlock(this.streamingComponent, 'assistant', assistantVisibleText(event.message));
1050
+ this.streamingToolSeparator = this.appendAssistantSeparator(!hasProse);
1051
+ this.setAssistantSeparatorContent(this.streamingToolSeparator, event.message);
1052
+ }
1053
+ break;
1054
+ }
1055
+ case 'message_update': {
1056
+ if (this.streamingComponent && event.message.role === 'assistant') {
1057
+ this.promoteStreamingAssistantToBoundary(event.message);
1058
+ // Incomplete Mermaid fences and HTML pairs stay literal until their
1059
+ // closing marker arrives; the transformers upgrade them on the render
1060
+ // that follows, with no separate mid-stream path.
1061
+ this.streamingComponent.updateContent(event.message);
1062
+ this.registerCopyBlock(this.streamingComponent, 'assistant', assistantVisibleText(event.message));
1063
+ this.historyContainer.markDirty(this.streamingComponent);
1064
+ const toolCalls = this.assistantToolCalls(event.message);
1065
+ if (this.streamingToolSeparator)
1066
+ this.setAssistantSeparatorContent(this.streamingToolSeparator, event.message);
1067
+ for (const content of toolCalls) {
1068
+ this.pushTranscriptValue(content.arguments);
1069
+ const existing = this.pendingTools.get(content.id);
1070
+ if (existing) {
1071
+ existing.updateArgs(content.arguments);
1072
+ this.noteGroupTool(existing, content.name, content.arguments);
1073
+ this.historyContainer.markDirty(existing);
1074
+ }
1075
+ else {
1076
+ const component = this.appendToolComponent(content.name, content.id, content.arguments);
1077
+ this.pendingTools.set(content.id, component);
1078
+ }
1079
+ }
1080
+ }
1081
+ break;
1082
+ }
1083
+ case 'message_end': {
1084
+ if (event.message.role !== 'assistant')
1085
+ break;
1086
+ const endedWithFailure = event.message.stopReason === 'aborted' || event.message.stopReason === 'error';
1087
+ // A terminal failure is always its own visible boundary, including an
1088
+ // empty abort created by yield or a daemon restart.
1089
+ this.promoteStreamingAssistantToBoundary(event.message, endedWithFailure);
1090
+ // Stash the completed reply's text for `/copy` (skip aborted/error turns,
1091
+ // whose text is partial or absent).
1092
+ if (this.streamingComponent)
1093
+ this.registerCopyBlock(this.streamingComponent, 'assistant', assistantVisibleText(event.message));
1094
+ if (event.message.stopReason !== 'aborted' && event.message.stopReason !== 'error') {
1095
+ const text = assistantVisibleText(event.message);
1096
+ if (text.trim()) {
1097
+ this.lastAssistantText = text;
1098
+ this.pushTranscriptText(text);
1099
+ }
1100
+ }
1101
+ if (this.streamingComponent) {
1102
+ const stopReason = event.message.stopReason;
1103
+ let errorMessage = event.message.errorMessage;
1104
+ // An aborted turn may be a user interrupt or a lifecycle interruption
1105
+ // (a refresh-yield aborts its own turn). Providers spell it several
1106
+ // ways — including `stopReason: 'error'` carrying a bare AbortError,
1107
+ // which would otherwise render as a red `Error: This operation was
1108
+ // aborted` for a perfectly healthy yield — so override it outright
1109
+ // with one plain, human label.
1110
+ if (endedByAbort(event.message)) {
1111
+ errorMessage = 'Interrupted';
1112
+ // Surface the abort on the assistant bubble itself, mirroring pi
1113
+ // (interactive-mode.js:2280 sets streamingMessage.errorMessage before
1114
+ // updateContent) so the rendered message shows the annotation. The
1115
+ // stopReason moves with it: pi's component reserves its red
1116
+ // `Error: …` line for stopReason 'error', and an abort is not one.
1117
+ event.message.errorMessage = errorMessage;
1118
+ event.message.stopReason = 'aborted';
1119
+ }
1120
+ this.streamingComponent.updateContent(event.message);
1121
+ if (stopReason === 'aborted' || stopReason === 'error') {
1122
+ const text = errorMessage ?? 'Error';
1123
+ for (const component of this.pendingTools.values()) {
1124
+ component.updateResult({ content: [{ type: 'text', text }], isError: true });
1125
+ this.registerCopyBlock(component, 'tool', text);
1126
+ this.settleGroupTool(component, { content: [{ type: 'text', text }], isError: true }, true);
1127
+ this.historyContainer.markDirty(component);
1128
+ }
1129
+ this.pendingTools.clear();
1130
+ }
1131
+ else {
1132
+ // Finalize renderer caches now that every tool argument is complete.
1133
+ for (const component of this.pendingTools.values()) {
1134
+ component.setArgsComplete();
1135
+ this.historyContainer.markDirty(component);
1136
+ }
1137
+ }
1138
+ this.historyContainer.markDirty(this.streamingComponent);
1139
+ this.streamingComponent = undefined;
1140
+ this.streamingToolSeparator = undefined;
1141
+ }
1142
+ if (endedWithFailure) {
1143
+ this.closeOpenGroup();
1144
+ // A summary normally follows this terminal frame, but re-evaluate now
1145
+ // too so an early recap immediately folds the tools before this seam.
1146
+ this.applyToolDisplay();
1147
+ }
1148
+ // The finished message's prose moves into the reply; at Replies only
1149
+ // its live copy folds.
1150
+ this.recordTurnProse(event.message, true);
1151
+ if (this.openReplyTurn)
1152
+ this.refreshWorkingRow(this.openReplyTurn);
1153
+ this.applyToolDisplay();
1154
+ break;
1155
+ }
1156
+ case 'tool_execution_start': {
1157
+ this.pushTranscriptValue(event.args);
1158
+ let component = this.pendingTools.get(event.toolCallId);
1159
+ if (!component) {
1160
+ component = this.appendToolComponent(event.toolName, event.toolCallId, event.args);
1161
+ this.pendingTools.set(event.toolCallId, component);
1162
+ }
1163
+ else {
1164
+ this.noteGroupTool(component, event.toolName, event.args);
1165
+ }
1166
+ component.markExecutionStarted();
1167
+ this.historyContainer.markDirty(component);
1168
+ break;
1169
+ }
1170
+ case 'tool_execution_update': {
1171
+ const result = this.projection.partialToolResults.get(event.toolCallId) ?? event.partialResult;
1172
+ this.pushTranscriptValue(result);
1173
+ const component = this.pendingTools.get(event.toolCallId);
1174
+ if (component) {
1175
+ component.updateResult(result, true);
1176
+ this.registerCopyBlock(component, 'tool', this.toolResultText(result));
1177
+ this.historyContainer.markDirty(component);
1178
+ }
1179
+ break;
1180
+ }
1181
+ case 'tool_execution_end': {
1182
+ const result = this.projection.partialToolResults.get(event.toolCallId) ?? event.result;
1183
+ this.pushTranscriptValue(result);
1184
+ const component = this.pendingTools.get(event.toolCallId);
1185
+ if (component) {
1186
+ component.updateResult(result);
1187
+ this.registerCopyBlock(component, 'tool', this.toolResultText(result));
1188
+ this.pendingTools.delete(event.toolCallId);
1189
+ this.settleGroupTool(component, result, event.isError);
1190
+ this.applyToolDisplay();
1191
+ this.historyContainer.markDirty(component);
1192
+ this.maybeAppendPageBlock(result);
1193
+ }
1194
+ break;
1195
+ }
1196
+ case 'compaction_start': {
1197
+ const label = event.reason === 'manual' ? 'Compacting context...' : 'Auto-compacting...';
1198
+ this.setActivity(this.makeLoader(label));
1199
+ break;
1200
+ }
1201
+ case 'compaction_end': {
1202
+ this.setActivity(this.runActive ? this.makeLoader(this.workingActivity) : undefined);
1203
+ if (event.aborted) {
1204
+ this.showStatus(event.reason === 'manual' ? 'Compaction cancelled' : 'Auto-compaction cancelled');
1205
+ }
1206
+ else if (event.result) {
1207
+ // 0.78.1 divergence from the §3.2 sketch: `compaction_end` carries only
1208
+ // the CompactionResult (summary + tokensBefore), NOT the post-compaction
1209
+ // message list — so the viewer cannot clear+rebuild the transcript the
1210
+ // way in-process pi does (it rebuilds from its own SessionManager). We
1211
+ // append the compaction summary marker instead and KEEP the
1212
+ // pre-compaction scrollback for the rest of this attach session; a fresh
1213
+ // re-attach gets the already-compacted history via `welcome`. (Reported
1214
+ // in T5's final.)
1215
+ this.addMessageToChat({
1216
+ role: 'compactionSummary',
1217
+ summary: event.result.summary,
1218
+ tokensBefore: event.result.tokensBefore,
1219
+ timestamp: Date.now(),
1220
+ });
1221
+ }
1222
+ else if (event.errorMessage) {
1223
+ this.showError(event.errorMessage);
1224
+ }
1225
+ break;
1226
+ }
1227
+ case 'auto_retry_start': {
1228
+ const seconds = Math.ceil(event.delayMs / 1000);
1229
+ this.setActivity(this.makeLoader(`Retrying (${event.attempt}/${event.maxAttempts}) in ${seconds}s...`));
1230
+ break;
1231
+ }
1232
+ case 'auto_retry_end': {
1233
+ this.setActivity(this.runActive ? this.makeLoader(this.workingActivity) : undefined);
1234
+ if (!event.success) {
1235
+ this.showError(`Retry failed after ${event.attempt} attempts: ${event.finalError ?? 'Unknown error'}`);
1236
+ }
1237
+ break;
1238
+ }
1239
+ // Footer/header-only — ChatView owns no footer; forward to the sink.
1240
+ case 'queue_update':
1241
+ case 'session_info_changed':
1242
+ case 'thinking_level_changed':
1243
+ this.onFooterEvent?.(event);
1244
+ break;
1245
+ // turn_start / turn_end — interactive pi ignores these (falls through
1246
+ // default); the viewer does too.
1247
+ default:
1248
+ break;
1249
+ }
1250
+ // No unconditional markDirty here: appends/removes invalidate through
1251
+ // MeasuredContainer, and branches that mutate a child in place explicitly
1252
+ // mark it dirty. Activity-only events leave settled history cached while the
1253
+ // independent status loader animates.
1254
+ this.tui.requestRender();
1255
+ }
1256
+ // `!` bash live stream (broker bash_start/bash_output/bash_end frames). Mirrors
1257
+ // pi interactive mode's `!` handling: create the component on start, stream
1258
+ // chunks into it, mark complete on end. The persisted `bashExecution` message
1259
+ // also rides the next snapshot, so this only drives the LIVE view.
1260
+ bashStart(command, excludeFromContext) {
1261
+ if (this.deferIfBuilding(() => this.bashStart(command, excludeFromContext)))
1262
+ return;
1263
+ this.projection = projectBashStart(this.projection, command, excludeFromContext);
1264
+ this.closeOpenGroup();
1265
+ this.settleBashComponent();
1266
+ let component;
1267
+ component = new BashExecutionComponent(command, this.componentTui(() => component), excludeFromContext);
1268
+ this.bashComponent = component;
1269
+ this.append(component);
1270
+ this.tui.requestRender();
1271
+ }
1272
+ bashOutput(chunk) {
1273
+ if (this.deferIfBuilding(() => this.bashOutput(chunk)))
1274
+ return;
1275
+ this.projection = projectBashOutput(this.projection, chunk);
1276
+ this.pushTranscriptText(chunk);
1277
+ if (this.bashComponent) {
1278
+ this.bashComponent.appendOutput(chunk);
1279
+ this.historyContainer.markDirty(this.bashComponent);
1280
+ }
1281
+ this.tui.requestRender();
1282
+ }
1283
+ bashEnd(result) {
1284
+ if (this.deferIfBuilding(() => this.bashEnd(result)))
1285
+ return;
1286
+ this.projection = projectBashEnd(this.projection, result);
1287
+ this.settleBashComponent(result);
1288
+ this.tui.requestRender();
1289
+ }
1290
+ // Rebuild path (ports addMessageToChat, interactive-mode.js:2483).
1291
+ addMessageToChat(message) {
1292
+ // Crouter-generated context retains its runtime role (user vs custom) so
1293
+ // delivery to the model is unchanged, but every attached view presents it
1294
+ // through one compact disclosure contract. The producer's envelope is what
1295
+ // classifies, so an ordinary user prompt cannot acquire this treatment and
1296
+ // saved transcripts gain it too.
1297
+ const card = parseCard(message);
1298
+ if (card !== null &&
1299
+ (message.role !== 'custom' || message.display === true)) {
1300
+ this.pushTranscriptText(card.body);
1301
+ // A person's inbox answer is the person speaking: their words leave the
1302
+ // card and render as their own message. A digest carrying nothing else
1303
+ // gets no card at all — but a passive backlog folded into the same body
1304
+ // is content, so the residue check keeps it from vanishing with the card.
1305
+ const answers = card.senders
1306
+ .flatMap((sender) => sender.entries)
1307
+ .filter(isHumanWordsEntry)
1308
+ .map((entry) => entry.body.trim())
1309
+ .filter((text) => text !== '');
1310
+ const onlyHumanWords = answers.length > 0
1311
+ && card.body.replace(INBOX_SENDER_SECTIONS, '').trim() === ''
1312
+ && card.senders.every((sender) => sender.entries.every(isHumanWordsEntry));
1313
+ if (!onlyHumanWords) {
1314
+ const presentation = presentationFor(card.kind);
1315
+ const component = new ContextMessageComponent(card, presentation, this.toolOutputExpanded(), this.dimStyle, (s) => this.spinnerStyle(this.labelStyle(s)));
1316
+ // A boundary card is a visible seam, not a group member: the preceding
1317
+ // span keeps its own recap and the next tool call begins a
1318
+ // broker-aligned fresh group.
1319
+ if (isGroupBoundaryKind(card.kind)) {
1320
+ this.closeOpenGroup();
1321
+ this.append(component);
1322
+ }
1323
+ else {
1324
+ // A folded group hides its members, so whatever the card should leave
1325
+ // behind — a child's final, a recovery — reaches the recap here.
1326
+ this.appendGroupMember(component)?.activity.noteCard(card, presentation);
1327
+ }
1328
+ }
1329
+ for (const answer of answers)
1330
+ this.appendHumanAnswer(answer);
1331
+ return;
1332
+ }
1333
+ switch (message.role) {
1334
+ case 'bashExecution': {
1335
+ this.closeOpenGroup();
1336
+ this.pushTranscriptText(message.output ?? '');
1337
+ const component = new BashExecutionComponent(message.command, this.tui, message.excludeFromContext);
1338
+ if (message.output)
1339
+ component.appendOutput(message.output);
1340
+ component.setComplete(message.exitCode, message.cancelled,
1341
+ // pi's interactive mode passes a minimal `{truncated:true}` marker here
1342
+ // (interactive-mode.js:2489) where the typed param is the full
1343
+ // TruncationResult; the snapshot message only carries the boolean, so we
1344
+ // mirror pi and cast.
1345
+ message.truncated ? { truncated: true } : undefined, message.fullOutputPath);
1346
+ this.append(component);
1347
+ break;
1348
+ }
1349
+ case 'custom': {
1350
+ if (message.display) {
1351
+ this.pushTranscriptText(this.userMessageText(message));
1352
+ if (message.customType === CRTR_OUTPUT_CUSTOM_TYPE) {
1353
+ this.appendGroupMember(new CrtrOutputMessageComponent(this.userMessageText(message), this.toolOutputExpanded(), this.crtrOutputTheme()));
1354
+ break;
1355
+ }
1356
+ // A refresh-yield cycle boundary (session-cycles.ts, synthetic — never
1357
+ // persisted): render as a dim rule rather than the generic custom-
1358
+ // message card, so scrolling through a multi-cycle node's full history
1359
+ // reads as one conversation with clear seams between cycles.
1360
+ if (message.customType === CRTR_CYCLE_DIVIDER_CUSTOM_TYPE) {
1361
+ this.closeOpenGroup();
1362
+ this.append(new Spacer(1));
1363
+ this.append(new Text(this.dimStyle(`── ${this.userMessageText(message)} ──`), 1, 0));
1364
+ this.append(new Spacer(1));
1365
+ break;
1366
+ }
1367
+ const component = new CustomMessageComponent(styleAttachMessageMarkdown(message), undefined, attachMarkdownTheme());
1368
+ component.setExpanded(this.toolOutputExpanded());
1369
+ this.appendGroupMember(component);
1370
+ }
1371
+ break;
1372
+ }
1373
+ case 'compactionSummary': {
1374
+ this.closeOpenGroup();
1375
+ this.append(new Spacer(1));
1376
+ const component = new CompactionSummaryMessageComponent(styleAttachSummaryMarkdown(message), attachMarkdownTheme());
1377
+ component.setExpanded(this.toolOutputExpanded());
1378
+ this.append(component);
1379
+ break;
1380
+ }
1381
+ case 'branchSummary': {
1382
+ this.closeOpenGroup();
1383
+ this.append(new Spacer(1));
1384
+ const component = new BranchSummaryMessageComponent(styleAttachSummaryMarkdown(message), attachMarkdownTheme());
1385
+ component.setExpanded(this.toolOutputExpanded());
1386
+ this.append(component);
1387
+ this.registerCopyBlock(component, 'assistant', message.summary);
1388
+ break;
1389
+ }
1390
+ case 'user': {
1391
+ if (isTrueUserMessage(message))
1392
+ this.closeOpenGroup();
1393
+ // The person's message stands outside every turn and opens the next
1394
+ // one, whose reply (shown at Replies only) sits directly beneath it.
1395
+ if (isTrueUserMessage(message) && this.consolidatingHere()) {
1396
+ // A turn carried over from condensed history ends here; give it its reply.
1397
+ if (!this.openReplyTurn && this.carriedTurn.prose.length > 0)
1398
+ this.currentTurn();
1399
+ this.outsideTurns++;
1400
+ try {
1401
+ this.appendUserMessage(message);
1402
+ }
1403
+ finally {
1404
+ this.outsideTurns--;
1405
+ }
1406
+ this.beginTurn(messageKey(message) ?? `local-${this.turns.length}`);
1407
+ break;
1408
+ }
1409
+ this.appendUserMessage(message);
1410
+ break;
1411
+ }
1412
+ case 'assistant': {
1413
+ const hasProse = assistantVisibleText(message).trim() !== '';
1414
+ if (hasProse)
1415
+ this.closeOpenGroup();
1416
+ this.appendAssistantMessage(message, !hasProse);
1417
+ break;
1418
+ }
1419
+ // toolResult is rendered inline with its tool call (handled in applySnapshot).
1420
+ default:
1421
+ break;
1422
+ }
1423
+ }
1424
+ appendUserMessage(message) {
1425
+ const textContent = this.userMessageText(message);
1426
+ if (!textContent)
1427
+ return;
1428
+ this.pushTranscriptText(textContent);
1429
+ if (this.chatChildCount() > 0)
1430
+ this.appendUserPart(new Spacer(1), !isTrueUserMessage(message));
1431
+ const skillBlock = parseSkillBlock(textContent);
1432
+ if (skillBlock) {
1433
+ // SkillInvocationMessageComponent has no transformer seam, so its body
1434
+ // is still styled before construction.
1435
+ const component = new SkillInvocationMessageComponent({ ...skillBlock, content: styleAttachMarkdownSource(skillBlock.content) }, attachMarkdownTheme());
1436
+ component.setExpanded(this.toolOutputExpanded());
1437
+ this.appendUserPart(component, !isTrueUserMessage(message));
1438
+ this.registerCopyBlock(component, 'user', textContent);
1439
+ if (skillBlock.userMessage) {
1440
+ const userMessage = new UserMessageComponent(skillBlock.userMessage, attachMarkdownTheme(), undefined, this.markdownTransformers);
1441
+ this.appendUserPart(userMessage, !isTrueUserMessage(message));
1442
+ this.registerCopyBlock(userMessage, 'user', skillBlock.userMessage);
1443
+ }
1444
+ }
1445
+ else {
1446
+ const component = new UserMessageComponent(textContent, attachMarkdownTheme(), undefined, this.markdownTransformers);
1447
+ this.appendUserPart(component, !isTrueUserMessage(message));
1448
+ this.registerCopyBlock(component, 'user', textContent);
1449
+ }
1450
+ }
1451
+ // Helpers
1452
+ /** Render an assistant reply plus its initially-hidden boundary separator.
1453
+ * A turn that ended on its own abort is rendered as the interrupt it is,
1454
+ * matching the live seam above, so re-reading the transcript later never
1455
+ * turns a healthy interrupt into a red `Error:` line. */
1456
+ appendAssistantMessage(message, groupMember = false) {
1457
+ const component = new ViewerAssistantMessageComponent(undefined, this.hideThinking, attachMarkdownTheme(), this.hiddenThinkingLabel, this.markdownTransformers);
1458
+ const rendered = endedByAbort(message)
1459
+ ? { ...message, stopReason: 'aborted', errorMessage: 'Interrupted' }
1460
+ : message;
1461
+ component.updateContent(rendered);
1462
+ this.appendAssistantPart(component, groupMember);
1463
+ this.registerCopyBlock(component, 'assistant', assistantVisibleText(message));
1464
+ const separator = this.appendAssistantSeparator(groupMember);
1465
+ this.setAssistantSeparatorContent(separator, message);
1466
+ return separator;
1467
+ }
1468
+ /** Add a separator in transcript order now; it renders only after a following
1469
+ * tool settles in the folded view. */
1470
+ appendAssistantSeparator(groupMember = false) {
1471
+ const separator = new FoldedToolSeparator();
1472
+ if (groupMember)
1473
+ this.appendGroupMember(separator);
1474
+ else
1475
+ this.append(separator);
1476
+ return separator;
1477
+ }
1478
+ appendAssistantPart(component, groupMember) {
1479
+ if (groupMember)
1480
+ this.appendGroupMember(component);
1481
+ else
1482
+ this.append(component);
1483
+ }
1484
+ appendUserPart(component, groupMember) {
1485
+ if (groupMember)
1486
+ this.appendGroupMember(component);
1487
+ else
1488
+ this.append(component);
1489
+ }
1490
+ /** An answer the person typed in their inbox renders exactly like a message
1491
+ * they typed here, and closes the run around it the same way. */
1492
+ appendHumanAnswer(text) {
1493
+ this.outsideTurns++;
1494
+ try {
1495
+ this.appendHumanAnswerParts(text);
1496
+ }
1497
+ finally {
1498
+ this.outsideTurns--;
1499
+ }
1500
+ }
1501
+ appendHumanAnswerParts(text) {
1502
+ this.closeOpenGroup();
1503
+ const live = this.appendTarget === this.historyContainer;
1504
+ if (this.chatChildCount() > 0) {
1505
+ const spacer = new Spacer(1);
1506
+ this.append(spacer);
1507
+ if (live)
1508
+ this.trackInboxAnswer(spacer);
1509
+ }
1510
+ const component = new UserMessageComponent(text, attachMarkdownTheme(), undefined, this.markdownTransformers);
1511
+ this.append(component);
1512
+ if (live)
1513
+ this.trackInboxAnswer(component);
1514
+ this.registerCopyBlock(component, 'user', text);
1515
+ }
1516
+ trackInboxAnswer(component) {
1517
+ this.inboxAnswers.add(component);
1518
+ if (this.hidesInboxExchange())
1519
+ this.historyContainer.setHidden(component, true);
1520
+ }
1521
+ /** Only the full-fidelity trailing region gets summary groups. Condensed
1522
+ * history intentionally drops tool traffic, so grouping there would create
1523
+ * phantom summary rows and cross the live/condensed boundary. */
1524
+ isLiveGroupRegion() {
1525
+ return this.appendTarget === this.historyContainer;
1526
+ }
1527
+ ensureGroup() {
1528
+ if (!this.isLiveGroupRegion())
1529
+ return undefined;
1530
+ if (this.openGroup)
1531
+ return this.openGroup;
1532
+ const recap = new GroupRecapComponent();
1533
+ const group = {
1534
+ members: [],
1535
+ recap,
1536
+ activity: new GroupActivityRecorder(this.cwd, this.nodeRoster),
1537
+ toolCount: 0,
1538
+ inFlight: new Set(),
1539
+ };
1540
+ this.append(recap);
1541
+ // The recap is a direct history child for cache identity, but zero-row and
1542
+ // hidden until a settled broker summary makes this group collapsible.
1543
+ this.historyContainer.setHidden(recap, true);
1544
+ this.groups.push(group);
1545
+ this.openGroup = group;
1546
+ return group;
1547
+ }
1548
+ closeOpenGroup() {
1549
+ this.openGroup = undefined;
1550
+ }
1551
+ appendGroupMember(component) {
1552
+ const group = this.ensureGroup();
1553
+ this.append(component);
1554
+ if (group)
1555
+ group.members.push(component);
1556
+ return group;
1557
+ }
1558
+ removeGroupMember(component) {
1559
+ for (const group of this.groups) {
1560
+ const index = group.members.indexOf(component);
1561
+ if (index !== -1)
1562
+ group.members.splice(index, 1);
1563
+ }
1564
+ this.historyContainer.setHidden(component, false);
1565
+ }
1566
+ /** Add one tool as a group member, moving the assistant's boundary separator
1567
+ * behind the new summary row without changing the separator's identity. */
1568
+ appendToolComponent(name, id, args) {
1569
+ const trailingSeparator = this.isLiveGroupRegion() &&
1570
+ !this.openGroup &&
1571
+ this.historyContainer.children.at(-1) instanceof FoldedToolSeparator
1572
+ ? this.historyContainer.children.at(-1)
1573
+ : undefined;
1574
+ if (trailingSeparator)
1575
+ this.historyContainer.removeChild(trailingSeparator);
1576
+ const group = this.ensureGroup();
1577
+ if (trailingSeparator) {
1578
+ this.append(trailingSeparator);
1579
+ group?.members.push(trailingSeparator);
1580
+ }
1581
+ const component = this.makeToolComponent(name, id, args);
1582
+ component.activityCallId = id;
1583
+ this.appendGroupMember(component);
1584
+ this.registerCopyBlock(component, 'tool', '');
1585
+ if (group) {
1586
+ group.key ??= id;
1587
+ group.toolCount++;
1588
+ group.inFlight.add(component);
1589
+ group.activity.noteCall(id, name, args);
1590
+ }
1591
+ return component;
1592
+ }
1593
+ noteGroupTool(component, name, args) {
1594
+ if (!component.activityCallId)
1595
+ return;
1596
+ for (const group of this.groups) {
1597
+ if (group.members.includes(component))
1598
+ group.activity.noteCall(component.activityCallId, name, args);
1599
+ }
1600
+ }
1601
+ settleGroupTool(component, result, isError = false) {
1602
+ for (const group of this.groups) {
1603
+ group.inFlight.delete(component);
1604
+ if (!component.activityCallId || !group.members.includes(component))
1605
+ continue;
1606
+ if (result === undefined)
1607
+ group.activity.resolveWithoutResult(component.activityCallId);
1608
+ else
1609
+ group.activity.settle(component.activityCallId, result, isError);
1610
+ }
1611
+ }
1612
+ /** An assistant starts as a non-boundary while its text is empty. Visible prose
1613
+ * or a terminal failure turns it into a boundary without recreating either
1614
+ * pi-owned component (their direct-child cache identities remain intact). */
1615
+ promoteStreamingAssistantToBoundary(message, force = false) {
1616
+ if (!this.streamingWasGroupMember || (!force && assistantVisibleText(message).trim() === ''))
1617
+ return;
1618
+ if (this.streamingComponent)
1619
+ this.removeGroupMember(this.streamingComponent);
1620
+ if (this.streamingToolSeparator)
1621
+ this.removeGroupMember(this.streamingToolSeparator);
1622
+ this.streamingWasGroupMember = false;
1623
+ this.closeOpenGroup();
1624
+ }
1625
+ seedToolGroupSummaries(summaries) {
1626
+ this.groupSummaries.clear();
1627
+ for (const [key, summary] of Object.entries(summaries))
1628
+ this.groupSummaries.set(key, summary);
1629
+ }
1630
+ /** Broker frames can arrive before or after their group's events, and snapshot
1631
+ * rebuilding defers them through the single-writer gate, so this stores first
1632
+ * and applies to every currently-rendered matching group. */
1633
+ applyToolGroupSummary(key, summary) {
1634
+ if (this.deferIfBuilding(() => this.applyToolGroupSummary(key, summary)))
1635
+ return;
1636
+ this.projection = projectToolGroupSummary(this.projection, key, summary);
1637
+ const projected = this.projection.toolGroupSummaryDetails[key];
1638
+ if (projected === undefined)
1639
+ return;
1640
+ this.groupSummaries.set(key, projected);
1641
+ this.applyToolDisplay();
1642
+ }
1643
+ applyGroupDisplay(group, turnFolded) {
1644
+ const summary = group.key === undefined ? undefined : this.groupSummaries.get(group.key);
1645
+ const collapsed = this.showsGroupSummaries() &&
1646
+ group.toolCount > 0 &&
1647
+ group.inFlight.size === 0 &&
1648
+ summary !== undefined;
1649
+ group.recap.setRecap(collapsed ? summary : undefined, group.toolCount, group.activity.activity(), this.detailedToolRecaps, this.recapPalette);
1650
+ this.historyContainer.setHidden(group.recap, !collapsed || turnFolded.has(group.recap));
1651
+ for (const member of group.members)
1652
+ this.historyContainer.setHidden(member, collapsed || turnFolded.has(member));
1653
+ }
1654
+ /** Make each separator visible only if its immediately-following tool call is
1655
+ * actually folded; in-flight calls remain flush with their live output. */
1656
+ updateFoldedToolSeparators(inFlight = new Set(this.pendingTools.values())) {
1657
+ const children = this.historyContainer.children;
1658
+ for (let i = 0; i < children.length; i++) {
1659
+ const separator = children[i];
1660
+ if (!(separator instanceof FoldedToolSeparator))
1661
+ continue;
1662
+ const followingTool = children[i + 1];
1663
+ separator.setFolded(this.foldsSettledTools() &&
1664
+ !this.historyContainer.hiddenChildren.has(separator) &&
1665
+ followingTool instanceof MinimizableToolComponent &&
1666
+ !this.historyContainer.hiddenChildren.has(followingTool) &&
1667
+ !inFlight.has(followingTool));
1668
+ this.historyContainer.markDirty(separator);
1669
+ }
1670
+ }
1671
+ /** Track whether an assistant response contains prose or thinking, then make
1672
+ * its separator eligible only for content the current Ctrl+T setting shows. */
1673
+ setAssistantSeparatorContent(separator, message) {
1674
+ const content = message.content;
1675
+ const parts = Array.isArray(content) ? content : [];
1676
+ const hasText = parts.some((part) => typeof part === 'object' &&
1677
+ part !== null &&
1678
+ part.type === 'text' &&
1679
+ typeof part.text === 'string' &&
1680
+ part.text.trim() !== '');
1681
+ const hasThinking = parts.some((part) => typeof part === 'object' &&
1682
+ part !== null &&
1683
+ part.type === 'thinking' &&
1684
+ typeof part.thinking === 'string' &&
1685
+ part.thinking.trim() !== '');
1686
+ this.foldedToolSeparatorContents.set(separator, { hasText, hasThinking });
1687
+ separator.setSeparatesToolGroup(hasText || (!this.hideThinking && hasThinking));
1688
+ }
1689
+ /** Tool component with native viewer renderers for crouter-owned tool output. */
1690
+ makeToolComponent(name, id, args) {
1691
+ const fold = new FoldedToolCallController();
1692
+ let resultObserver;
1693
+ let toolDefinition;
1694
+ if (name === 'bash') {
1695
+ const crtr = createCrtrBashToolDefinition(args, fold);
1696
+ if (crtr === undefined) {
1697
+ toolDefinition = createCrtrPlainBashToolDefinition(this.cwd, fold, this.backgroundBashHint);
1698
+ }
1699
+ else {
1700
+ toolDefinition = crtr.definition;
1701
+ }
1702
+ }
1703
+ else if (name === 'edit') {
1704
+ const edit = createCrtrEditToolDefinition(this.cwd, fold);
1705
+ toolDefinition = edit.definition;
1706
+ resultObserver = edit.observeResult;
1707
+ }
1708
+ else if (name === 'read') {
1709
+ toolDefinition = createCrtrReadToolDefinition(this.cwd, fold);
1710
+ }
1711
+ else if (name === 'write') {
1712
+ toolDefinition = createCrtrWriteToolDefinition(this.cwd, fold);
1713
+ }
1714
+ let component;
1715
+ component = new MinimizableToolComponent(name, id, args, { showImages: this.showImages, imageWidthCells: this.imageWidthCells }, toolDefinition, this.componentTui(() => component), this.cwd);
1716
+ component.setToolView(toolDefinition === undefined ? undefined : fold, resultObserver);
1717
+ component.setExpanded(this.toolOutputExpanded());
1718
+ return component;
1719
+ }
1720
+ /** Append conversation content above the independent live status area — or into
1721
+ * the nested container while condensed history is under construction. */
1722
+ append(child) {
1723
+ if (this.outsideTurns === 0 && this.consolidatingHere()) {
1724
+ const turn = this.currentTurn();
1725
+ this.appendTarget.addChild(child);
1726
+ turn.members.add(child);
1727
+ return;
1728
+ }
1729
+ this.appendTarget.addChild(child);
1730
+ }
1731
+ /** Number of rendered conversation components in the container currently being
1732
+ * appended to (live history or the nested condensed region). */
1733
+ chatChildCount() {
1734
+ return this.appendTarget.children.length;
1735
+ }
1736
+ /** Clear all chat content. */
1737
+ resetChat() {
1738
+ this.setActivity(undefined);
1739
+ this.settleBashComponent();
1740
+ this.streamingComponent = undefined;
1741
+ this.streamingToolSeparator = undefined;
1742
+ this.streamingWasGroupMember = false;
1743
+ this.foldedToolSeparatorContents.clear();
1744
+ this.groups.length = 0;
1745
+ this.openGroup = undefined;
1746
+ this.turns.length = 0;
1747
+ this.openReplyTurn = undefined;
1748
+ this.carriedTurn = { key: START_TURN_KEY, prose: [] };
1749
+ this.turnHidden = new Set();
1750
+ this.condensedBlocks = {};
1751
+ this.lastReplyText = undefined;
1752
+ this.groupSummaries.clear();
1753
+ this.nodeRoster.clear();
1754
+ this.pendingTools.clear();
1755
+ this.lastAssistantText = undefined;
1756
+ this.copyBlockRecords.length = 0;
1757
+ this.copyIndex.clear();
1758
+ this.transcriptFilePaths.length = 0;
1759
+ this.transcriptDocRefs.length = 0;
1760
+ this.pageBlocks.clear();
1761
+ this.inboxAnswers.clear();
1762
+ this.historyContainer.clear();
1763
+ }
1764
+ /** Place the transcript block for an inline page a `human send` just raised.
1765
+ * The block is a plain history child, NOT a tool-group member: collapsing the
1766
+ * tool group folds the command away and leaves the page itself on screen, the
1767
+ * way assistant prose stays. Condensed history is skipped deliberately — old
1768
+ * cycles keep only prose and cycle seams. */
1769
+ maybeAppendPageBlock(result) {
1770
+ if (!this.inlinePageBlocks || this.appendTarget !== this.historyContainer)
1771
+ return;
1772
+ const page = detectInlinePageResult(result);
1773
+ if (page === undefined || this.pageBlocks.has(page.pageId))
1774
+ return;
1775
+ const block = new PageBlockComponent(page.pageId, this.pageOpenHint);
1776
+ this.pageBlocks.set(page.pageId, block);
1777
+ // A page asks the person something; it never folds into the working.
1778
+ this.outsideTurns++;
1779
+ try {
1780
+ this.append(block);
1781
+ }
1782
+ finally {
1783
+ this.outsideTurns--;
1784
+ }
1785
+ // The block is placed empty and fills itself from the daemon: reading a
1786
+ // request is a round trip, and the transcript must not block on one.
1787
+ void this.loadPageBlock(block);
1788
+ }
1789
+ async loadPageBlock(block) {
1790
+ if (!(await block.refresh()))
1791
+ return;
1792
+ this.historyContainer.setHidden(block, this.hidesInboxExchange() && block.settled);
1793
+ this.historyContainer.markDirty(block);
1794
+ this.tui.requestRender();
1795
+ }
1796
+ /** Re-measure the tool calls still in flight. A silent long-running command
1797
+ * emits no tool-execution update, so nothing else would evict its cached
1798
+ * lines and its backgrounding hint would never appear. Driven by the
1799
+ * viewer's existing low-rate chrome poll, and cheap because it touches only
1800
+ * in-flight tools — usually one, never the transcript. */
1801
+ refreshInFlightTools() {
1802
+ if (this.pendingTools.size === 0)
1803
+ return;
1804
+ for (const component of this.pendingTools.values())
1805
+ this.historyContainer.markDirty(component);
1806
+ this.tui.requestRender();
1807
+ }
1808
+ /** Re-read every placed page through the daemon. Driven by the viewer's
1809
+ * ticket-activity watcher, so an answer, a cancellation, or a `--replace`
1810
+ * revision lands on the block already anchored in the transcript. */
1811
+ async refreshPageBlocks() {
1812
+ const blocks = [...this.pageBlocks.values()];
1813
+ const changed = await Promise.all(blocks.map(async (block) => {
1814
+ const moved = await block.refresh();
1815
+ if (moved) {
1816
+ this.historyContainer.setHidden(block, this.hidesInboxExchange() && block.settled);
1817
+ this.historyContainer.markDirty(block);
1818
+ }
1819
+ return moved;
1820
+ }));
1821
+ if (changed.some(Boolean))
1822
+ this.tui.requestRender();
1823
+ }
1824
+ makeLoader(message) {
1825
+ // Loader updates itself on an interval. Its TUI callback has to evict the
1826
+ // status block's cached frame before requesting the next render.
1827
+ let loader;
1828
+ const statusTui = {
1829
+ requestRender: (force) => {
1830
+ if (loader && !this.onActivityChange)
1831
+ this.statusContainer.markDirty(loader);
1832
+ this.tui.requestRender(force);
1833
+ },
1834
+ terminal: this.tui.terminal,
1835
+ };
1836
+ loader = new Loader(statusTui, this.spinnerStyle, this.dimStyle, message);
1837
+ return loader;
1838
+ }
1839
+ /** Let a self-updating history child invalidate only its own cached lines. */
1840
+ componentTui(component) {
1841
+ return {
1842
+ requestRender: (force) => {
1843
+ this.historyContainer.markDirty(component());
1844
+ this.tui.requestRender(force);
1845
+ },
1846
+ terminal: this.tui.terminal,
1847
+ };
1848
+ }
1849
+ /** Complete and release the live bash component before ChatView gives up ownership. */
1850
+ settleBashComponent(result) {
1851
+ if (!this.bashComponent)
1852
+ return;
1853
+ const component = this.bashComponent;
1854
+ component.setComplete(result?.exitCode, result?.cancelled ?? true, result?.truncated ? { truncated: true } : undefined, result?.fullOutputPath);
1855
+ this.historyContainer.markDirty(component);
1856
+ this.bashComponent = undefined;
1857
+ }
1858
+ /** Swap the single active activity indicator (working/compaction/retry). */
1859
+ setActivity(loader) {
1860
+ this.activityLoader?.stop();
1861
+ this.activityLoader = loader;
1862
+ if (this.onActivityChange) {
1863
+ this.onActivityChange(loader);
1864
+ return;
1865
+ }
1866
+ this.statusContainer.clear();
1867
+ if (loader)
1868
+ this.statusContainer.addChild(loader);
1869
+ }
1870
+ showStatus(message) {
1871
+ this.closeOpenGroup();
1872
+ this.append(new Spacer(1));
1873
+ this.append(new Text(this.dimStyle(message), 1, 0));
1874
+ }
1875
+ /** Append an error to the transcript. pi's own error events land here, and so
1876
+ * do the broker's `error` frames: their text is the engine's own and is
1877
+ * routinely multi-line (pi's login help is three lines), which the one-row
1878
+ * status notice cannot show. */
1879
+ showError(message) {
1880
+ if (this.deferIfBuilding(() => this.showError(message)))
1881
+ return;
1882
+ this.closeOpenGroup();
1883
+ // An error stays in view even when consolidated replies fold the turn.
1884
+ this.outsideTurns++;
1885
+ try {
1886
+ this.append(new Spacer(1));
1887
+ this.append(new Text(this.errorStyle(message), 1, 0));
1888
+ }
1889
+ finally {
1890
+ this.outsideTurns--;
1891
+ }
1892
+ this.tui.requestRender();
1893
+ }
1894
+ crtrOutputTheme() {
1895
+ return {
1896
+ fg: (name, text) => {
1897
+ if (name === 'error')
1898
+ return this.errorStyle(text);
1899
+ if (name === 'warning' || name === 'accent' || name === 'toolTitle' || name === 'success')
1900
+ return this.spinnerStyle(text);
1901
+ if (name === 'muted')
1902
+ return this.dimStyle(text);
1903
+ return text;
1904
+ },
1905
+ bg: (_name, text) => text,
1906
+ bold: (text) => this.labelStyle(text),
1907
+ };
1908
+ }
1909
+ /** Extract the tool-call content items from an assistant message. */
1910
+ assistantToolCalls(message) {
1911
+ const content = message.content;
1912
+ if (!Array.isArray(content))
1913
+ return [];
1914
+ return content.filter((c) => typeof c === 'object' && c !== null && c.type === 'toolCall');
1915
+ }
1916
+ /** Existing file paths from the rendered transcript, newest first. */
1917
+ getTranscriptFilePathsNewestFirst() {
1918
+ return [...this.transcriptFilePaths];
1919
+ }
1920
+ /** `[[ref]]` document references from the transcript, newest first, deduped. */
1921
+ getTranscriptDocRefsNewestFirst() {
1922
+ return [...this.transcriptDocRefs];
1923
+ }
1924
+ /** Re-run every Markdown transform: a document link's rendered target changed. */
1925
+ refreshMarkdown() {
1926
+ this.historyContainer.invalidate();
1927
+ this.tui.requestRender();
1928
+ }
1929
+ /** The text of the most recent assistant message, for `/copy`. Undefined when
1930
+ * no assistant message has been seen (or it had no text content). */
1931
+ getLastAssistantText() {
1932
+ const t = (this.repliesOnly() ? this.lastReplyText ?? this.lastAssistantText : this.lastAssistantText)?.trim();
1933
+ return t ? t : undefined;
1934
+ }
1935
+ /** Copyable source text for a transcript block, if it has any. */
1936
+ blockText(block) {
1937
+ const index = this.copyIndex.get(block);
1938
+ return index === undefined ? undefined : this.copyBlockRecords[index]?.text;
1939
+ }
1940
+ /** The canonical ordered copy record, oldest → newest. */
1941
+ copyBlocks() {
1942
+ return this.copyBlockRecords;
1943
+ }
1944
+ /** Newest tool call's result text (`/copy-tool`). */
1945
+ getLastToolOutputText() {
1946
+ for (let i = this.copyBlockRecords.length - 1; i >= 0; i--) {
1947
+ const copyBlock = this.copyBlockRecords[i];
1948
+ if (copyBlock.kind !== 'tool')
1949
+ continue;
1950
+ return copyBlock.text.trim() === '' ? undefined : copyBlock.text;
1951
+ }
1952
+ return undefined;
1953
+ }
1954
+ /** Every copyable block's text, oldest → newest, joined by blank lines. */
1955
+ getTranscriptPlainText() {
1956
+ const inactive = this.inactiveFormBlocks();
1957
+ return this.copyBlockRecords
1958
+ .filter((copyBlock) => !inactive.has(copyBlock.block))
1959
+ .map((copyBlock) => copyBlock.text)
1960
+ .filter((text) => text.trim() !== '')
1961
+ .join('\n\n');
1962
+ }
1963
+ /** Blocks built for the other side of the Replies-only boundary: the turn
1964
+ * replies and reply-form condensed history at every other level, and the
1965
+ * message-form condensed history at Replies only. */
1966
+ inactiveFormBlocks() {
1967
+ const inactive = new Set();
1968
+ if (this.repliesOnly()) {
1969
+ if (this.condensedBlocks.messages)
1970
+ inactive.add(this.condensedBlocks.messages);
1971
+ }
1972
+ else {
1973
+ if (this.condensedBlocks.turns)
1974
+ inactive.add(this.condensedBlocks.turns);
1975
+ for (const turn of this.turns)
1976
+ inactive.add(turn.reply);
1977
+ }
1978
+ return inactive;
1979
+ }
1980
+ registerCopyBlock(block, kind, text) {
1981
+ const condensedCopyBlocks = this.condensedCopyBlocks.get(this.appendTarget);
1982
+ if (condensedCopyBlocks) {
1983
+ const index = condensedCopyBlocks.findIndex((copyBlock) => copyBlock.block === block);
1984
+ if (index === -1)
1985
+ condensedCopyBlocks.push({ block, kind, text });
1986
+ else
1987
+ condensedCopyBlocks[index].text = text;
1988
+ return;
1989
+ }
1990
+ const index = this.copyIndex.get(block);
1991
+ if (index === undefined) {
1992
+ this.copyIndex.set(block, this.copyBlockRecords.length);
1993
+ this.copyBlockRecords.push({ block, kind, text });
1994
+ }
1995
+ else {
1996
+ this.copyBlockRecords[index].text = text;
1997
+ }
1998
+ }
1999
+ unregisterCopyBlock(block) {
2000
+ const condensedCopyBlocks = this.condensedCopyBlocks.get(this.appendTarget);
2001
+ if (condensedCopyBlocks) {
2002
+ const index = condensedCopyBlocks.findIndex((copyBlock) => copyBlock.block === block);
2003
+ if (index !== -1)
2004
+ condensedCopyBlocks.splice(index, 1);
2005
+ return;
2006
+ }
2007
+ const index = this.copyIndex.get(block);
2008
+ if (index === undefined)
2009
+ return;
2010
+ this.copyBlockRecords.splice(index, 1);
2011
+ this.copyIndex.delete(block);
2012
+ for (let i = index; i < this.copyBlockRecords.length; i++) {
2013
+ this.copyIndex.set(this.copyBlockRecords[i].block, i);
2014
+ }
2015
+ }
2016
+ appendCondensedBlock({ component, copyBlocks }, form) {
2017
+ this.outsideTurns++;
2018
+ try {
2019
+ this.append(component);
2020
+ }
2021
+ finally {
2022
+ this.outsideTurns--;
2023
+ }
2024
+ this.condensedBlocks[form] = component;
2025
+ this.historyContainer.setHidden(component, (form === 'turns') !== this.repliesOnly());
2026
+ this.registerCopyBlock(component, 'condensed', copyBlocks.map((copyBlock) => copyBlock.text).filter((text) => text.trim() !== '').join('\n\n'));
2027
+ }
2028
+ /** Flatten arbitrary tool result payloads into the visible text copy target. */
2029
+ toolResultText(result) {
2030
+ if (typeof result === 'string')
2031
+ return result;
2032
+ if (typeof result === 'object' && result !== null && 'content' in result) {
2033
+ const content = result.content;
2034
+ if (typeof content === 'string')
2035
+ return content;
2036
+ if (Array.isArray(content)) {
2037
+ return content
2038
+ .filter((part) => typeof part === 'object' &&
2039
+ part !== null &&
2040
+ part.type === 'text' &&
2041
+ typeof part.text === 'string')
2042
+ .map((part) => part.text)
2043
+ .join('');
2044
+ }
2045
+ }
2046
+ try {
2047
+ const text = JSON.stringify(result);
2048
+ return typeof text === 'string' ? text : '';
2049
+ }
2050
+ catch {
2051
+ return '';
2052
+ }
2053
+ }
2054
+ pushTranscriptText(text) {
2055
+ const trimmed = text.trim();
2056
+ if (trimmed === '')
2057
+ return;
2058
+ const refs = [...new Set(extractDocRefs(trimmed).reverse())];
2059
+ if (refs.length > 0) {
2060
+ const nextRefs = [...refs, ...this.transcriptDocRefs.filter((ref) => !refs.includes(ref))].slice(0, 50);
2061
+ this.transcriptDocRefs.splice(0, this.transcriptDocRefs.length, ...nextRefs);
2062
+ }
2063
+ const paths = extractFilePaths([trimmed], this.cwd);
2064
+ if (paths.length === 0)
2065
+ return;
2066
+ const next = [...paths, ...this.transcriptFilePaths.filter((path) => !paths.includes(path))].slice(0, 50);
2067
+ this.transcriptFilePaths.splice(0, this.transcriptFilePaths.length, ...next);
2068
+ }
2069
+ pushTranscriptValue(value) {
2070
+ try {
2071
+ const text = typeof value === 'string' ? value : JSON.stringify(value);
2072
+ if (typeof text === 'string')
2073
+ this.pushTranscriptText(text);
2074
+ }
2075
+ catch {
2076
+ // Tool payloads that cannot serialize are not transcript text.
2077
+ }
2078
+ }
2079
+ /** Concatenate the text blocks of a user message (string or content array). */
2080
+ userMessageText(message) {
2081
+ const content = message.content;
2082
+ if (typeof content === 'string')
2083
+ return content;
2084
+ if (!Array.isArray(content))
2085
+ return '';
2086
+ return content
2087
+ .filter((c) => typeof c === 'object' && c !== null && c.type === 'text')
2088
+ .map((c) => c.text)
2089
+ .join('');
2090
+ }
2091
+ }