@youweichen/pi-harness 0.0.0-stage → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (456) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +74 -2
  3. package/bin/pi-harness.mjs +1819 -0
  4. package/deploy/com.youweichen.pi-harness.plist +48 -0
  5. package/deploy/nginx-subpath.conf +88 -0
  6. package/deploy/pi-harness-task.xml +71 -0
  7. package/deploy/pi-harness.service +31 -0
  8. package/dist/server/agent-service.js +3131 -0
  9. package/dist/server/app-version.js +19 -0
  10. package/dist/server/attachments.js +526 -0
  11. package/dist/server/auth-file.js +61 -0
  12. package/dist/server/bg-servers.js +154 -0
  13. package/dist/server/client-eviction.js +19 -0
  14. package/dist/server/client-id.js +9 -0
  15. package/dist/server/client-state.js +202 -0
  16. package/dist/server/codemode-image-routes.js +36 -0
  17. package/dist/server/codemode-presentation.js +19 -0
  18. package/dist/server/component-updates.js +135 -0
  19. package/dist/server/context-breakdown.js +56 -0
  20. package/dist/server/control-socket.js +178 -0
  21. package/dist/server/conversation.js +65 -0
  22. package/dist/server/dir-browser.js +77 -0
  23. package/dist/server/editor-snapshot.js +38 -0
  24. package/dist/server/ensure-bash.js +80 -0
  25. package/dist/server/extension-display.js +23 -0
  26. package/dist/server/extensions-catalog.js +64 -0
  27. package/dist/server/extensions-model.js +46 -0
  28. package/dist/server/extensions-routes.js +255 -0
  29. package/dist/server/extensions-worker.js +188 -0
  30. package/dist/server/files-service.js +787 -0
  31. package/dist/server/index.js +1033 -0
  32. package/dist/server/markdown-images.js +42 -0
  33. package/dist/server/model-admin.js +801 -0
  34. package/dist/server/model-config-merge.js +32 -0
  35. package/dist/server/native-mcp-config.js +103 -0
  36. package/dist/server/native-mcp-presentation.js +12 -0
  37. package/dist/server/native-prompt-template.js +12 -0
  38. package/dist/server/native-tools.js +32 -0
  39. package/dist/server/node-agent.js +262 -0
  40. package/dist/server/node-sources.js +142 -0
  41. package/dist/server/node-workbench.js +729 -0
  42. package/dist/server/origin-policy.js +50 -0
  43. package/dist/server/patch-node-pty.js +96 -0
  44. package/dist/server/pi-environment.js +203 -0
  45. package/dist/server/plan/extension.js +74 -0
  46. package/dist/server/plan/progress.js +90 -0
  47. package/dist/server/plan/settings.js +41 -0
  48. package/dist/server/plan/state.js +123 -0
  49. package/dist/server/plugin-facilities.js +304 -0
  50. package/dist/server/plugin-updater.js +245 -0
  51. package/dist/server/plugins.js +712 -0
  52. package/dist/server/private-file.js +28 -0
  53. package/dist/server/process-utils.js +112 -0
  54. package/dist/server/prompt-delivery.js +80 -0
  55. package/dist/server/protocol-version.js +11 -0
  56. package/dist/server/protocol.js +6 -0
  57. package/dist/server/provider-auth.js +99 -0
  58. package/dist/server/query-cache.js +45 -0
  59. package/dist/server/recovery-state.js +37 -0
  60. package/dist/server/scm.js +459 -0
  61. package/dist/server/security-headers.js +24 -0
  62. package/dist/server/serialize.js +254 -0
  63. package/dist/server/session-file-read.js +225 -0
  64. package/dist/server/session-record-worker.js +21 -0
  65. package/dist/server/session-reload.js +13 -0
  66. package/dist/server/session-tree-controller.js +250 -0
  67. package/dist/server/session-tree.js +191 -0
  68. package/dist/server/settings-service.js +53 -0
  69. package/dist/server/skills-service.js +87 -0
  70. package/dist/server/slash-commands.js +286 -0
  71. package/dist/server/sqlite-preview.js +58 -0
  72. package/dist/server/sqlite-query.js +67 -0
  73. package/dist/server/sqlite-worker.js +12 -0
  74. package/dist/server/system-prompt-files.js +158 -0
  75. package/dist/server/system-prompt-routes.js +40 -0
  76. package/dist/server/system-prompt-view.js +49 -0
  77. package/dist/server/task-progress.js +233 -0
  78. package/dist/server/terminals.js +833 -0
  79. package/dist/server/text-sniff.js +269 -0
  80. package/dist/server/thinking-timing.js +91 -0
  81. package/dist/server/token-auth.js +37 -0
  82. package/dist/server/tool-output.js +97 -0
  83. package/dist/server/tool-text-incidents.js +82 -0
  84. package/dist/server/tool-text.js +67 -0
  85. package/dist/server/uploads.js +112 -0
  86. package/dist/server/user-attachments.js +96 -0
  87. package/dist/server/webui-context.js +257 -0
  88. package/dist/server/wiki-links.js +136 -0
  89. package/dist/server/wiki-pdf-worker.js +23 -0
  90. package/dist/server/wiki-pdf.js +36 -0
  91. package/dist/server/wiki-routes.js +184 -0
  92. package/dist/server/wiki-service.js +524 -0
  93. package/electron/main.mjs +607 -0
  94. package/extensions/webui.ts +192 -0
  95. package/package.json +122 -4
  96. package/web/dist/apple-touch-icon.png +0 -0
  97. package/web/dist/assets/NodeWorkbench-BiP2ktQP.js +3 -0
  98. package/web/dist/assets/TerminalPanel-CKaSUsN-.js +2 -0
  99. package/web/dist/assets/abnfDiagram-VCTEODGH-CnwRJDRL.js +1 -0
  100. package/web/dist/assets/arc-CG4Q7-W_.js +1 -0
  101. package/web/dist/assets/architectureDiagram-5GKGNRK7-BrGqX_Rg.js +36 -0
  102. package/web/dist/assets/blockDiagram-I7D4REHJ-C2t0PjZT.js +129 -0
  103. package/web/dist/assets/c4Diagram-7LVT6UL2-CadrcgGL.js +38 -0
  104. package/web/dist/assets/channel-C27Jizb6.js +1 -0
  105. package/web/dist/assets/chunk-2Q5K7J3B-CC3V2ITZ.js +1 -0
  106. package/web/dist/assets/chunk-5VM5RSS4-DqKSbGmE.js +15 -0
  107. package/web/dist/assets/chunk-F27PBJKO-_CDr3JbY.js +1 -0
  108. package/web/dist/assets/chunk-IMKFNOWR-BIR4H4fX.js +231 -0
  109. package/web/dist/assets/chunk-JWPE2WC7-CrsdBGXT.js +1 -0
  110. package/web/dist/assets/chunk-POPQ4Y6H-C6q9kQmf.js +1 -0
  111. package/web/dist/assets/chunk-SVP7TREG-l2XXTr2v.js +88 -0
  112. package/web/dist/assets/chunk-TICWLB2K-29I_mZgB.js +206 -0
  113. package/web/dist/assets/chunk-XXDRQBXY-htV9FBqi.js +1 -0
  114. package/web/dist/assets/classDiagram-ZZMXUADV-DYTBrAEP.js +1 -0
  115. package/web/dist/assets/classDiagram-v2-VYDZK3BY-DYTBrAEP.js +1 -0
  116. package/web/dist/assets/cose-bilkent-JH36ORCC-Cop-ihyx.js +1 -0
  117. package/web/dist/assets/cynefin-OW5HDTMX-IEk8qBRq.js +178 -0
  118. package/web/dist/assets/cynefinDiagram-5FMLGOSQ-Bmzt6Qb5.js +62 -0
  119. package/web/dist/assets/cytoscape.esm-Bch-eiPH.js +331 -0
  120. package/web/dist/assets/dagre-GXQ25YYZ-DiXTJYYU.js +4 -0
  121. package/web/dist/assets/defaultLocale-DX6XiGOO.js +1 -0
  122. package/web/dist/assets/diagram-S7CK7UJ4-BT7CLuNk.js +30 -0
  123. package/web/dist/assets/diagram-UQ7AKVKN-BZZ3nTCO.js +41 -0
  124. package/web/dist/assets/diagram-VSXAHHWV-Dal8LeZh.js +3 -0
  125. package/web/dist/assets/diagram-VX7I27RA-D6V9FfNA.js +24 -0
  126. package/web/dist/assets/diagram-Z3DM3KII-KUAIcFiD.js +24 -0
  127. package/web/dist/assets/ebnfDiagram-PWID7BFC-s0FEPZrV.js +1 -0
  128. package/web/dist/assets/erDiagram-RLTQ6QDP-CiIQPFCD.js +99 -0
  129. package/web/dist/assets/flowDiagram-HODETNUW-CvG4MYWn.js +168 -0
  130. package/web/dist/assets/ganttDiagram-EL5Y4UJY-CUf115ii.js +292 -0
  131. package/web/dist/assets/gitGraphDiagram-WWUBYQGX-o3K1r6fL.js +106 -0
  132. package/web/dist/assets/index-C3vDFSEV.css +10 -0
  133. package/web/dist/assets/index-C5or_GAq.js +276 -0
  134. package/web/dist/assets/infoDiagram-27XIBGKW-BxiBeQ8E.js +2 -0
  135. package/web/dist/assets/init-Gi6I4Gst.js +1 -0
  136. package/web/dist/assets/ishikawaDiagram-5VMMS53U-B1ONuCkH.js +70 -0
  137. package/web/dist/assets/journeyDiagram-3NMN7TZE-DwmuoXcX.js +139 -0
  138. package/web/dist/assets/kanban-definition-UXKFOSKX-pMKHubxH.js +89 -0
  139. package/web/dist/assets/katex-C5jXJg4s.js +257 -0
  140. package/web/dist/assets/layout-CEwfjQR0.js +1 -0
  141. package/web/dist/assets/linear-D22Gdbt1.js +1 -0
  142. package/web/dist/assets/markdown-BhJ_LInD.js +51 -0
  143. package/web/dist/assets/mermaid.core-CO2nrD04.js +312 -0
  144. package/web/dist/assets/mindmap-definition-YA3MSWOX-9MQn9ZAp.js +96 -0
  145. package/web/dist/assets/ordinal-Cboi1Yqb.js +1 -0
  146. package/web/dist/assets/pegDiagram-XKGWAZYB-Dy6fLjM-.js +1 -0
  147. package/web/dist/assets/pieDiagram-E7YTZNPT-EDLez6nA.js +39 -0
  148. package/web/dist/assets/quadrantDiagram-AXDQQJYC-Cgcd9mvy.js +7 -0
  149. package/web/dist/assets/railroadDiagram-O6MQD6OU-B4Td0tjj.js +1 -0
  150. package/web/dist/assets/react-BddUxV-9.js +24 -0
  151. package/web/dist/assets/requirementDiagram-BXWQKSXE-aF2QNZ78.js +84 -0
  152. package/web/dist/assets/sankeyDiagram-P5KCCOFB-DgTYwYMa.js +40 -0
  153. package/web/dist/assets/sequenceDiagram-WJ2MYXX4-EUcddWUc.js +162 -0
  154. package/web/dist/assets/sizeCapture-INFHLROL-CXHOv9Sx.js +1 -0
  155. package/web/dist/assets/stateDiagram-D77RDMKH-B-xlgfaK.js +1 -0
  156. package/web/dist/assets/stateDiagram-v2-MP3YSRHH-kwAwAlWX.js +1 -0
  157. package/web/dist/assets/swimlanes-42K2YHIH-BtFBOCDh.js +1 -0
  158. package/web/dist/assets/swimlanesDiagram-VR7AAH4N-D5j5Cj3S.js +8 -0
  159. package/web/dist/assets/timeline-definition-24CTP7MA-CZlQY6pb.js +120 -0
  160. package/web/dist/assets/vennDiagram-4TSXK5OY-Cn61dJvL.js +34 -0
  161. package/web/dist/assets/wardleyDiagram-VM6X3IG4-fiMNrWpr.js +78 -0
  162. package/web/dist/assets/xterm-6GBZ9nXN.css +32 -0
  163. package/web/dist/assets/xterm-D1D2FVe3.js +38 -0
  164. package/web/dist/assets/xychartDiagram-S5SC5T6Z-CuzM_sof.js +7 -0
  165. package/web/dist/brand-mark.svg +5 -0
  166. package/web/dist/favicon-32.png +0 -0
  167. package/web/dist/favicon.svg +5 -0
  168. package/web/dist/fonts/WIKI-FONTS.md +5 -0
  169. package/web/dist/fonts/ibm-plex-mono/ibm-plex-mono-latin-400-normal.woff2 +0 -0
  170. package/web/dist/fonts/ibm-plex-mono/ibm-plex-mono-latin-500-normal.woff2 +0 -0
  171. package/web/dist/fonts/ibm-plex-mono/ibm-plex-mono-latin-600-normal.woff2 +0 -0
  172. package/web/dist/fonts/ibm-plex-mono/ibm-plex-mono-latin-ext-400-normal.woff2 +0 -0
  173. package/web/dist/fonts/ibm-plex-mono/ibm-plex-mono-latin-ext-500-normal.woff2 +0 -0
  174. package/web/dist/fonts/ibm-plex-mono/ibm-plex-mono-latin-ext-600-normal.woff2 +0 -0
  175. package/web/dist/fonts/ibm-plex-sans/LICENSE +93 -0
  176. package/web/dist/fonts/ibm-plex-sans/ibm-plex-sans-latin-400-normal.woff2 +0 -0
  177. package/web/dist/fonts/ibm-plex-sans/ibm-plex-sans-latin-500-normal.woff2 +0 -0
  178. package/web/dist/fonts/ibm-plex-sans/ibm-plex-sans-latin-600-normal.woff2 +0 -0
  179. package/web/dist/fonts/ibm-plex-sans/ibm-plex-sans-latin-ext-400-normal.woff2 +0 -0
  180. package/web/dist/fonts/ibm-plex-sans/ibm-plex-sans-latin-ext-500-normal.woff2 +0 -0
  181. package/web/dist/fonts/ibm-plex-sans/ibm-plex-sans-latin-ext-600-normal.woff2 +0 -0
  182. package/web/dist/fonts/inter/inter-latin-400-normal.woff2 +0 -0
  183. package/web/dist/fonts/inter/inter-latin-500-normal.woff2 +0 -0
  184. package/web/dist/fonts/inter/inter-latin-600-normal.woff2 +0 -0
  185. package/web/dist/fonts/inter/inter-latin-700-normal.woff2 +0 -0
  186. package/web/dist/fonts/inter/inter-latin-800-normal.woff2 +0 -0
  187. package/web/dist/fonts/inter/inter-latin-ext-400-normal.woff2 +0 -0
  188. package/web/dist/fonts/inter/inter-latin-ext-500-normal.woff2 +0 -0
  189. package/web/dist/fonts/inter/inter-latin-ext-600-normal.woff2 +0 -0
  190. package/web/dist/fonts/inter/inter-latin-ext-700-normal.woff2 +0 -0
  191. package/web/dist/fonts/inter/inter-latin-ext-800-normal.woff2 +0 -0
  192. package/web/dist/fonts/jetbrains-mono/LICENSE +93 -0
  193. package/web/dist/fonts/jetbrains-mono/jetbrains-mono-latin-400-normal.woff2 +0 -0
  194. package/web/dist/fonts/jetbrains-mono/jetbrains-mono-latin-500-normal.woff2 +0 -0
  195. package/web/dist/fonts/jetbrains-mono/jetbrains-mono-latin-600-normal.woff2 +0 -0
  196. package/web/dist/fonts/jetbrains-mono/jetbrains-mono-latin-ext-400-normal.woff2 +0 -0
  197. package/web/dist/fonts/jetbrains-mono/jetbrains-mono-latin-ext-500-normal.woff2 +0 -0
  198. package/web/dist/fonts/jetbrains-mono/jetbrains-mono-latin-ext-600-normal.woff2 +0 -0
  199. package/web/dist/fonts/noto-serif-sc/LICENSE +94 -0
  200. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-0.woff2 +0 -0
  201. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-1.woff2 +0 -0
  202. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-10.woff2 +0 -0
  203. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-100.woff2 +0 -0
  204. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-11.woff2 +0 -0
  205. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-12.woff2 +0 -0
  206. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-13.woff2 +0 -0
  207. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-14.woff2 +0 -0
  208. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-15.woff2 +0 -0
  209. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-16.woff2 +0 -0
  210. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-17.woff2 +0 -0
  211. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-18.woff2 +0 -0
  212. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-19.woff2 +0 -0
  213. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-2.woff2 +0 -0
  214. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-20.woff2 +0 -0
  215. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-21.woff2 +0 -0
  216. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-22.woff2 +0 -0
  217. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-23.woff2 +0 -0
  218. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-24.woff2 +0 -0
  219. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-25.woff2 +0 -0
  220. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-26.woff2 +0 -0
  221. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-27.woff2 +0 -0
  222. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-28.woff2 +0 -0
  223. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-29.woff2 +0 -0
  224. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-3.woff2 +0 -0
  225. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-30.woff2 +0 -0
  226. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-31.woff2 +0 -0
  227. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-32.woff2 +0 -0
  228. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-33.woff2 +0 -0
  229. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-34.woff2 +0 -0
  230. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-35.woff2 +0 -0
  231. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-36.woff2 +0 -0
  232. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-37.woff2 +0 -0
  233. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-38.woff2 +0 -0
  234. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-39.woff2 +0 -0
  235. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-4.woff2 +0 -0
  236. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-40.woff2 +0 -0
  237. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-41.woff2 +0 -0
  238. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-42.woff2 +0 -0
  239. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-43.woff2 +0 -0
  240. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-44.woff2 +0 -0
  241. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-45.woff2 +0 -0
  242. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-46.woff2 +0 -0
  243. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-47.woff2 +0 -0
  244. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-48.woff2 +0 -0
  245. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-49.woff2 +0 -0
  246. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-5.woff2 +0 -0
  247. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-50.woff2 +0 -0
  248. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-51.woff2 +0 -0
  249. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-52.woff2 +0 -0
  250. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-53.woff2 +0 -0
  251. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-54.woff2 +0 -0
  252. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-55.woff2 +0 -0
  253. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-56.woff2 +0 -0
  254. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-57.woff2 +0 -0
  255. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-58.woff2 +0 -0
  256. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-59.woff2 +0 -0
  257. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-6.woff2 +0 -0
  258. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-60.woff2 +0 -0
  259. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-61.woff2 +0 -0
  260. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-62.woff2 +0 -0
  261. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-63.woff2 +0 -0
  262. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-64.woff2 +0 -0
  263. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-65.woff2 +0 -0
  264. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-66.woff2 +0 -0
  265. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-67.woff2 +0 -0
  266. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-68.woff2 +0 -0
  267. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-69.woff2 +0 -0
  268. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-7.woff2 +0 -0
  269. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-70.woff2 +0 -0
  270. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-71.woff2 +0 -0
  271. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-72.woff2 +0 -0
  272. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-73.woff2 +0 -0
  273. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-74.woff2 +0 -0
  274. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-75.woff2 +0 -0
  275. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-76.woff2 +0 -0
  276. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-77.woff2 +0 -0
  277. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-78.woff2 +0 -0
  278. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-79.woff2 +0 -0
  279. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-8.woff2 +0 -0
  280. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-80.woff2 +0 -0
  281. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-81.woff2 +0 -0
  282. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-82.woff2 +0 -0
  283. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-83.woff2 +0 -0
  284. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-84.woff2 +0 -0
  285. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-85.woff2 +0 -0
  286. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-86.woff2 +0 -0
  287. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-87.woff2 +0 -0
  288. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-88.woff2 +0 -0
  289. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-89.woff2 +0 -0
  290. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-9.woff2 +0 -0
  291. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-90.woff2 +0 -0
  292. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-91.woff2 +0 -0
  293. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-92.woff2 +0 -0
  294. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-93.woff2 +0 -0
  295. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-94.woff2 +0 -0
  296. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-95.woff2 +0 -0
  297. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-96.woff2 +0 -0
  298. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-97.woff2 +0 -0
  299. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-98.woff2 +0 -0
  300. package/web/dist/fonts/noto-serif-sc/noto-serif-sc-500-99.woff2 +0 -0
  301. package/web/dist/fonts/source-serif-4/LICENSE +93 -0
  302. package/web/dist/fonts/source-serif-4/source-serif-4-500-0.woff2 +0 -0
  303. package/web/dist/fonts/source-serif-4/source-serif-4-500-1.woff2 +0 -0
  304. package/web/dist/fonts/source-serif-4/source-serif-4-500-2.woff2 +0 -0
  305. package/web/dist/fonts/source-serif-4/source-serif-4-500-3.woff2 +0 -0
  306. package/web/dist/fonts/source-serif-4/source-serif-4-500-4.woff2 +0 -0
  307. package/web/dist/fonts/source-serif-4/source-serif-4-500-5.woff2 +0 -0
  308. package/web/dist/icon/1a-mark.svg +1 -0
  309. package/web/dist/icon.ico +0 -0
  310. package/web/dist/index.html +18 -0
  311. package/web/public/apple-touch-icon.png +0 -0
  312. package/web/public/brand-mark.svg +5 -0
  313. package/web/public/favicon-32.png +0 -0
  314. package/web/public/favicon.svg +5 -0
  315. package/web/public/fonts/WIKI-FONTS.md +5 -0
  316. package/web/public/fonts/ibm-plex-mono/ibm-plex-mono-latin-400-normal.woff2 +0 -0
  317. package/web/public/fonts/ibm-plex-mono/ibm-plex-mono-latin-500-normal.woff2 +0 -0
  318. package/web/public/fonts/ibm-plex-mono/ibm-plex-mono-latin-600-normal.woff2 +0 -0
  319. package/web/public/fonts/ibm-plex-mono/ibm-plex-mono-latin-ext-400-normal.woff2 +0 -0
  320. package/web/public/fonts/ibm-plex-mono/ibm-plex-mono-latin-ext-500-normal.woff2 +0 -0
  321. package/web/public/fonts/ibm-plex-mono/ibm-plex-mono-latin-ext-600-normal.woff2 +0 -0
  322. package/web/public/fonts/ibm-plex-sans/LICENSE +93 -0
  323. package/web/public/fonts/ibm-plex-sans/ibm-plex-sans-latin-400-normal.woff2 +0 -0
  324. package/web/public/fonts/ibm-plex-sans/ibm-plex-sans-latin-500-normal.woff2 +0 -0
  325. package/web/public/fonts/ibm-plex-sans/ibm-plex-sans-latin-600-normal.woff2 +0 -0
  326. package/web/public/fonts/ibm-plex-sans/ibm-plex-sans-latin-ext-400-normal.woff2 +0 -0
  327. package/web/public/fonts/ibm-plex-sans/ibm-plex-sans-latin-ext-500-normal.woff2 +0 -0
  328. package/web/public/fonts/ibm-plex-sans/ibm-plex-sans-latin-ext-600-normal.woff2 +0 -0
  329. package/web/public/fonts/inter/inter-latin-400-normal.woff2 +0 -0
  330. package/web/public/fonts/inter/inter-latin-500-normal.woff2 +0 -0
  331. package/web/public/fonts/inter/inter-latin-600-normal.woff2 +0 -0
  332. package/web/public/fonts/inter/inter-latin-700-normal.woff2 +0 -0
  333. package/web/public/fonts/inter/inter-latin-800-normal.woff2 +0 -0
  334. package/web/public/fonts/inter/inter-latin-ext-400-normal.woff2 +0 -0
  335. package/web/public/fonts/inter/inter-latin-ext-500-normal.woff2 +0 -0
  336. package/web/public/fonts/inter/inter-latin-ext-600-normal.woff2 +0 -0
  337. package/web/public/fonts/inter/inter-latin-ext-700-normal.woff2 +0 -0
  338. package/web/public/fonts/inter/inter-latin-ext-800-normal.woff2 +0 -0
  339. package/web/public/fonts/jetbrains-mono/LICENSE +93 -0
  340. package/web/public/fonts/jetbrains-mono/jetbrains-mono-latin-400-normal.woff2 +0 -0
  341. package/web/public/fonts/jetbrains-mono/jetbrains-mono-latin-500-normal.woff2 +0 -0
  342. package/web/public/fonts/jetbrains-mono/jetbrains-mono-latin-600-normal.woff2 +0 -0
  343. package/web/public/fonts/jetbrains-mono/jetbrains-mono-latin-ext-400-normal.woff2 +0 -0
  344. package/web/public/fonts/jetbrains-mono/jetbrains-mono-latin-ext-500-normal.woff2 +0 -0
  345. package/web/public/fonts/jetbrains-mono/jetbrains-mono-latin-ext-600-normal.woff2 +0 -0
  346. package/web/public/fonts/noto-serif-sc/LICENSE +94 -0
  347. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-0.woff2 +0 -0
  348. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-1.woff2 +0 -0
  349. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-10.woff2 +0 -0
  350. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-100.woff2 +0 -0
  351. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-11.woff2 +0 -0
  352. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-12.woff2 +0 -0
  353. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-13.woff2 +0 -0
  354. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-14.woff2 +0 -0
  355. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-15.woff2 +0 -0
  356. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-16.woff2 +0 -0
  357. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-17.woff2 +0 -0
  358. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-18.woff2 +0 -0
  359. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-19.woff2 +0 -0
  360. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-2.woff2 +0 -0
  361. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-20.woff2 +0 -0
  362. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-21.woff2 +0 -0
  363. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-22.woff2 +0 -0
  364. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-23.woff2 +0 -0
  365. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-24.woff2 +0 -0
  366. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-25.woff2 +0 -0
  367. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-26.woff2 +0 -0
  368. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-27.woff2 +0 -0
  369. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-28.woff2 +0 -0
  370. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-29.woff2 +0 -0
  371. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-3.woff2 +0 -0
  372. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-30.woff2 +0 -0
  373. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-31.woff2 +0 -0
  374. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-32.woff2 +0 -0
  375. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-33.woff2 +0 -0
  376. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-34.woff2 +0 -0
  377. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-35.woff2 +0 -0
  378. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-36.woff2 +0 -0
  379. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-37.woff2 +0 -0
  380. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-38.woff2 +0 -0
  381. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-39.woff2 +0 -0
  382. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-4.woff2 +0 -0
  383. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-40.woff2 +0 -0
  384. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-41.woff2 +0 -0
  385. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-42.woff2 +0 -0
  386. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-43.woff2 +0 -0
  387. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-44.woff2 +0 -0
  388. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-45.woff2 +0 -0
  389. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-46.woff2 +0 -0
  390. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-47.woff2 +0 -0
  391. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-48.woff2 +0 -0
  392. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-49.woff2 +0 -0
  393. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-5.woff2 +0 -0
  394. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-50.woff2 +0 -0
  395. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-51.woff2 +0 -0
  396. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-52.woff2 +0 -0
  397. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-53.woff2 +0 -0
  398. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-54.woff2 +0 -0
  399. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-55.woff2 +0 -0
  400. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-56.woff2 +0 -0
  401. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-57.woff2 +0 -0
  402. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-58.woff2 +0 -0
  403. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-59.woff2 +0 -0
  404. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-6.woff2 +0 -0
  405. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-60.woff2 +0 -0
  406. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-61.woff2 +0 -0
  407. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-62.woff2 +0 -0
  408. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-63.woff2 +0 -0
  409. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-64.woff2 +0 -0
  410. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-65.woff2 +0 -0
  411. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-66.woff2 +0 -0
  412. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-67.woff2 +0 -0
  413. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-68.woff2 +0 -0
  414. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-69.woff2 +0 -0
  415. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-7.woff2 +0 -0
  416. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-70.woff2 +0 -0
  417. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-71.woff2 +0 -0
  418. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-72.woff2 +0 -0
  419. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-73.woff2 +0 -0
  420. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-74.woff2 +0 -0
  421. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-75.woff2 +0 -0
  422. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-76.woff2 +0 -0
  423. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-77.woff2 +0 -0
  424. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-78.woff2 +0 -0
  425. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-79.woff2 +0 -0
  426. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-8.woff2 +0 -0
  427. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-80.woff2 +0 -0
  428. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-81.woff2 +0 -0
  429. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-82.woff2 +0 -0
  430. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-83.woff2 +0 -0
  431. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-84.woff2 +0 -0
  432. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-85.woff2 +0 -0
  433. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-86.woff2 +0 -0
  434. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-87.woff2 +0 -0
  435. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-88.woff2 +0 -0
  436. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-89.woff2 +0 -0
  437. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-9.woff2 +0 -0
  438. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-90.woff2 +0 -0
  439. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-91.woff2 +0 -0
  440. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-92.woff2 +0 -0
  441. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-93.woff2 +0 -0
  442. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-94.woff2 +0 -0
  443. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-95.woff2 +0 -0
  444. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-96.woff2 +0 -0
  445. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-97.woff2 +0 -0
  446. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-98.woff2 +0 -0
  447. package/web/public/fonts/noto-serif-sc/noto-serif-sc-500-99.woff2 +0 -0
  448. package/web/public/fonts/source-serif-4/LICENSE +93 -0
  449. package/web/public/fonts/source-serif-4/source-serif-4-500-0.woff2 +0 -0
  450. package/web/public/fonts/source-serif-4/source-serif-4-500-1.woff2 +0 -0
  451. package/web/public/fonts/source-serif-4/source-serif-4-500-2.woff2 +0 -0
  452. package/web/public/fonts/source-serif-4/source-serif-4-500-3.woff2 +0 -0
  453. package/web/public/fonts/source-serif-4/source-serif-4-500-4.woff2 +0 -0
  454. package/web/public/fonts/source-serif-4/source-serif-4-500-5.woff2 +0 -0
  455. package/web/public/icon/1a-mark.svg +1 -0
  456. package/web/public/icon.ico +0 -0
@@ -0,0 +1,254 @@
1
+ import { codemodeDetails } from "./codemode-presentation.js";
2
+ import { createHash } from "node:crypto";
3
+ import { snapshotFromDetails } from "./plan/state.js";
4
+ const TEXT_CAP = 200_000;
5
+ const TOOL_OUTPUT_CAP = 100_000;
6
+ const ARGS_CAP = 20_000;
7
+ function truncate(s, cap) {
8
+ if (s.length <= cap)
9
+ return { text: s, truncated: false };
10
+ return { text: `${s.slice(0, cap)}\n\n… [truncated]`, truncated: true };
11
+ }
12
+ /** Only documented native result fields cross the wire. */
13
+ export function toolExitCode(result, isError = false) {
14
+ if (!result || typeof result !== "object")
15
+ return undefined;
16
+ const r = result;
17
+ for (const value of [r.structuredContent?.exit_code, r.details?.exitCode]) {
18
+ if (typeof value === "number" && Number.isSafeInteger(value))
19
+ return value;
20
+ }
21
+ if (!isError)
22
+ return undefined;
23
+ const text = Array.isArray(r.content) ? r.content.filter(c => c?.type === "text" && typeof c.text === "string").map(c => c.text).join("\n") : "";
24
+ const match = text.match(/exited with code (-?\d+)/);
25
+ return match && Number.isSafeInteger(Number(match[1])) ? Number(match[1]) : undefined;
26
+ }
27
+ export function nativeToolDetails(name, result) {
28
+ if (!result || typeof result !== "object")
29
+ return undefined;
30
+ const r = result;
31
+ const d = r.details;
32
+ const out = {};
33
+ if (name === "edit") {
34
+ if (typeof d?.diff === "string") {
35
+ const bounded = truncate(d.diff, TOOL_OUTPUT_CAP);
36
+ out.diff = bounded.text;
37
+ out.diffTruncated = bounded.truncated;
38
+ }
39
+ if (typeof d?.firstChangedLine === "number" && Number.isSafeInteger(d.firstChangedLine) && d.firstChangedLine > 0)
40
+ out.firstChangedLine = d.firstChangedLine;
41
+ }
42
+ const path = d?.fullOutputPath ?? (["bash", "powershell"].includes(name) ? r.structuredContent?.full_output_path : undefined);
43
+ if (typeof path === "string" && path.length <= 4096)
44
+ out.fullOutputPath = path;
45
+ if (name === "bash") {
46
+ out.exitCode = toolExitCode(result, r.isError);
47
+ if (d?.truncation && typeof d.truncation === "object") {
48
+ const source = d.truncation;
49
+ const truncation = {};
50
+ for (const key of ["truncated", "lastLinePartial"])
51
+ if (typeof source[key] === "boolean")
52
+ truncation[key] = source[key];
53
+ for (const key of ["totalLines", "totalBytes", "outputLines", "outputBytes"])
54
+ if (typeof source[key] === "number" && Number.isSafeInteger(source[key]) && source[key] >= 0)
55
+ truncation[key] = source[key];
56
+ if (source.truncatedBy === "lines" || source.truncatedBy === "bytes")
57
+ truncation.truncatedBy = source.truncatedBy;
58
+ out.truncation = truncation;
59
+ }
60
+ }
61
+ return Object.keys(out).length ? out : undefined;
62
+ }
63
+ function serializeUserContent(content) {
64
+ if (typeof content === "string")
65
+ return [{ type: "text", text: content }];
66
+ return content.map((b) => {
67
+ if (b.type === "image") {
68
+ const img = b;
69
+ // Canonical ImageContent shape is { type, data, mimeType }; tolerate the
70
+ // legacy { source } wrapper too.
71
+ if (typeof img.data === "string" && img.data.length > 0) {
72
+ return {
73
+ type: "image",
74
+ dataUrl: `data:${img.mimeType ?? "image/png"};base64,${img.data}`,
75
+ mimeType: img.mimeType,
76
+ };
77
+ }
78
+ const src = img.source;
79
+ if (src?.type === "base64" && src.data) {
80
+ return {
81
+ type: "image",
82
+ dataUrl: `data:${src.mediaType ?? "image/png"};base64,${src.data}`,
83
+ mimeType: src.mediaType,
84
+ };
85
+ }
86
+ return { type: "image", dataUrl: src?.url };
87
+ }
88
+ return { type: "text", text: String(b.text ?? "") };
89
+ });
90
+ }
91
+ function serializeAssistantContent(content) {
92
+ return content.map((b) => {
93
+ if (b.type === "text") {
94
+ const { text, truncated } = truncate(b.text, TEXT_CAP);
95
+ return { type: "text", text, truncated };
96
+ }
97
+ if (b.type === "thinking") {
98
+ return { type: "thinking", thinking: b.thinking };
99
+ }
100
+ if (b.type === "toolCall") {
101
+ if (b.arguments === undefined) {
102
+ return { type: "toolCall", id: b.id, name: b.name };
103
+ }
104
+ const { text, truncated } = truncate(JSON.stringify(b.arguments), ARGS_CAP);
105
+ return {
106
+ type: "toolCall",
107
+ id: b.id,
108
+ name: b.name,
109
+ argumentsText: text,
110
+ argumentsTruncated: truncated,
111
+ };
112
+ }
113
+ return { type: "unknown", ...b };
114
+ });
115
+ }
116
+ export function serializeMessage(m, seq) {
117
+ switch (m.role) {
118
+ case "user":
119
+ return {
120
+ id: `u-${m.timestamp}-${seq}`,
121
+ role: "user",
122
+ content: serializeUserContent(m.content),
123
+ timestamp: m.timestamp,
124
+ };
125
+ case "assistant":
126
+ return {
127
+ id: `a-${m.timestamp}-${seq}`,
128
+ role: "assistant",
129
+ content: serializeAssistantContent(m.content),
130
+ timestamp: m.timestamp,
131
+ model: m.model,
132
+ provider: m.provider,
133
+ stopReason: m.stopReason,
134
+ usage: m.usage ? { input: m.usage.input, output: m.usage.output, cacheRead: m.usage.cacheRead, cacheWrite: m.usage.cacheWrite } : undefined,
135
+ errorMessage: m.errorMessage,
136
+ };
137
+ case "toolResult": {
138
+ const raw = m.content
139
+ .map((c) => (c.type === "text" ? c.text : ""))
140
+ .join("\n");
141
+ const { text, truncated } = truncate(raw, TOOL_OUTPUT_CAP);
142
+ const plan = m.toolName === "plan" && !m.isError ? snapshotFromDetails(m.details) : undefined;
143
+ let nestedComplete = m.nestedCalls?.complete === true && m.nestedCalls.calls.length <= 256;
144
+ const nestedCalls = m.nestedCalls?.calls.slice(0, 256).map(call => {
145
+ const args = call.arguments ? truncate(JSON.stringify(call.arguments), ARGS_CAP) : undefined;
146
+ if (args?.truncated)
147
+ nestedComplete = false;
148
+ return { id: call.id, name: call.name, status: call.status, durationMs: call.durationMs,
149
+ error: call.error?.slice(0, 500), argumentsBytes: call.argumentsBytes,
150
+ argumentsText: args?.text };
151
+ });
152
+ return {
153
+ id: `t-${m.toolCallId}`,
154
+ role: "toolResult",
155
+ content: [{ type: "text", text, truncated }, ...serializeUserContent(m.content.filter(block => block.type === "image"))],
156
+ ...(nestedCalls ? { nestedCalls: { complete: nestedComplete, calls: nestedCalls } } : {}),
157
+ toolCallId: m.toolCallId,
158
+ toolName: m.toolName,
159
+ details: nativeToolDetails(m.toolName, m),
160
+ ...(m.toolName === "codemode" ? { codemode: codemodeDetails(m.details) } : {}),
161
+ isError: m.isError,
162
+ ...(plan ? { planSnapshot: plan } : {}),
163
+ timestamp: m.timestamp,
164
+ };
165
+ }
166
+ case "bashExecution": {
167
+ const { text, truncated } = truncate(m.output, TOOL_OUTPUT_CAP);
168
+ return {
169
+ id: `b-${m.timestamp}-${seq}`,
170
+ role: "bashExecution",
171
+ content: [
172
+ {
173
+ type: "bash",
174
+ command: m.command,
175
+ output: text,
176
+ exitCode: m.exitCode,
177
+ cancelled: m.cancelled,
178
+ truncated,
179
+ },
180
+ ],
181
+ timestamp: m.timestamp,
182
+ };
183
+ }
184
+ case "custom": {
185
+ // Third-party extension messages with display:false are UI-hidden
186
+ // (they still go into LLM context — the SDK handles that).
187
+ if (m.display === false) {
188
+ return null;
189
+ }
190
+ const content = serializeUserContent(m.content);
191
+ return {
192
+ id: `c-${m.timestamp}-${seq}`,
193
+ role: "custom",
194
+ content,
195
+ customType: m.customType,
196
+ details: m.details,
197
+ timestamp: m.timestamp,
198
+ };
199
+ }
200
+ case "branchSummary": {
201
+ const { text, truncated } = truncate(m.summary, TEXT_CAP);
202
+ return {
203
+ id: `bs-${m.timestamp}-${seq}`,
204
+ role: "branchSummary",
205
+ content: [{ type: "text", text, truncated }],
206
+ timestamp: m.timestamp,
207
+ };
208
+ }
209
+ case "compactionSummary": {
210
+ const { text, truncated } = truncate(m.summary, TEXT_CAP);
211
+ return {
212
+ id: `cs-${m.timestamp}-${seq}`,
213
+ role: "compactionSummary",
214
+ content: [{ type: "text", text, truncated }],
215
+ timestamp: m.timestamp,
216
+ };
217
+ }
218
+ default:
219
+ return {
220
+ id: `x-${seq}`,
221
+ role: String(m.role ?? "unknown"),
222
+ content: [],
223
+ timestamp: m.timestamp,
224
+ };
225
+ }
226
+ }
227
+ /**
228
+ * Serialize the in-progress assistant message (agent.state.streamingMessage).
229
+ *
230
+ * Unlike persisted messages, the id must be STABLE across snapshots: the SDK
231
+ * replaces the partial object on every stream event, so a seq-based id would
232
+ * remount the React component (and collapse open thinking/tool blocks) every
233
+ * 60ms. The timestamp is fixed at message creation, so `stream-<ts>` stays
234
+ * constant for the whole stream.
235
+ */
236
+ export function serializeStreamingMessage(m) {
237
+ const msg = serializeMessage(m, 0);
238
+ if (!msg)
239
+ return null;
240
+ return { ...msg, id: `stream-${m.timestamp ?? 0}` };
241
+ }
242
+ /** Stable discriminator for messages sharing a role and millisecond timestamp. */
243
+ const fingerprints = new WeakMap();
244
+ export function contentFingerprint(message) {
245
+ const cached = fingerprints.get(message);
246
+ if (cached)
247
+ return cached;
248
+ // Persisted messages are immutable. Hash all blocks once, including image
249
+ // bytes, thinking, tool arguments and custom metadata; a prefix/length is
250
+ // not an identity. Streaming messages never use this cache.
251
+ const fingerprint = createHash("sha256").update(JSON.stringify(message)).digest("hex");
252
+ fingerprints.set(message, fingerprint);
253
+ return fingerprint;
254
+ }
@@ -0,0 +1,225 @@
1
+ import { statSync } from "node:fs";
2
+ import { open, readFile, stat } from "node:fs/promises";
3
+ import { setImmediate as yieldLoop } from "node:timers/promises";
4
+ import { Worker } from "node:worker_threads";
5
+ import { StringDecoder } from "node:string_decoder";
6
+ import { isDeepStrictEqual } from "node:util";
7
+ import { parseSessionEntries } from "@earendil-works/pi-coding-agent";
8
+ const stamp = (s) => `${s.dev}:${s.ino}:${s.size}:${s.mtimeMs}:${s.ctimeMs}`;
9
+ const matches = (native, disk) => native !== undefined && isDeepStrictEqual(JSON.parse(JSON.stringify(native)), disk);
10
+ /** Verify the baseline once, then read only appended bytes except for equal-size stamp changes. */
11
+ export class SessionTailValidator {
12
+ path;
13
+ changed;
14
+ previous;
15
+ verified = new Set();
16
+ invalid = false;
17
+ missing = false;
18
+ disposed = false;
19
+ pending;
20
+ worker;
21
+ get checking() { return !!this.pending; }
22
+ blockingCheck = false;
23
+ get blocking() { return this.checking && this.blockingCheck; }
24
+ dispose() { this.disposed = true; void this.worker?.terminate(); }
25
+ async ready() { return this.pending ?? !this.invalid; }
26
+ async verify(source) { return this.check(source) ?? this.ready(); }
27
+ /** Includes baseline I/O; callers can measure subsequent reads by subtracting the initial value. */
28
+ bytesRead = 0;
29
+ constructor(path, source, changed = () => { }) {
30
+ this.path = path;
31
+ this.changed = changed;
32
+ this.check(source);
33
+ }
34
+ check(source) {
35
+ if (this.invalid || this.disposed)
36
+ return false;
37
+ if (this.pending)
38
+ return undefined;
39
+ this.blockingCheck = true;
40
+ try {
41
+ const current = statSync(this.path);
42
+ this.blockingCheck = !this.previous || current.size <= this.previous.size || current.ino !== this.previous.ino || current.dev !== this.previous.dev;
43
+ if (this.previous && stamp(this.previous) === stamp(current))
44
+ return true;
45
+ }
46
+ catch (error) {
47
+ if (this.missing && error.code === "ENOENT")
48
+ return true;
49
+ }
50
+ const finish = (valid) => {
51
+ this.pending = undefined;
52
+ if (this.disposed)
53
+ return false;
54
+ this.invalid = !valid;
55
+ if (this.blockingCheck || !valid)
56
+ this.changed();
57
+ return valid;
58
+ };
59
+ this.pending = this.validate(source).then(finish, () => finish(false));
60
+ return undefined;
61
+ }
62
+ compareInWorker(request) {
63
+ const worker = this.worker ??= new Worker(new URL(import.meta.url.endsWith(".ts") ? "./session-record-worker.ts" : "./session-record-worker.js", import.meta.url), { execArgv: process.execArgv.filter(arg => !arg.startsWith("--watch")) });
64
+ return new Promise((resolve, reject) => {
65
+ const cleanup = () => { worker.off("message", message); worker.off("error", failed); worker.off("exit", exited); };
66
+ const failed = (error) => { cleanup(); reject(error); };
67
+ const exited = () => failed(new Error("Record validation cancelled"));
68
+ const message = (result) => { cleanup(); if (result.error)
69
+ reject(new Error("Invalid session record"));
70
+ else
71
+ resolve(result); };
72
+ worker.once("message", message);
73
+ worker.once("error", failed);
74
+ worker.once("exit", exited);
75
+ worker.postMessage(request);
76
+ });
77
+ }
78
+ async validate(source) {
79
+ let handle;
80
+ let observed = false;
81
+ try {
82
+ const current = await stat(this.path);
83
+ observed = true;
84
+ const previous = this.previous;
85
+ if (previous && stamp(previous) === stamp(current))
86
+ return true;
87
+ if (previous && (previous.ino !== current.ino || previous.dev !== current.dev || current.size < previous.size))
88
+ return false;
89
+ const full = !previous || current.size === previous.size;
90
+ const offset = full ? 0 : previous.size;
91
+ const expected = full ? [source.getHeader(), ...source.getEntries()] : undefined;
92
+ const added = new Set();
93
+ let index = 0;
94
+ const accept = async (line) => {
95
+ if (!line.trim())
96
+ return true;
97
+ let id, equal;
98
+ if (line.length > 256 * 1024) {
99
+ ({ id } = await this.compareInWorker({ text: line }));
100
+ const native = full ? expected[index] : typeof id === "string" ? source.getEntry(id) : undefined;
101
+ equal = (await this.compareInWorker({ native })).equal === true;
102
+ }
103
+ else {
104
+ const entry = JSON.parse(line);
105
+ id = entry?.id;
106
+ equal = matches(full ? expected[index] : typeof id === "string" ? source.getEntry(id) : undefined, entry);
107
+ }
108
+ if (!equal || (!full && typeof id === "string" && this.verified.has(id)))
109
+ return false;
110
+ if (!(full && index === 0)) {
111
+ if (typeof id !== "string" || added.has(id))
112
+ return false;
113
+ added.add(id);
114
+ }
115
+ index++;
116
+ return true;
117
+ };
118
+ handle = await open(this.path, "r");
119
+ const opened = await handle.stat();
120
+ if (stamp(opened) !== stamp(current)) {
121
+ if (opened.ino !== current.ino || opened.dev !== current.dev || opened.size < current.size)
122
+ return false;
123
+ await handle.close();
124
+ handle = undefined;
125
+ return this.disposed ? false : this.validate(source);
126
+ }
127
+ const buffer = Buffer.alloc(64 * 1024), decoder = new StringDecoder("utf8");
128
+ let position = offset;
129
+ let fragments = [];
130
+ while (position < current.size) {
131
+ if (this.disposed)
132
+ return false;
133
+ const { bytesRead: n } = await handle.read(buffer, 0, Math.min(buffer.length, current.size - position), position);
134
+ if (!n)
135
+ return false;
136
+ position += n;
137
+ this.bytesRead += n;
138
+ const text = decoder.write(buffer.subarray(0, n));
139
+ let start = 0, newline;
140
+ while ((newline = text.indexOf("\n", start)) !== -1) {
141
+ fragments.push(text.slice(start, newline));
142
+ if (!await accept(fragments.join("")))
143
+ return false;
144
+ fragments = [];
145
+ start = newline + 1;
146
+ }
147
+ if (start < text.length)
148
+ fragments.push(text.slice(start));
149
+ await yieldLoop();
150
+ }
151
+ const after = await stat(this.path);
152
+ if (stamp(await handle.stat()) !== stamp(current) || stamp(after) !== stamp(current)) {
153
+ if (after.ino !== current.ino || after.dev !== current.dev || after.size < current.size)
154
+ return false;
155
+ await handle.close();
156
+ handle = undefined;
157
+ // Native writes may continue during metadata verification. Retry against
158
+ // the new snapshot instead of treating our own append as a conflict.
159
+ return this.disposed ? false : this.validate(source);
160
+ }
161
+ if (decoder.end() || fragments.length || !index || (expected && index !== expected.length))
162
+ return false;
163
+ if (full)
164
+ this.verified = added;
165
+ else
166
+ for (const id of added)
167
+ this.verified.add(id);
168
+ this.previous = current;
169
+ this.missing = false;
170
+ return true;
171
+ }
172
+ catch (error) {
173
+ this.missing = !observed && !this.previous && error.code === "ENOENT";
174
+ return this.missing;
175
+ }
176
+ finally {
177
+ await handle?.close();
178
+ if (this.worker) {
179
+ const worker = this.worker;
180
+ this.worker = undefined;
181
+ await worker.terminate();
182
+ }
183
+ }
184
+ }
185
+ }
186
+ /** Listing must never instantiate a SessionManager: open() can migrate and rewrite files. */
187
+ export class SessionBranchCounts {
188
+ cache = new Map();
189
+ async getMany(paths) {
190
+ const results = new Array(paths.length);
191
+ let next = 0;
192
+ await Promise.all(Array.from({ length: Math.min(8, paths.length) }, async () => {
193
+ while (next < paths.length) {
194
+ const index = next++;
195
+ results[index] = await this.get(paths[index]);
196
+ }
197
+ }));
198
+ return results;
199
+ }
200
+ async get(path) {
201
+ try {
202
+ const before = await stat(path), key = stamp(before);
203
+ const cached = this.cache.get(path);
204
+ if (cached?.stamp === key)
205
+ return cached.count;
206
+ const entries = parseSessionEntries(await readFile(path, "utf8"));
207
+ if (stamp(await stat(path)) !== key)
208
+ return undefined;
209
+ const parents = new Map();
210
+ for (const entry of entries)
211
+ if ("parentId" in entry && entry.parentId)
212
+ parents.set(entry.parentId, (parents.get(entry.parentId) ?? 0) + 1);
213
+ const count = [...parents.values()].filter(n => n > 1).length;
214
+ this.cache.delete(path);
215
+ this.cache.set(path, { stamp: key, count });
216
+ if (this.cache.size > 1000)
217
+ this.cache.delete(this.cache.keys().next().value);
218
+ return count;
219
+ }
220
+ catch {
221
+ this.cache.delete(path);
222
+ return undefined;
223
+ }
224
+ }
225
+ }
@@ -0,0 +1,21 @@
1
+ import { parentPort } from "node:worker_threads";
2
+ import { isDeepStrictEqual } from "node:util";
3
+ // Large JSON records are parsed and compared away from the server event loop.
4
+ let record;
5
+ parentPort.on("message", (request) => {
6
+ try {
7
+ if ("text" in request) {
8
+ record = JSON.parse(request.text);
9
+ parentPort.postMessage({ id: record?.id });
10
+ }
11
+ else {
12
+ const equal = request.native !== undefined && isDeepStrictEqual(JSON.parse(JSON.stringify(request.native)), record);
13
+ record = undefined;
14
+ parentPort.postMessage({ equal });
15
+ }
16
+ }
17
+ catch {
18
+ record = undefined;
19
+ parentPort.postMessage({ error: true });
20
+ }
21
+ });
@@ -0,0 +1,13 @@
1
+ const pending = new WeakMap();
2
+ /** Host reload entry points share one queue per native session. A failed
3
+ * reload is reported to its caller without poisoning later retries. */
4
+ export function reloadSession(session) {
5
+ const previous = pending.get(session) ?? Promise.resolve();
6
+ const operation = previous.catch(() => { }).then(() => session.reload());
7
+ pending.set(session, operation);
8
+ void operation.finally(() => {
9
+ if (pending.get(session) === operation)
10
+ pending.delete(session);
11
+ }).catch(() => { });
12
+ return operation;
13
+ }