@pasko70/pibo 1.0.5 → 1.2.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 (429) hide show
  1. package/README.md +106 -250
  2. package/context/codex-base-prompt.md +4 -0
  3. package/context/compute-worker.md +23 -0
  4. package/context/pibo-native-tooling.md +18 -0
  5. package/context/pibo-system-prompt.md +69 -8
  6. package/dist/api/simple-agent-api.js +136 -0
  7. package/dist/app-context.js +4 -0
  8. package/dist/apps/chat/agent-profiles.js +42 -5
  9. package/dist/apps/chat/agent-store.js +113 -16
  10. package/dist/apps/chat/chat-api-routes.js +311 -0
  11. package/dist/apps/chat/chat-capability-routes.js +90 -0
  12. package/dist/apps/chat/chat-files.js +178 -0
  13. package/dist/apps/chat/chat-request-normalizers.js +681 -0
  14. package/dist/apps/chat/chat-settings-routes.js +75 -0
  15. package/dist/apps/chat/chat-trace-helpers.js +94 -0
  16. package/dist/apps/chat/chat-user-skill-routes.js +149 -0
  17. package/dist/apps/chat/cron-api.js +213 -0
  18. package/dist/apps/chat/data/chat-data-mappers.js +74 -0
  19. package/dist/apps/chat/data/event-command-service.js +75 -0
  20. package/dist/apps/chat/data/navigation-query-service.js +11 -0
  21. package/dist/apps/chat/data/project-service.js +844 -0
  22. package/dist/apps/chat/data/read-state-service.js +42 -0
  23. package/dist/apps/chat/data/room-service.js +52 -0
  24. package/dist/apps/chat/data/session-query-service.js +63 -0
  25. package/dist/apps/chat/data/timeline-query-service.js +96 -0
  26. package/dist/apps/chat/event-log.js +1 -307
  27. package/dist/apps/chat/model-catalog.js +47 -0
  28. package/dist/apps/chat/output-compactor.js +126 -0
  29. package/dist/apps/chat/output-event-policy.js +17 -0
  30. package/dist/apps/chat/project-workflow-human-actions.js +347 -0
  31. package/dist/apps/chat/project-workflow-sessions.js +260 -0
  32. package/dist/apps/chat/provider-auth-actions.js +43 -0
  33. package/dist/apps/chat/ralph-api.js +156 -0
  34. package/dist/apps/chat/read-model.js +1 -218
  35. package/dist/apps/chat/rooms.js +1 -321
  36. package/dist/apps/chat/static-assets.js +996 -0
  37. package/dist/apps/chat/stream.js +29 -6
  38. package/dist/apps/chat/trace.js +179 -1003
  39. package/dist/apps/chat/types/event-store.js +1 -0
  40. package/dist/apps/chat/types/read-model.js +1 -0
  41. package/dist/apps/chat/types/rooms.js +36 -0
  42. package/dist/apps/chat/web-app.js +3168 -1811
  43. package/dist/apps/chat/workflow-catalog.js +572 -0
  44. package/dist/apps/chat/workflow-edge-compatibility.js +51 -0
  45. package/dist/apps/chat/workflow-json-schema-validation.js +335 -0
  46. package/dist/apps/chat/workflow-persistence-model.js +140 -0
  47. package/dist/apps/chat/workflow-persistence.js +633 -0
  48. package/dist/apps/chat/workflow-registered-ref-params.js +130 -0
  49. package/dist/apps/chat/workflow-registered-ref-pickers.js +179 -0
  50. package/dist/apps/chat/workflow-registered-ref-validation.js +210 -0
  51. package/dist/apps/chat/workflow-v2-security-validation.js +93 -0
  52. package/dist/apps/chat/workflow-validation-helpers.js +114 -0
  53. package/dist/apps/chat-ui/assets/{dist-CI0Xj2Cp.js → dist-B4lw9z4F.js} +1 -1
  54. package/dist/apps/chat-ui/assets/{dist-aMr2VYOu.js → dist-BbTaHWON.js} +1 -1
  55. package/dist/apps/chat-ui/assets/{dist-u2OzzOTm.js → dist-BcT_c1EJ.js} +1 -1
  56. package/dist/apps/chat-ui/assets/{dist-Di1ScJ22.js → dist-CGINd7XU.js} +1 -1
  57. package/dist/apps/chat-ui/assets/{dist-wiRpAHIv.js → dist-CrBzZkUp.js} +1 -1
  58. package/dist/apps/chat-ui/assets/{dist-CaNOvqMY.js → dist-CyyISotB.js} +1 -1
  59. package/dist/apps/chat-ui/assets/{dist-zgYUl2B-.js → dist-DFbnFNpX.js} +1 -1
  60. package/dist/apps/chat-ui/assets/{dist-CNlhGq5i.js → dist-DGLWQLX8.js} +1 -1
  61. package/dist/apps/chat-ui/assets/{dist-BGxHKHPX.js → dist-DfcIkFSN.js} +1 -1
  62. package/dist/apps/chat-ui/assets/{dist-DrM-H3e1.js → dist-sKDHTwaT.js} +1 -1
  63. package/dist/apps/chat-ui/assets/{dist-DpmEro5R.js → dist-y9D6la48.js} +1 -1
  64. package/dist/apps/chat-ui/assets/index-C25VYnyb.css +1 -0
  65. package/dist/apps/chat-ui/assets/index-CUkuvI3v.js +165 -0
  66. package/dist/apps/chat-ui/assets/pwa-images/android/launchericon-144x144.png +0 -0
  67. package/dist/apps/chat-ui/assets/pwa-images/android/launchericon-192x192.png +0 -0
  68. package/dist/apps/chat-ui/assets/pwa-images/android/launchericon-48x48.png +0 -0
  69. package/dist/apps/chat-ui/assets/pwa-images/android/launchericon-512x512.png +0 -0
  70. package/dist/apps/chat-ui/assets/pwa-images/android/launchericon-72x72.png +0 -0
  71. package/dist/apps/chat-ui/assets/pwa-images/android/launchericon-96x96.png +0 -0
  72. package/dist/apps/chat-ui/assets/pwa-images/ios/100.png +0 -0
  73. package/dist/apps/chat-ui/assets/pwa-images/ios/1024.png +0 -0
  74. package/dist/apps/chat-ui/assets/pwa-images/ios/114.png +0 -0
  75. package/dist/apps/chat-ui/assets/pwa-images/ios/120.png +0 -0
  76. package/dist/apps/chat-ui/assets/pwa-images/ios/128.png +0 -0
  77. package/dist/apps/chat-ui/assets/pwa-images/ios/144.png +0 -0
  78. package/dist/apps/chat-ui/assets/pwa-images/ios/152.png +0 -0
  79. package/dist/apps/chat-ui/assets/pwa-images/ios/16.png +0 -0
  80. package/dist/apps/chat-ui/assets/pwa-images/ios/167.png +0 -0
  81. package/dist/apps/chat-ui/assets/pwa-images/ios/180.png +0 -0
  82. package/dist/apps/chat-ui/assets/pwa-images/ios/192.png +0 -0
  83. package/dist/apps/chat-ui/assets/pwa-images/ios/20.png +0 -0
  84. package/dist/apps/chat-ui/assets/pwa-images/ios/256.png +0 -0
  85. package/dist/apps/chat-ui/assets/pwa-images/ios/29.png +0 -0
  86. package/dist/apps/chat-ui/assets/pwa-images/ios/32.png +0 -0
  87. package/dist/apps/chat-ui/assets/pwa-images/ios/40.png +0 -0
  88. package/dist/apps/chat-ui/assets/pwa-images/ios/50.png +0 -0
  89. package/dist/apps/chat-ui/assets/pwa-images/ios/512.png +0 -0
  90. package/dist/apps/chat-ui/assets/pwa-images/ios/57.png +0 -0
  91. package/dist/apps/chat-ui/assets/pwa-images/ios/58.png +0 -0
  92. package/dist/apps/chat-ui/assets/pwa-images/ios/60.png +0 -0
  93. package/dist/apps/chat-ui/assets/pwa-images/ios/64.png +0 -0
  94. package/dist/apps/chat-ui/assets/pwa-images/ios/72.png +0 -0
  95. package/dist/apps/chat-ui/assets/pwa-images/ios/76.png +0 -0
  96. package/dist/apps/chat-ui/assets/pwa-images/ios/80.png +0 -0
  97. package/dist/apps/chat-ui/assets/pwa-images/ios/87.png +0 -0
  98. package/dist/apps/chat-ui/assets/pwa-images/windows/LargeTile.scale-100.png +0 -0
  99. package/dist/apps/chat-ui/assets/pwa-images/windows/LargeTile.scale-125.png +0 -0
  100. package/dist/apps/chat-ui/assets/pwa-images/windows/LargeTile.scale-150.png +0 -0
  101. package/dist/apps/chat-ui/assets/pwa-images/windows/LargeTile.scale-200.png +0 -0
  102. package/dist/apps/chat-ui/assets/pwa-images/windows/LargeTile.scale-400.png +0 -0
  103. package/dist/apps/chat-ui/assets/pwa-images/windows/SmallTile.scale-100.png +0 -0
  104. package/dist/apps/chat-ui/assets/pwa-images/windows/SmallTile.scale-125.png +0 -0
  105. package/dist/apps/chat-ui/assets/pwa-images/windows/SmallTile.scale-150.png +0 -0
  106. package/dist/apps/chat-ui/assets/pwa-images/windows/SmallTile.scale-200.png +0 -0
  107. package/dist/apps/chat-ui/assets/pwa-images/windows/SmallTile.scale-400.png +0 -0
  108. package/dist/apps/chat-ui/assets/pwa-images/windows/SplashScreen.scale-100.png +0 -0
  109. package/dist/apps/chat-ui/assets/pwa-images/windows/SplashScreen.scale-125.png +0 -0
  110. package/dist/apps/chat-ui/assets/pwa-images/windows/SplashScreen.scale-150.png +0 -0
  111. package/dist/apps/chat-ui/assets/pwa-images/windows/SplashScreen.scale-200.png +0 -0
  112. package/dist/apps/chat-ui/assets/pwa-images/windows/SplashScreen.scale-400.png +0 -0
  113. package/dist/apps/chat-ui/assets/pwa-images/windows/Square150x150Logo.scale-100.png +0 -0
  114. package/dist/apps/chat-ui/assets/pwa-images/windows/Square150x150Logo.scale-125.png +0 -0
  115. package/dist/apps/chat-ui/assets/pwa-images/windows/Square150x150Logo.scale-150.png +0 -0
  116. package/dist/apps/chat-ui/assets/pwa-images/windows/Square150x150Logo.scale-200.png +0 -0
  117. package/dist/apps/chat-ui/assets/pwa-images/windows/Square150x150Logo.scale-400.png +0 -0
  118. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-16.png +0 -0
  119. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-20.png +0 -0
  120. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-24.png +0 -0
  121. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-256.png +0 -0
  122. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-30.png +0 -0
  123. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-32.png +0 -0
  124. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-36.png +0 -0
  125. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-40.png +0 -0
  126. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-44.png +0 -0
  127. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-48.png +0 -0
  128. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-60.png +0 -0
  129. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-64.png +0 -0
  130. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-72.png +0 -0
  131. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-80.png +0 -0
  132. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-lightunplated_targetsize-96.png +0 -0
  133. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-16.png +0 -0
  134. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-20.png +0 -0
  135. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-24.png +0 -0
  136. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-256.png +0 -0
  137. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-30.png +0 -0
  138. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-32.png +0 -0
  139. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-36.png +0 -0
  140. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-40.png +0 -0
  141. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-44.png +0 -0
  142. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-48.png +0 -0
  143. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-60.png +0 -0
  144. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-64.png +0 -0
  145. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-72.png +0 -0
  146. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-80.png +0 -0
  147. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.altform-unplated_targetsize-96.png +0 -0
  148. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.scale-100.png +0 -0
  149. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.scale-125.png +0 -0
  150. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.scale-150.png +0 -0
  151. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.scale-200.png +0 -0
  152. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.scale-400.png +0 -0
  153. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-16.png +0 -0
  154. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-20.png +0 -0
  155. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-24.png +0 -0
  156. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-256.png +0 -0
  157. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-30.png +0 -0
  158. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-32.png +0 -0
  159. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-36.png +0 -0
  160. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-40.png +0 -0
  161. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-44.png +0 -0
  162. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-48.png +0 -0
  163. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-60.png +0 -0
  164. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-64.png +0 -0
  165. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-72.png +0 -0
  166. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-80.png +0 -0
  167. package/dist/apps/chat-ui/assets/pwa-images/windows/Square44x44Logo.targetsize-96.png +0 -0
  168. package/dist/apps/chat-ui/assets/pwa-images/windows/StoreLogo.scale-100.png +0 -0
  169. package/dist/apps/chat-ui/assets/pwa-images/windows/StoreLogo.scale-125.png +0 -0
  170. package/dist/apps/chat-ui/assets/pwa-images/windows/StoreLogo.scale-150.png +0 -0
  171. package/dist/apps/chat-ui/assets/pwa-images/windows/StoreLogo.scale-200.png +0 -0
  172. package/dist/apps/chat-ui/assets/pwa-images/windows/StoreLogo.scale-400.png +0 -0
  173. package/dist/apps/chat-ui/assets/pwa-images/windows/Wide310x150Logo.scale-100.png +0 -0
  174. package/dist/apps/chat-ui/assets/pwa-images/windows/Wide310x150Logo.scale-125.png +0 -0
  175. package/dist/apps/chat-ui/assets/pwa-images/windows/Wide310x150Logo.scale-150.png +0 -0
  176. package/dist/apps/chat-ui/assets/pwa-images/windows/Wide310x150Logo.scale-200.png +0 -0
  177. package/dist/apps/chat-ui/assets/pwa-images/windows/Wide310x150Logo.scale-400.png +0 -0
  178. package/dist/apps/chat-ui/index.html +8 -3
  179. package/dist/apps/chat-ui/manifest.webmanifest +25 -0
  180. package/dist/apps/chat-ui/sw.js +41 -0
  181. package/dist/apps/cli-ui/InkSessionApp.js +1218 -0
  182. package/dist/apps/cli-ui/InkTerminalLine.js +53 -0
  183. package/dist/apps/cli-ui/InkTerminalRow.js +304 -0
  184. package/dist/apps/cli-ui/InkTerminalView.js +25 -0
  185. package/dist/apps/cli-ui/cliSessionsCommand.js +232 -0
  186. package/dist/apps/cli-ui/index.js +8 -0
  187. package/dist/apps/cli-ui/inkColors.js +67 -0
  188. package/dist/apps/cli-ui/inkJson.js +244 -0
  189. package/dist/apps/cli-ui/inkMarkdown.js +122 -0
  190. package/dist/apps/context-files-ui/assets/{dist-DFi2YGux.js → dist-BOiGdrG-.js} +1 -1
  191. package/dist/apps/context-files-ui/assets/{dist-DyfSeBMu.js → dist-DK01b7x4.js} +1 -1
  192. package/dist/apps/context-files-ui/assets/{dist-CwbH_3RN.js → dist-DPG9jOQ-.js} +1 -1
  193. package/dist/apps/context-files-ui/assets/{dist-dTBsFYAl.js → dist-Dp5AH00p.js} +1 -1
  194. package/dist/apps/context-files-ui/assets/{dist-CxRLRmMx.js → dist-DqYw0LH7.js} +1 -1
  195. package/dist/apps/context-files-ui/assets/{dist-MyZgX9K2.js → dist-TF5iO5ML.js} +1 -1
  196. package/dist/apps/context-files-ui/assets/{dist-DQXzt2Ng.js → dist-TbjAhles.js} +1 -1
  197. package/dist/apps/context-files-ui/assets/{dist-YwR9dpb-.js → dist-ZsBbt0uY.js} +1 -1
  198. package/dist/apps/context-files-ui/assets/{dist-CKQF1zEu.js → dist-kmsvtHkH.js} +1 -1
  199. package/dist/apps/context-files-ui/assets/{dist-BJW3917N.js → dist-vnd7PMu3.js} +1 -1
  200. package/dist/apps/context-files-ui/assets/{index-BwRDoHMC.css → index-B92tL3Pp.css} +1 -1
  201. package/dist/apps/context-files-ui/assets/{index-GwvjXytt.js → index-BhAWD3dv.js} +2 -2
  202. package/dist/apps/context-files-ui/index.html +2 -2
  203. package/dist/auth/better-auth.js +2 -1
  204. package/dist/auth/login-actions.js +251 -0
  205. package/dist/auth/openai-codex-usage.js +147 -0
  206. package/dist/bin/pibo.js +0 -0
  207. package/dist/bin/rg.js +15 -0
  208. package/dist/cli-session/fakeSessionSource.js +804 -0
  209. package/dist/cli-session/index.js +3 -0
  210. package/dist/cli-session/localSessionSource.js +1144 -0
  211. package/dist/cli-session/sessionSource.js +13 -0
  212. package/dist/cli.js +142 -14
  213. package/dist/compute/cli.js +415 -0
  214. package/dist/compute/docker.js +827 -0
  215. package/dist/compute/resource-health.js +333 -0
  216. package/dist/compute/resource-policy.js +98 -0
  217. package/dist/config/config.js +9 -5
  218. package/dist/core/context-build.js +677 -0
  219. package/dist/core/model-defaults.js +51 -9
  220. package/dist/core/pibo-home.js +8 -0
  221. package/dist/core/profiles.js +48 -0
  222. package/dist/core/provider-telemetry.js +222 -0
  223. package/dist/core/routed-session.js +441 -47
  224. package/dist/core/runtime-telemetry.js +853 -0
  225. package/dist/core/runtime.js +103 -15
  226. package/dist/core/session-errors.js +47 -0
  227. package/dist/core/session-model.js +39 -0
  228. package/dist/core/session-router.js +292 -62
  229. package/dist/core/shared-app.js +17 -0
  230. package/dist/core/skill-expansion.js +43 -0
  231. package/dist/core/system-prompt-template.js +9 -9
  232. package/dist/core/telemetry-staleness.js +128 -0
  233. package/dist/core/test-output-compaction.js +145 -0
  234. package/dist/core/user-settings.js +73 -0
  235. package/dist/cron/channel.js +28 -0
  236. package/dist/cron/cli.js +230 -0
  237. package/dist/cron/plugin.js +11 -0
  238. package/dist/cron/schedule.js +214 -0
  239. package/dist/cron/service.js +177 -0
  240. package/dist/cron/store.js +349 -0
  241. package/dist/cron/types.js +1 -0
  242. package/dist/data/cli.js +184 -0
  243. package/dist/data/event-log.js +106 -0
  244. package/dist/data/final-app-space-cutover-migration.js +728 -0
  245. package/dist/data/ingest-service.js +389 -0
  246. package/dist/data/message-store.js +62 -0
  247. package/dist/data/navigation-store.js +75 -0
  248. package/dist/data/observation-store.js +46 -0
  249. package/dist/data/payload-store.js +144 -0
  250. package/dist/data/pibo-store.js +59 -0
  251. package/dist/data/schema.js +434 -0
  252. package/dist/data/session-store.js +63 -0
  253. package/dist/data/shared-app-migration.js +757 -0
  254. package/dist/data/sqlite-schema.js +12 -0
  255. package/dist/data/telemetry-preview.js +65 -0
  256. package/dist/data/telemetry-queries.js +212 -0
  257. package/dist/data/telemetry-retention.js +50 -0
  258. package/dist/data/telemetry-rows.js +158 -0
  259. package/dist/data/telemetry.js +357 -0
  260. package/dist/debug/delta-compaction.js +99 -0
  261. package/dist/debug/detail-format.js +86 -0
  262. package/dist/debug/events.js +149 -29
  263. package/dist/debug/failures.js +162 -0
  264. package/dist/debug/index.js +655 -30
  265. package/dist/debug/messages.js +185 -0
  266. package/dist/debug/next-commands.js +6 -0
  267. package/dist/debug/payloads.js +123 -0
  268. package/dist/debug/pty.js +924 -0
  269. package/dist/debug/session.js +45 -15
  270. package/dist/debug/sql.js +1 -1
  271. package/dist/debug/stores.js +18 -13
  272. package/dist/debug/summary.js +72 -0
  273. package/dist/debug/telemetry.js +649 -0
  274. package/dist/debug/tools.js +168 -0
  275. package/dist/debug/trace-render-check.js +151 -0
  276. package/dist/debug/trace.js +152 -27
  277. package/dist/debug/web-artifacts.js +63 -0
  278. package/dist/debug/web-options.js +313 -0
  279. package/dist/debug/web-render-analysis.js +310 -0
  280. package/dist/debug/web-snapshot-browser-scripts.js +303 -0
  281. package/dist/debug/web-streaming-benchmark-analysis.js +605 -0
  282. package/dist/debug/web-streaming-browser-library.js +928 -0
  283. package/dist/debug/web-streaming-browser-scripts.js +242 -0
  284. package/dist/debug/web-streaming-provider-telemetry.js +194 -0
  285. package/dist/debug/web-streaming-report.js +493 -0
  286. package/dist/debug/web-streaming-types.js +1 -0
  287. package/dist/debug/web.js +574 -0
  288. package/dist/gateway/backup.js +83 -0
  289. package/dist/gateway/cli.js +511 -0
  290. package/dist/gateway/fallback.js +155 -0
  291. package/dist/gateway/pidfile.js +84 -0
  292. package/dist/gateway/protocol.js +16 -0
  293. package/dist/gateway/server.js +174 -17
  294. package/dist/gateway/tool.js +54 -51
  295. package/dist/gateway/web.js +74 -2
  296. package/dist/index.js +3 -1
  297. package/dist/local/client.js +3 -3
  298. package/dist/local/extension.js +8 -5
  299. package/dist/plugins/builtin.js +252 -49
  300. package/dist/plugins/chat-vscode-web.js +28 -0
  301. package/dist/plugins/codex-compat.js +0 -41
  302. package/dist/plugins/context-files.js +98 -18
  303. package/dist/plugins/dev-auth.js +124 -0
  304. package/dist/plugins/native-tooling.js +15 -0
  305. package/dist/plugins/registry.js +66 -2
  306. package/dist/plugins/web-annotations.js +27 -0
  307. package/dist/providers/minimax.js +70 -0
  308. package/dist/providers/openai-compat.js +48 -0
  309. package/dist/ralph/channel.js +8 -0
  310. package/dist/ralph/cli.js +152 -0
  311. package/dist/ralph/plugin.js +14 -0
  312. package/dist/ralph/service.js +271 -0
  313. package/dist/ralph/stopping.js +151 -0
  314. package/dist/ralph/store.js +450 -0
  315. package/dist/ralph/templates.js +200 -0
  316. package/dist/ralph/types.js +1 -0
  317. package/dist/reliability/store.js +42 -26
  318. package/dist/runs/registry.js +72 -35
  319. package/dist/session-ui/commandCatalog.js +193 -0
  320. package/dist/session-ui/commandResults.js +95 -0
  321. package/dist/session-ui/index.js +7 -0
  322. package/dist/session-ui/ownerViewModel.js +27 -0
  323. package/dist/session-ui/roomSessionViewModel.js +69 -0
  324. package/dist/session-ui/statusViewModel.js +127 -0
  325. package/dist/session-ui/terminalCards.js +210 -0
  326. package/dist/session-ui/terminalRows.js +937 -0
  327. package/dist/session-ui/terminalValue.js +45 -0
  328. package/dist/sessions/pibo-data-store.js +178 -0
  329. package/dist/sessions/sqlite-store.js +78 -12
  330. package/dist/sessions/store.js +11 -4
  331. package/dist/sessions/workflow-session-kind.js +20 -0
  332. package/dist/setup/cli.js +567 -0
  333. package/dist/shared/trace-async-agent-runs.js +127 -0
  334. package/dist/shared/trace-engine.js +96 -0
  335. package/dist/shared/trace-event-projection.js +679 -0
  336. package/dist/shared/trace-live-reducer.js +191 -0
  337. package/dist/shared/trace-nodes.js +76 -0
  338. package/dist/shared/trace-order.js +11 -10
  339. package/dist/shared/trace-patch-nodes.js +83 -0
  340. package/dist/shared/trace-run-notifications.js +69 -0
  341. package/dist/shared/trace-subagent-links.js +46 -0
  342. package/dist/shared/trace-transcript.js +303 -0
  343. package/dist/shared/trace-types.js +1 -0
  344. package/dist/shared-app.js +4 -0
  345. package/dist/signals/aggregate.js +65 -0
  346. package/dist/signals/events.js +1 -0
  347. package/dist/signals/projector.js +158 -0
  348. package/dist/signals/registry.js +513 -0
  349. package/dist/signals/store.js +1 -0
  350. package/dist/signals/types.js +1 -0
  351. package/dist/skills/cli.js +117 -0
  352. package/dist/tools/agent-browser-leases.js +219 -0
  353. package/dist/tools/agent-browser-wrapper.js +99 -0
  354. package/dist/tools/browser-pool.js +623 -0
  355. package/dist/tools/browser-use-cdp.js +56 -4
  356. package/dist/tools/browser-use-leases.js +215 -37
  357. package/dist/tools/browser-use-wrapper.js +508 -65
  358. package/dist/tools/cdp-client.js +189 -0
  359. package/dist/tools/guides.js +203 -4
  360. package/dist/tools/index.js +666 -16
  361. package/dist/tools/npm-runtime.js +136 -0
  362. package/dist/tools/registry.js +107 -8
  363. package/dist/tools/runtime/index.js +3 -0
  364. package/dist/tools/runtime/node-backend.js +225 -0
  365. package/dist/tools/runtime/node-worker-source.js +206 -0
  366. package/dist/tools/runtime/python-backend.js +227 -0
  367. package/dist/tools/runtime/python-worker-source.js +178 -0
  368. package/dist/tools/runtime/registry.js +255 -0
  369. package/dist/tools/runtime/tool.js +168 -0
  370. package/dist/tools/runtime/types.js +1 -0
  371. package/dist/tools/web-search.js +2 -1
  372. package/dist/user-skills/installer.js +214 -0
  373. package/dist/user-skills/manager.js +35 -0
  374. package/dist/user-skills/store.js +267 -0
  375. package/dist/user-skills/types.js +1 -0
  376. package/dist/web/auth.js +5 -1
  377. package/dist/web/channel.js +86 -0
  378. package/dist/web/http.js +79 -14
  379. package/dist/web-annotations/api.js +348 -0
  380. package/dist/web-annotations/attachments.js +201 -0
  381. package/dist/web-annotations/cdp.js +1107 -0
  382. package/dist/web-annotations/index.js +7 -0
  383. package/dist/web-annotations/store.js +407 -0
  384. package/dist/web-annotations/tools.js +350 -0
  385. package/dist/web-annotations/types.js +34 -0
  386. package/dist/web-annotations/validation.js +288 -0
  387. package/docs/README.md +23 -0
  388. package/docs/ops/install-developer-host.md +112 -0
  389. package/docs/ops/install-user-host.md +76 -0
  390. package/docs/ops/upgrade-user-to-developer-host.md +69 -0
  391. package/package.json +24 -10
  392. package/{.codex/skills → skills/builtin}/pi-agent-harness/SKILL.md +24 -24
  393. package/skills/builtin/pibo-docker-system/SKILL.md +170 -0
  394. package/skills/builtin/pibo-spec-writing/SKILL.md +330 -0
  395. package/skills/builtin/prd/SKILL.md +143 -0
  396. package/skills/builtin/ralph-loop/SKILL.md +359 -0
  397. package/skills/builtin/ralph-prd-json/SKILL.md +123 -0
  398. package/skills/builtin/skill-creator/LICENSE.txt +202 -0
  399. package/skills/builtin/skill-creator/SKILL.md +513 -0
  400. package/skills/builtin/skill-creator/agents/analyzer.md +274 -0
  401. package/skills/builtin/skill-creator/agents/comparator.md +202 -0
  402. package/skills/builtin/skill-creator/agents/grader.md +223 -0
  403. package/skills/builtin/skill-creator/assets/eval_review.html +146 -0
  404. package/skills/builtin/skill-creator/eval-viewer/generate_review.py +471 -0
  405. package/skills/builtin/skill-creator/eval-viewer/viewer.html +1325 -0
  406. package/skills/builtin/skill-creator/references/schemas.md +430 -0
  407. package/skills/builtin/skill-creator/scripts/__init__.py +0 -0
  408. package/skills/builtin/skill-creator/scripts/aggregate_benchmark.py +401 -0
  409. package/skills/builtin/skill-creator/scripts/generate_report.py +326 -0
  410. package/skills/builtin/skill-creator/scripts/improve_description.py +247 -0
  411. package/skills/builtin/skill-creator/scripts/package_skill.py +136 -0
  412. package/skills/builtin/skill-creator/scripts/quick_validate.py +103 -0
  413. package/skills/builtin/skill-creator/scripts/run_eval.py +310 -0
  414. package/skills/builtin/skill-creator/scripts/run_loop.py +328 -0
  415. package/skills/builtin/skill-creator/scripts/utils.py +47 -0
  416. package/skills/builtin/web-annotations/SKILL.md +93 -0
  417. package/dist/apps/chat-ui/assets/index-B_E935fP.js +0 -151
  418. package/dist/apps/chat-ui/assets/index-Dk-opWl3.css +0 -1
  419. package/dist/env.js +0 -32
  420. package/dist/plugins/core-tools.js +0 -94
  421. package/dist/plugins/example.js +0 -67
  422. package/dist/plugins/remote-agent.js +0 -9
  423. package/dist/remote/channel.js +0 -176
  424. package/dist/remote/client.js +0 -92
  425. package/dist/remote/examples/tui-controller.js +0 -263
  426. package/dist/remote/protocol.js +0 -55
  427. package/dist/remote/session-client.js +0 -189
  428. package/dist/sessions/bindings.js +0 -41
  429. /package/{.codex/skills → skills/builtin}/pi-agent-harness/agents/openai.yaml +0 -0
@@ -0,0 +1,928 @@
1
+ export function browserStreamingBenchmarkLibrary() {
2
+ return String.raw `
3
+ const ASSISTANT_SELECTOR = '[data-pibo-component="MarkdownRendererHost"][data-pibo-markdown-kind="assistant-message"]';
4
+ function nowIso() { return new Date().toISOString(); }
5
+ function cloneDebugSnapshot(value) {
6
+ if (!value || typeof value !== 'object') return undefined;
7
+ try { return JSON.parse(JSON.stringify(value)); } catch { return undefined; }
8
+ }
9
+ function numericDelta(before, after, keys) {
10
+ const delta = {};
11
+ for (const key of keys) {
12
+ const left = before && typeof before[key] === 'number' ? before[key] : 0;
13
+ const right = after && typeof after[key] === 'number' ? after[key] : 0;
14
+ delta[key] = right - left;
15
+ }
16
+ return delta;
17
+ }
18
+ function stats(values) {
19
+ const nums = values.filter((value) => Number.isFinite(value)).slice().sort((a, b) => a - b);
20
+ if (!nums.length) return { count: 0 };
21
+ const pick = (q) => nums[Math.min(nums.length - 1, Math.max(0, Math.floor((nums.length - 1) * q)))];
22
+ const avg = nums.reduce((sum, value) => sum + value, 0) / nums.length;
23
+ return {
24
+ count: nums.length,
25
+ min: Math.round(nums[0] * 1000) / 1000,
26
+ p50: Math.round(pick(0.50) * 1000) / 1000,
27
+ p90: Math.round(pick(0.90) * 1000) / 1000,
28
+ p99: Math.round(pick(0.99) * 1000) / 1000,
29
+ max: Math.round(nums[nums.length - 1] * 1000) / 1000,
30
+ avg: Math.round(avg * 1000) / 1000,
31
+ };
32
+ }
33
+ function fetchWithTimeout(url, init, timeoutMs) {
34
+ if (typeof AbortController === 'undefined') return fetch(url, init);
35
+ const controller = new AbortController();
36
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
37
+ return fetch(url, { ...init, signal: controller.signal }).finally(() => clearTimeout(timer));
38
+ }
39
+ function installOverlayDropSimulation(enabled) {
40
+ if (!enabled) {
41
+ delete window.__piboStreamingBenchmarkShouldDropOverlayEvent;
42
+ delete window.__piboStreamingBenchmarkOverlayDrop;
43
+ return undefined;
44
+ }
45
+ const state = {
46
+ requested: true,
47
+ installed: true,
48
+ dropTypes: ['TEXT_MESSAGE_CONTENT', 'REASONING_MESSAGE_CONTENT'],
49
+ droppedCount: 0,
50
+ passedCount: 0,
51
+ };
52
+ window.__piboStreamingBenchmarkOverlayDrop = state;
53
+ window.__piboStreamingBenchmarkShouldDropOverlayEvent = (event) => {
54
+ const type = event && typeof event.type === 'string' ? event.type : '';
55
+ if (state.dropTypes.includes(type)) {
56
+ state.droppedCount += 1;
57
+ state.lastDroppedType = type;
58
+ return true;
59
+ }
60
+ state.passedCount += 1;
61
+ return false;
62
+ };
63
+ return state;
64
+ }
65
+ function numberArray(value) {
66
+ return Array.isArray(value) ? value.filter((item) => typeof item === 'number' && Number.isFinite(item)) : [];
67
+ }
68
+ function scheduleGaps(scheduleMs) {
69
+ const gaps = [];
70
+ let previous = 0;
71
+ for (const delay of scheduleMs) {
72
+ gaps.push(delay - previous);
73
+ previous = delay;
74
+ }
75
+ return gaps;
76
+ }
77
+ function createSseProbe(piboSessionId, startedAt) {
78
+ const result = {
79
+ requested: true,
80
+ installed: false,
81
+ url: '/api/chat/events?piboSessionId=' + encodeURIComponent(piboSessionId) + '&mode=live&probe=streaming-benchmark-' + Date.now(),
82
+ headers: {},
83
+ aborted: false,
84
+ errors: [],
85
+ chunkCount: 0,
86
+ chunkBytes: { count: 0 },
87
+ chunkGapsMs: { count: 0 },
88
+ textEventsPerChunk: { count: 0 },
89
+ eventCount: 0,
90
+ textEventCount: 0,
91
+ reasoningEventCount: 0,
92
+ textDeltaBytes: { count: 0 },
93
+ textEventGapsMs: { count: 0 },
94
+ idCount: 0,
95
+ transientIdCount: 0,
96
+ durableIdCount: 0,
97
+ otherIdCount: 0,
98
+ };
99
+ const chunkBytes = [];
100
+ const chunkGaps = [];
101
+ const textEventsPerChunk = [];
102
+ const textDeltaBytes = [];
103
+ const textEventGaps = [];
104
+ const ids = [];
105
+ let lastChunkAt;
106
+ let lastTextAt;
107
+ let buffer = '';
108
+ let stopped = false;
109
+ let finished = false;
110
+ const controller = typeof AbortController === 'undefined' ? undefined : new AbortController();
111
+ const decoder = typeof TextDecoder === 'undefined' ? undefined : new TextDecoder();
112
+ const encoder = typeof TextEncoder === 'undefined' ? undefined : new TextEncoder();
113
+ const byteLength = (text) => encoder ? encoder.encode(text).length : String(text || '').length;
114
+ const finalize = () => {
115
+ result.chunkCount = chunkBytes.length;
116
+ result.chunkBytes = stats(chunkBytes);
117
+ result.chunkGapsMs = stats(chunkGaps);
118
+ result.textEventsPerChunk = stats(textEventsPerChunk);
119
+ result.textDeltaBytes = stats(textDeltaBytes);
120
+ result.textEventGapsMs = stats(textEventGaps);
121
+ result.idCount = ids.length;
122
+ result.transientIdCount = ids.filter((id) => /^live:\d+$/.test(id)).length;
123
+ result.durableIdCount = ids.filter((id) => /^\d+:\d+$/.test(id)).length;
124
+ result.otherIdCount = ids.filter((id) => !/^live:\d+$/.test(id) && !/^\d+:\d+$/.test(id)).length;
125
+ result.lastEventId = ids.at(-1);
126
+ return result;
127
+ };
128
+ const elapsed = (t) => Math.round((t - startedAt) * 1000) / 1000;
129
+ const consumeBlock = (block, t) => {
130
+ if (!block.trim()) return 0;
131
+ let eventName = '';
132
+ let id = '';
133
+ const data = [];
134
+ for (const line of block.split(/\r?\n/)) {
135
+ if (line.startsWith('event:')) eventName = line.slice(6).trim();
136
+ else if (line.startsWith('id:')) id = line.slice(3).trim();
137
+ else if (line.startsWith('data:')) data.push(line.slice(5).replace(/^ /, ''));
138
+ }
139
+ if (id) ids.push(id);
140
+ if (eventName && eventName !== 'pibo') return 0;
141
+ result.eventCount += 1;
142
+ result.firstEventMs ??= elapsed(t);
143
+ let payload;
144
+ try { payload = data.length ? JSON.parse(data.join('\n')) : undefined; } catch (error) { result.errors.push('parse: ' + String(error && error.message ? error.message : error)); }
145
+ if (!payload || typeof payload.type !== 'string') return 0;
146
+ if (payload.type === 'TEXT_MESSAGE_CONTENT') {
147
+ result.textEventCount += 1;
148
+ result.firstTextEventMs ??= elapsed(t);
149
+ const delta = typeof payload.delta === 'string' ? payload.delta : '';
150
+ textDeltaBytes.push(byteLength(delta));
151
+ if (lastTextAt !== undefined) textEventGaps.push(t - lastTextAt);
152
+ lastTextAt = t;
153
+ return 1;
154
+ }
155
+ if (payload.type === 'REASONING_MESSAGE_CONTENT') {
156
+ result.reasoningEventCount += 1;
157
+ result.firstReasoningEventMs ??= elapsed(t);
158
+ }
159
+ return 0;
160
+ };
161
+ if (typeof fetch !== 'function' || !decoder) {
162
+ result.errors.push('fetch streaming unavailable');
163
+ return { result: finalize(), stop: async () => finalize() };
164
+ }
165
+ const done = (async () => {
166
+ try {
167
+ const response = await fetch(result.url, { headers: { accept: 'text/event-stream' }, signal: controller && controller.signal });
168
+ result.status = response.status;
169
+ response.headers.forEach((value, key) => { result.headers[key] = value; });
170
+ if (!response.body || typeof response.body.getReader !== 'function') throw new Error('ReadableStream unavailable');
171
+ result.installed = true;
172
+ const reader = response.body.getReader();
173
+ while (true) {
174
+ const next = await reader.read();
175
+ if (next.done) break;
176
+ const t = performance.now();
177
+ result.firstChunkMs ??= elapsed(t);
178
+ if (lastChunkAt !== undefined) chunkGaps.push(t - lastChunkAt);
179
+ lastChunkAt = t;
180
+ const value = next.value || new Uint8Array();
181
+ chunkBytes.push(value.byteLength || value.length || 0);
182
+ buffer += decoder.decode(value, { stream: true });
183
+ let chunkTextEvents = 0;
184
+ while (true) {
185
+ const index = buffer.search(/\r?\n\r?\n/);
186
+ if (index < 0) break;
187
+ const separatorLength = buffer[index] === '\r' ? 4 : 2;
188
+ const block = buffer.slice(0, index);
189
+ buffer = buffer.slice(index + separatorLength);
190
+ chunkTextEvents += consumeBlock(block, t);
191
+ }
192
+ textEventsPerChunk.push(chunkTextEvents);
193
+ }
194
+ buffer += decoder.decode();
195
+ if (buffer.trim()) consumeBlock(buffer, performance.now());
196
+ } catch (error) {
197
+ if (stopped || (error && error.name === 'AbortError')) result.aborted = true;
198
+ else result.errors.push(String(error && error.message ? error.message : error));
199
+ } finally {
200
+ finished = true;
201
+ finalize();
202
+ }
203
+ })();
204
+ return {
205
+ result,
206
+ stop: async () => {
207
+ stopped = true;
208
+ if (controller) controller.abort();
209
+ await Promise.race([done.catch(() => {}), new Promise((resolve) => setTimeout(resolve, 2500))]);
210
+ if (!finished) {
211
+ result.aborted = true;
212
+ result.errors.push('stop timeout after abort');
213
+ }
214
+ return finalize();
215
+ },
216
+ };
217
+ }
218
+ async function waitForSseProbeReady(probe, timeoutMs) {
219
+ const started = performance.now();
220
+ while (performance.now() - started < timeoutMs) {
221
+ if (!probe || probe.installed || probe.status || (probe.errors && probe.errors.length)) return;
222
+ await new Promise((resolve) => setTimeout(resolve, 25));
223
+ }
224
+ }
225
+ function createTraceProbe(piboSessionId, startedAt, intervalMs) {
226
+ const result = {
227
+ requested: true,
228
+ installed: true,
229
+ piboSessionId,
230
+ intervalMs,
231
+ sampleCount: 0,
232
+ fetchCount: 0,
233
+ failedFetchCount: 0,
234
+ liveVersionCount: 0,
235
+ maxAssistantOutputLength: 0,
236
+ samples: [],
237
+ };
238
+ let sampling = false;
239
+ const sample = async () => {
240
+ if (sampling) return;
241
+ sampling = true;
242
+ try {
243
+ const t = Math.round(performance.now() - startedAt);
244
+ const response = await fetchWithTimeout('/api/chat/trace?piboSessionId=' + encodeURIComponent(piboSessionId) + '&includeRawEvents=true&rawEventsLimit=80', {}, 2500);
245
+ if (!response.ok) throw new Error(response.status + ' ' + response.statusText);
246
+ const trace = await response.json();
247
+ result.fetchCount += 1;
248
+ const version = typeof trace.version === 'string' ? trace.version : undefined;
249
+ const rawEvents = Array.isArray(trace.rawEvents) ? trace.rawEvents : [];
250
+ const assistantOutputLength = maxTraceAssistantOutputLength(trace);
251
+ const liveVersion = Boolean(version && version.includes(':live:'));
252
+ const sampleResult = {
253
+ t,
254
+ version,
255
+ eventCount: typeof trace.eventCount === 'number' ? trace.eventCount : undefined,
256
+ rawEventCount: rawEvents.length,
257
+ assistantOutputLength,
258
+ liveVersion,
259
+ rawEventTypes: countRawTraceEventTypes(rawEvents),
260
+ };
261
+ result.samples.push(sampleResult);
262
+ if (result.samples.length > 80) result.samples.shift();
263
+ result.sampleCount = result.samples.length;
264
+ result.maxAssistantOutputLength = Math.max(result.maxAssistantOutputLength, assistantOutputLength);
265
+ result.finalAssistantOutputLength = assistantOutputLength;
266
+ if (typeof sampleResult.eventCount === 'number') {
267
+ result.durableEventCountStart ??= sampleResult.eventCount;
268
+ result.durableEventCountEnd = sampleResult.eventCount;
269
+ }
270
+ if (liveVersion) {
271
+ result.liveVersionCount += 1;
272
+ result.firstLiveVersionMs ??= t;
273
+ }
274
+ } catch {
275
+ result.failedFetchCount += 1;
276
+ } finally {
277
+ sampling = false;
278
+ }
279
+ };
280
+ const timer = setInterval(() => { sample().catch(() => {}); }, intervalMs);
281
+ return { result, sample, stop: () => clearInterval(timer) };
282
+ }
283
+ function countRawTraceEventTypes(rawEvents) {
284
+ const counts = {};
285
+ for (const event of rawEvents) {
286
+ const type = typeof event?.type === 'string' ? event.type : (typeof event?.payload?.type === 'string' ? event.payload.type : 'unknown');
287
+ counts[type] = (counts[type] || 0) + 1;
288
+ }
289
+ return counts;
290
+ }
291
+ function maxTraceAssistantOutputLength(trace) {
292
+ let max = 0;
293
+ const visit = (node) => {
294
+ if (!node || typeof node !== 'object') return;
295
+ if (node.type === 'assistant.message' && typeof node.output === 'string') max = Math.max(max, node.output.length);
296
+ if (Array.isArray(node.children)) node.children.forEach(visit);
297
+ };
298
+ if (Array.isArray(trace?.nodes)) trace.nodes.forEach(visit);
299
+ return max;
300
+ }
301
+ function summarizeEventSourceProbe(startedAt, requested, forcedReconnectAtMs, textDropRequested, textDropDurationMs) {
302
+ const probe = window.__piboStreamingBenchmarkEventSourceProbe;
303
+ if (!requested) return undefined;
304
+ if (!probe) {
305
+ return {
306
+ requested,
307
+ installed: false,
308
+ forcedReconnectAtMs,
309
+ openCount: 0,
310
+ openCountAfterStart: 0,
311
+ errorCount: 0,
312
+ errorCountAfterStart: 0,
313
+ closeCount: 0,
314
+ forcedCloseCount: 0,
315
+ forcedCloseCountAfterStart: 0,
316
+ eventCount: 0,
317
+ eventCountAfterStart: 0,
318
+ textEventCount: 0,
319
+ textEventCountAfterStart: 0,
320
+ reasoningEventCount: 0,
321
+ reasoningEventCountAfterStart: 0,
322
+ transientIdCount: 0,
323
+ uniqueTransientIdCount: 0,
324
+ transientIdCountAfterStart: 0,
325
+ uniqueTransientIdCountAfterStart: 0,
326
+ durableIdCount: 0,
327
+ otherIdCount: 0,
328
+ transientIdResetObserved: false,
329
+ reconnectObserved: false,
330
+ textDropRequested: Boolean(textDropRequested),
331
+ textDropDurationMs,
332
+ textDropCount: 0,
333
+ textDropTextEventCount: 0,
334
+ streams: [],
335
+ };
336
+ }
337
+ const streamEvents = (Array.isArray(probe.events) ? probe.events : []).filter((event) => String(event.url || '').includes('/api/chat/events'));
338
+ const afterStartStreamEvents = streamEvents.filter((event) => typeof event.t === 'number' && event.t >= startedAt);
339
+ const afterStartConnections = (Array.isArray(probe.connections) ? probe.connections : []).filter((event) => typeof event.t === 'number' && event.t >= startedAt && String(event.url || '').includes('/api/chat/events'));
340
+ const ids = streamEvents.map((event) => event.lastEventId).filter(Boolean);
341
+ const afterStartIds = afterStartStreamEvents.map((event) => event.lastEventId).filter(Boolean);
342
+ const transientIds = ids.filter((id) => /^live:\d+$/.test(id));
343
+ const afterStartTransientIds = afterStartIds.filter((id) => /^live:\d+$/.test(id));
344
+ const durableIds = ids.filter((id) => /^\d+:\d+$/.test(id));
345
+ const otherIds = ids.filter((id) => !/^live:\d+$/.test(id) && !/^\d+:\d+$/.test(id));
346
+ const firstEventMsAfterStart = firstProbeEventMs(afterStartStreamEvents, startedAt);
347
+ const firstTextEventMsAfterStart = firstProbeEventMs(afterStartStreamEvents, startedAt, 'TEXT_MESSAGE_CONTENT');
348
+ const firstReasoningEventMsAfterStart = firstProbeEventMs(afterStartStreamEvents, startedAt, 'REASONING_MESSAGE_CONTENT');
349
+ const forcedCloseCountAfterStart = afterStartConnections.filter((event) => event.kind === 'close' && event.forced).length;
350
+ const openCountAfterStart = afterStartConnections.filter((event) => event.kind === 'open').length;
351
+ const streams = summarizeEventSourceStreams(streamEvents, afterStartConnections, startedAt);
352
+ return {
353
+ requested,
354
+ installed: true,
355
+ forcedReconnectAtMs,
356
+ openCount: Number(probe.openCount || 0),
357
+ openCountAfterStart,
358
+ errorCount: Number(probe.errorCount || 0),
359
+ errorCountAfterStart: afterStartConnections.filter((event) => event.kind === 'error').length,
360
+ closeCount: Number(probe.closeCount || 0),
361
+ forcedCloseCount: Number(probe.forcedCloseCount || 0),
362
+ forcedCloseCountAfterStart,
363
+ eventCount: streamEvents.length,
364
+ eventCountAfterStart: afterStartStreamEvents.length,
365
+ textEventCount: streamEvents.filter((event) => event.type === 'TEXT_MESSAGE_CONTENT').length,
366
+ textEventCountAfterStart: afterStartStreamEvents.filter((event) => event.type === 'TEXT_MESSAGE_CONTENT').length,
367
+ reasoningEventCount: streamEvents.filter((event) => event.type === 'REASONING_MESSAGE_CONTENT').length,
368
+ reasoningEventCountAfterStart: afterStartStreamEvents.filter((event) => event.type === 'REASONING_MESSAGE_CONTENT').length,
369
+ transientIdCount: transientIds.length,
370
+ uniqueTransientIdCount: new Set(transientIds).size,
371
+ transientIdCountAfterStart: afterStartTransientIds.length,
372
+ uniqueTransientIdCountAfterStart: new Set(afterStartTransientIds).size,
373
+ durableIdCount: durableIds.length,
374
+ otherIdCount: otherIds.length,
375
+ lastEventId: ids.at(-1),
376
+ firstTransientId: transientIds[0],
377
+ firstEventMsAfterStart,
378
+ firstTextEventMsAfterStart,
379
+ firstReasoningEventMsAfterStart,
380
+ lastTransientId: transientIds.at(-1),
381
+ transientIdResetObserved: new Set(transientIds).size < transientIds.length,
382
+ reconnectObserved: forcedCloseCountAfterStart > 0 && openCountAfterStart > 0,
383
+ textDropRequested: Boolean(textDropRequested),
384
+ textDropDurationMs: textDropRequested ? Number(probe.textDropDurationMs || textDropDurationMs || 0) || undefined : undefined,
385
+ textDropCount: textDropRequested ? Number(probe.textDropCount || 0) : 0,
386
+ textDropTextEventCount: textDropRequested ? Number(probe.textDropTextEventCount || 0) : 0,
387
+ streams,
388
+ };
389
+ }
390
+ function firstProbeEventMs(events, startedAt, type) {
391
+ const event = events.find((item) => typeof item.t === 'number' && (type === undefined || item.type === type));
392
+ return event ? Math.round((event.t - startedAt) * 1000) / 1000 : undefined;
393
+ }
394
+ function summarizeEventSourceStreams(streamEvents, afterStartConnections, startedAt) {
395
+ const groups = new Map();
396
+ const ensureGroup = (rawUrl) => {
397
+ const parsed = parseChatEventsProbeUrl(rawUrl);
398
+ const key = [parsed.role, parsed.piboSessionId || '', parsed.roomId || '', parsed.mode || '', parsed.url].join('|');
399
+ let group = groups.get(key);
400
+ if (!group) {
401
+ group = {
402
+ url: parsed.url,
403
+ mode: parsed.mode,
404
+ role: parsed.role,
405
+ piboSessionId: parsed.piboSessionId,
406
+ roomId: parsed.roomId,
407
+ sinceValues: [],
408
+ liveSinceValues: [],
409
+ openCountAfterStart: 0,
410
+ errorCountAfterStart: 0,
411
+ closeCountAfterStart: 0,
412
+ forcedCloseCountAfterStart: 0,
413
+ events: [],
414
+ };
415
+ groups.set(key, group);
416
+ }
417
+ if (parsed.since && !group.sinceValues.includes(parsed.since)) group.sinceValues.push(parsed.since);
418
+ if (parsed.liveSince && !group.liveSinceValues.includes(parsed.liveSince)) group.liveSinceValues.push(parsed.liveSince);
419
+ return group;
420
+ };
421
+ for (const event of streamEvents) ensureGroup(event.url).events.push(event);
422
+ for (const connection of afterStartConnections) {
423
+ const group = ensureGroup(connection.url);
424
+ if (connection.kind === 'open') group.openCountAfterStart += 1;
425
+ else if (connection.kind === 'error') group.errorCountAfterStart += 1;
426
+ else if (connection.kind === 'close') {
427
+ group.closeCountAfterStart += 1;
428
+ if (connection.forced) group.forcedCloseCountAfterStart += 1;
429
+ }
430
+ }
431
+ return Array.from(groups.values()).map((group) => {
432
+ const events = group.events;
433
+ const afterStartEvents = events.filter((event) => typeof event.t === 'number' && event.t >= startedAt);
434
+ const ids = events.map((event) => event.lastEventId).filter(Boolean);
435
+ const afterStartIds = afterStartEvents.map((event) => event.lastEventId).filter(Boolean);
436
+ const transientIds = ids.filter((id) => /^live:\d+$/.test(id));
437
+ const afterStartTransientIds = afterStartIds.filter((id) => /^live:\d+$/.test(id));
438
+ const liveReplayReplayedCount = events.reduce((total, event) => total + (typeof event.liveReplayReplayed === 'number' && Number.isFinite(event.liveReplayReplayed) ? event.liveReplayReplayed : 0), 0);
439
+ const liveReplayReplayedCountAfterStart = afterStartEvents.reduce((total, event) => total + (typeof event.liveReplayReplayed === 'number' && Number.isFinite(event.liveReplayReplayed) ? event.liveReplayReplayed : 0), 0);
440
+ const liveReplayMisses = events.filter((event) => event.liveReplayMissed === true);
441
+ const afterStartLiveReplayMisses = afterStartEvents.filter((event) => event.liveReplayMissed === true);
442
+ const liveReplayDuplicateCount = countLiveReplayDuplicateIds(events);
443
+ const liveReplayDuplicateCountAfterStart = countLiveReplayDuplicateIds(events, startedAt);
444
+ const liveReplayEvictedBeforeValues = events.map((event) => event.liveReplayEvictedBefore).filter((value) => typeof value === 'number' && Number.isFinite(value));
445
+ const liveReplayCursorLagValues = events.map((event) => typeof event.liveReplayRequestedAfter === 'number' && Number.isFinite(event.liveReplayRequestedAfter) && typeof event.liveReplayNewestAvailable === 'number' && Number.isFinite(event.liveReplayNewestAvailable) ? Math.max(0, event.liveReplayNewestAvailable - event.liveReplayRequestedAfter) : undefined).filter((value) => typeof value === 'number' && Number.isFinite(value));
446
+ const afterStartLiveReplayCursorLagValues = afterStartEvents.map((event) => typeof event.liveReplayRequestedAfter === 'number' && Number.isFinite(event.liveReplayRequestedAfter) && typeof event.liveReplayNewestAvailable === 'number' && Number.isFinite(event.liveReplayNewestAvailable) ? Math.max(0, event.liveReplayNewestAvailable - event.liveReplayRequestedAfter) : undefined).filter((value) => typeof value === 'number' && Number.isFinite(value));
447
+ const firstEventMsAfterStart = firstProbeEventMs(afterStartEvents, startedAt);
448
+ const firstTextEventMsAfterStart = firstProbeEventMs(afterStartEvents, startedAt, 'TEXT_MESSAGE_CONTENT');
449
+ const firstReasoningEventMsAfterStart = firstProbeEventMs(afterStartEvents, startedAt, 'REASONING_MESSAGE_CONTENT');
450
+ const durableIds = ids.filter((id) => /^\d+:\d+$/.test(id));
451
+ const otherIds = ids.filter((id) => !/^live:\d+$/.test(id) && !/^\d+:\d+$/.test(id));
452
+ return {
453
+ url: group.url,
454
+ mode: group.mode,
455
+ role: group.role,
456
+ piboSessionId: group.piboSessionId,
457
+ roomId: group.roomId,
458
+ sinceValues: group.sinceValues,
459
+ liveSinceValues: group.liveSinceValues,
460
+ openCountAfterStart: group.openCountAfterStart,
461
+ errorCountAfterStart: group.errorCountAfterStart,
462
+ closeCountAfterStart: group.closeCountAfterStart,
463
+ forcedCloseCountAfterStart: group.forcedCloseCountAfterStart,
464
+ eventCount: events.length,
465
+ eventCountAfterStart: afterStartEvents.length,
466
+ textEventCount: events.filter((event) => event.type === 'TEXT_MESSAGE_CONTENT').length,
467
+ textEventCountAfterStart: afterStartEvents.filter((event) => event.type === 'TEXT_MESSAGE_CONTENT').length,
468
+ reasoningEventCount: events.filter((event) => event.type === 'REASONING_MESSAGE_CONTENT').length,
469
+ reasoningEventCountAfterStart: afterStartEvents.filter((event) => event.type === 'REASONING_MESSAGE_CONTENT').length,
470
+ transientIdCount: transientIds.length,
471
+ uniqueTransientIdCount: new Set(transientIds).size,
472
+ transientIdCountAfterStart: afterStartTransientIds.length,
473
+ uniqueTransientIdCountAfterStart: new Set(afterStartTransientIds).size,
474
+ durableIdCount: durableIds.length,
475
+ otherIdCount: otherIds.length,
476
+ liveReplayEventCount: liveReplayReplayedCount,
477
+ liveReplayEventCountAfterStart: liveReplayReplayedCountAfterStart,
478
+ liveReplayMissedCount: liveReplayMisses.length,
479
+ liveReplayMissedCountAfterStart: afterStartLiveReplayMisses.length,
480
+ liveReplayDuplicateCount,
481
+ liveReplayDuplicateCountAfterStart,
482
+ liveReplayEvictedBeforeMax: liveReplayEvictedBeforeValues.length ? Math.max(...liveReplayEvictedBeforeValues) : undefined,
483
+ liveReplayCursorLagMax: liveReplayCursorLagValues.length ? Math.max(...liveReplayCursorLagValues) : undefined,
484
+ liveReplayCursorLagMaxAfterStart: afterStartLiveReplayCursorLagValues.length ? Math.max(...afterStartLiveReplayCursorLagValues) : undefined,
485
+ lastEventId: ids.at(-1),
486
+ firstEventMsAfterStart,
487
+ firstTextEventMsAfterStart,
488
+ firstReasoningEventMsAfterStart,
489
+ };
490
+ }).sort((left, right) => roleSort(left.role) - roleSort(right.role) || left.url.localeCompare(right.url));
491
+ }
492
+ function countLiveReplayDuplicateIds(events, startedAt) {
493
+ const seen = new Set();
494
+ let duplicateCount = 0;
495
+ const ordered = events.slice().sort((left, right) => Number(left.t || 0) - Number(right.t || 0));
496
+ for (const event of ordered) {
497
+ const requestedAfter = typeof event.liveReplayRequestedAfter === 'number' && Number.isFinite(event.liveReplayRequestedAfter) ? event.liveReplayRequestedAfter : undefined;
498
+ const newestAvailable = typeof event.liveReplayNewestAvailable === 'number' && Number.isFinite(event.liveReplayNewestAvailable) ? event.liveReplayNewestAvailable : undefined;
499
+ const replayed = typeof event.liveReplayReplayed === 'number' && Number.isFinite(event.liveReplayReplayed) ? event.liveReplayReplayed : 0;
500
+ const countThisStatus = startedAt === undefined || (typeof event.t === 'number' && event.t >= startedAt);
501
+ if (countThisStatus && replayed > 0 && requestedAfter !== undefined && newestAvailable !== undefined) {
502
+ for (const replayId of seen) {
503
+ if (replayId > requestedAfter && replayId <= newestAvailable) duplicateCount += 1;
504
+ }
505
+ }
506
+ if (typeof event.liveReplayId === 'number' && Number.isFinite(event.liveReplayId)) seen.add(event.liveReplayId);
507
+ }
508
+ return duplicateCount;
509
+ }
510
+ function parseChatEventsProbeUrl(rawUrl) {
511
+ let parsed;
512
+ try { parsed = new URL(String(rawUrl || ''), location.href); } catch { parsed = new URL('/api/chat/events', location.href); }
513
+ const params = parsed.searchParams;
514
+ const mode = params.get('mode') || undefined;
515
+ const piboSessionId = params.get('piboSessionId') || undefined;
516
+ const roomId = params.get('roomId') || undefined;
517
+ const role = mode === 'summary' || (roomId && !piboSessionId) ? 'room-summary' : (mode === 'live' || piboSessionId ? 'selected-live' : 'chat-events');
518
+ const withoutResume = new URL(parsed.href);
519
+ withoutResume.searchParams.delete('since');
520
+ withoutResume.searchParams.delete('liveSince');
521
+ return {
522
+ url: withoutResume.pathname + (withoutResume.search ? withoutResume.search : ''),
523
+ mode,
524
+ role,
525
+ piboSessionId,
526
+ roomId,
527
+ since: params.get('since') || undefined,
528
+ liveSince: params.get('liveSince') || undefined,
529
+ };
530
+ }
531
+ function roleSort(role) {
532
+ if (role === 'selected-live') return 0;
533
+ if (role === 'room-summary') return 1;
534
+ return 2;
535
+ }
536
+ function streamingBenchmarkRegressions(result) {
537
+ const failures = [];
538
+ const fixture = result.fixture;
539
+ const expectedDeltas = fixture && typeof fixture.deltaCount === 'number' ? fixture.deltaCount : undefined;
540
+ const expectedReasoningDeltas = fixture && typeof fixture.reasoningDeltaCount === 'number' ? fixture.reasoningDeltaCount : undefined;
541
+ const cadenceMs = fixture && typeof fixture.cadenceMs === 'number' ? fixture.cadenceMs : 100;
542
+ const textDeltas = result.debugDelta && typeof result.debugDelta.textDeltaCount === 'number' ? result.debugDelta.textDeltaCount : 0;
543
+ const reasoningDeltas = result.debugDelta && typeof result.debugDelta.reasoningDeltaCount === 'number' ? result.debugDelta.reasoningDeltaCount : 0;
544
+ const domPositive = result.dom.positiveUpdateCount || 0;
545
+ const domGapP90 = result.dom.gapsMs && typeof result.dom.gapsMs.p90 === 'number' ? result.dom.gapsMs.p90 : undefined;
546
+ const domJumpMax = result.dom.positiveCharJumps && typeof result.dom.positiveCharJumps.max === 'number' ? result.dom.positiveCharJumps.max : undefined;
547
+ const firstPositiveMs = typeof result.dom.firstPositiveUpdateMs === 'number' ? result.dom.firstPositiveUpdateMs : undefined;
548
+ const longTaskMax = result.longTasks.length ? Math.max(...result.longTasks) : 0;
549
+ const traceCatchupRequested = Boolean(result.eventSource && result.eventSource.textDropRequested);
550
+ const reconnectRequested = Boolean(result.eventSource && typeof result.eventSource.forcedReconnectAtMs === 'number');
551
+ if (!result.debugAfter) failures.push('debug counters unavailable');
552
+ if (fixture) {
553
+ if (!fixture.available) failures.push('fixture unavailable');
554
+ if (!fixture.started) failures.push('fixture did not start');
555
+ if (fixture.error) failures.push('fixture error: ' + fixture.error);
556
+ if (!traceCatchupRequested && expectedDeltas !== undefined && textDeltas < expectedDeltas) failures.push('text deltas ' + textDeltas + ' < fixture deltas ' + expectedDeltas);
557
+ if (!traceCatchupRequested && expectedReasoningDeltas !== undefined && reasoningDeltas < expectedReasoningDeltas) failures.push('reasoning deltas ' + reasoningDeltas + ' < fixture reasoning deltas ' + expectedReasoningDeltas);
558
+ if (!traceCatchupRequested && expectedDeltas !== undefined && domPositive < Math.max(1, expectedDeltas - 2)) failures.push('positive DOM updates ' + domPositive + ' < ' + Math.max(1, expectedDeltas - 2));
559
+ if (!traceCatchupRequested && domGapP90 !== undefined && domGapP90 > Math.max(300, cadenceMs * 3)) failures.push('DOM p90 gap ' + domGapP90 + 'ms exceeds gate');
560
+ if (!traceCatchupRequested && domJumpMax !== undefined && domJumpMax > 4) failures.push('DOM max jump ' + domJumpMax + ' chars exceeds gate');
561
+ if (!traceCatchupRequested && firstPositiveMs !== undefined && firstPositiveMs > 500) failures.push('first visible update ' + firstPositiveMs + 'ms exceeds gate');
562
+ if (traceCatchupRequested) {
563
+ const traceRefreshes = result.debugDelta && typeof result.debugDelta.traceRefreshCompletedCount === 'number' ? result.debugDelta.traceRefreshCompletedCount : 0;
564
+ if (traceRefreshes < 1) failures.push('trace catch-up did not complete a trace refresh');
565
+ const maxVisibleLength = result.dom && typeof result.dom.lengthMax === 'number' ? result.dom.lengthMax : result.dom && result.dom.lengthEnd;
566
+ if (!result.dom || !(maxVisibleLength > result.dom.lengthStart)) failures.push('trace catch-up did not advance visible DOM output');
567
+ if (expectedDeltas !== undefined && textDeltas > Math.max(1, expectedDeltas - 2)) failures.push('trace catch-up did not suppress live text deltas before recovery');
568
+ if (!result.trace) failures.push('trace catch-up trace probe unavailable');
569
+ else {
570
+ if (result.trace.sampleCount < 1 || result.trace.fetchCount < 1) failures.push('trace catch-up trace probe did not fetch samples');
571
+ if (result.trace.liveVersionCount < 1) failures.push('trace catch-up trace probe did not observe live snapshot version');
572
+ if (result.trace.maxAssistantOutputLength < 1) failures.push('trace catch-up trace probe did not observe assistant output');
573
+ }
574
+ }
575
+ }
576
+ if (result.eventSource && result.eventSource.requested) {
577
+ if (!result.eventSource.installed) failures.push('EventSource probe unavailable');
578
+ const selectedLiveStreams = Array.isArray(result.eventSource.streams) ? result.eventSource.streams.filter((stream) => stream.role === 'selected-live') : [];
579
+ const selectedLive = selectedLiveStreams.length > 1
580
+ ? selectedLiveStreams.reduce((total, stream) => ({
581
+ textEventCountAfterStart: total.textEventCountAfterStart + (stream.textEventCountAfterStart || 0),
582
+ reasoningEventCountAfterStart: total.reasoningEventCountAfterStart + (stream.reasoningEventCountAfterStart || 0),
583
+ liveReplayEventCountAfterStart: total.liveReplayEventCountAfterStart + (stream.liveReplayEventCountAfterStart || 0),
584
+ liveReplayMissedCountAfterStart: total.liveReplayMissedCountAfterStart + (stream.liveReplayMissedCountAfterStart || 0),
585
+ liveReplayDuplicateCountAfterStart: total.liveReplayDuplicateCountAfterStart + (stream.liveReplayDuplicateCountAfterStart || 0),
586
+ liveSinceValues: Array.from(new Set(total.liveSinceValues.concat(stream.liveSinceValues || []))),
587
+ }), { textEventCountAfterStart: 0, reasoningEventCountAfterStart: 0, liveReplayEventCountAfterStart: 0, liveReplayMissedCountAfterStart: 0, liveReplayDuplicateCountAfterStart: 0, liveSinceValues: [] })
588
+ : selectedLiveStreams[0];
589
+ if (!selectedLive) failures.push('EventSource selected-live stream was not observed');
590
+ if (!traceCatchupRequested && selectedLive && expectedDeltas !== undefined && selectedLive.textEventCountAfterStart < expectedDeltas) failures.push('selected-live text events after start ' + selectedLive.textEventCountAfterStart + ' < fixture deltas ' + expectedDeltas);
591
+ if (!traceCatchupRequested && selectedLive && expectedReasoningDeltas !== undefined && selectedLive.reasoningEventCountAfterStart < expectedReasoningDeltas) failures.push('selected-live reasoning events after start ' + selectedLive.reasoningEventCountAfterStart + ' < fixture reasoning deltas ' + expectedReasoningDeltas);
592
+ if (traceCatchupRequested) {
593
+ if (selectedLive && selectedLive.textEventCountAfterStart > Math.max(1, (expectedDeltas || 0) - 2)) failures.push('trace catch-up selected-live text was not suppressed');
594
+ } else {
595
+ if (reconnectRequested && result.eventSource.forcedCloseCountAfterStart < 1) failures.push('EventSource forced close was not observed');
596
+ if (reconnectRequested && result.eventSource.openCountAfterStart < 1) failures.push('EventSource reconnect open was not observed');
597
+ if (reconnectRequested && selectedLive && (selectedLive.liveReplayMissedCountAfterStart || 0) > 0) failures.push('selected-live transient replay missed buffered events');
598
+ if (reconnectRequested && selectedLive && (selectedLive.liveReplayDuplicateCountAfterStart || 0) > 0) failures.push('selected-live transient replay duplicated already observed frames');
599
+ if (reconnectRequested && selectedLive && (selectedLive.liveSinceValues || []).length > 0 && (selectedLive.liveReplayEventCountAfterStart || 0) < 1) failures.push('selected-live transient replay cursor did not replay buffered events');
600
+ if (result.eventSource.transientIdCountAfterStart < 1) failures.push('EventSource transient live ids were not observed');
601
+ }
602
+ }
603
+ if (result.sse && result.sse.requested) {
604
+ if (!result.sse.installed) failures.push('SSE fetch probe unavailable');
605
+ if (result.sse.status && result.sse.status !== 200) failures.push('SSE fetch status ' + result.sse.status);
606
+ if (result.sse.headers && String(result.sse.headers['x-accel-buffering'] || '').toLowerCase() !== 'no') failures.push('SSE X-Accel-Buffering header is not no');
607
+ if (result.sse.errors && result.sse.errors.length) failures.push('SSE fetch errors: ' + result.sse.errors.slice(0, 2).join('; '));
608
+ if (!traceCatchupRequested && expectedDeltas !== undefined && result.sse.textEventCount < expectedDeltas) failures.push('SSE text events ' + result.sse.textEventCount + ' < fixture deltas ' + expectedDeltas);
609
+ if (!traceCatchupRequested && expectedReasoningDeltas !== undefined && result.sse.reasoningEventCount < expectedReasoningDeltas) failures.push('SSE reasoning events ' + result.sse.reasoningEventCount + ' < fixture reasoning deltas ' + expectedReasoningDeltas);
610
+ if (!traceCatchupRequested && expectedDeltas !== undefined && result.sse.transientIdCount < expectedDeltas) failures.push('SSE transient live ids ' + result.sse.transientIdCount + ' < fixture deltas ' + expectedDeltas);
611
+ const sseGapGate = Math.max(300, cadenceMs * 3);
612
+ const sseChunkGapP90 = result.sse.chunkGapsMs && typeof result.sse.chunkGapsMs.p90 === 'number' ? result.sse.chunkGapsMs.p90 : undefined;
613
+ const sseTextGapP90 = result.sse.textEventGapsMs && typeof result.sse.textEventGapsMs.p90 === 'number' ? result.sse.textEventGapsMs.p90 : undefined;
614
+ const sseTextPerChunkP90 = result.sse.textEventsPerChunk && typeof result.sse.textEventsPerChunk.p90 === 'number' ? result.sse.textEventsPerChunk.p90 : undefined;
615
+ if (!traceCatchupRequested && sseChunkGapP90 !== undefined && sseChunkGapP90 > sseGapGate) failures.push('SSE chunk p90 gap ' + sseChunkGapP90 + 'ms exceeds gate');
616
+ if (!traceCatchupRequested && sseTextGapP90 !== undefined && sseTextGapP90 > sseGapGate) failures.push('SSE text p90 gap ' + sseTextGapP90 + 'ms exceeds gate');
617
+ if (!traceCatchupRequested && sseTextPerChunkP90 !== undefined && sseTextPerChunkP90 > 2) failures.push('SSE text events per chunk p90 ' + sseTextPerChunkP90 + ' exceeds gate');
618
+ }
619
+ if (longTaskMax > 50) failures.push('long task max ' + Math.round(longTaskMax * 1000) / 1000 + 'ms exceeds 50ms');
620
+ return failures;
621
+ }
622
+ function assistantTargets() {
623
+ return Array.from(document.querySelectorAll(ASSISTANT_SELECTOR));
624
+ }
625
+ function selectedAssistantText(initialTargets, ignorePreludeTargets) {
626
+ const targets = assistantTargets();
627
+ const texts = [];
628
+ for (const target of targets) {
629
+ if (initialTargets && initialTargets.has(target)) continue;
630
+ const text = target.innerText || target.textContent || '';
631
+ if (ignorePreludeTargets && /\bprelude\b/i.test(text)) continue;
632
+ texts.push(text);
633
+ }
634
+ return texts.join('\n');
635
+ }
636
+ async function waitForAssistantDomSettle(timeoutMs) {
637
+ const deadline = performance.now() + timeoutMs;
638
+ let lastText = selectedAssistantText();
639
+ let stableSamples = 0;
640
+ while (performance.now() < deadline) {
641
+ await new Promise((resolve) => setTimeout(resolve, 100));
642
+ const text = selectedAssistantText();
643
+ if (text === lastText) {
644
+ stableSamples += 1;
645
+ if (stableSamples >= 5) return;
646
+ } else {
647
+ stableSamples = 0;
648
+ lastText = text;
649
+ }
650
+ }
651
+ }
652
+ async function runStreamingBenchmark(options) {
653
+ const warnings = [];
654
+ const selectedSessionId = () => document.querySelector('[data-pibo-debug="chat-shell"]')?.getAttribute('data-pibo-session-id')
655
+ || document.querySelector('[data-pibo-selected-session-id]')?.getAttribute('data-pibo-selected-session-id')
656
+ || undefined;
657
+ let reset = false;
658
+ let backendPreludeError;
659
+ let backendPreludeConfig;
660
+ try { localStorage.setItem('pibo.chat.debugStreaming', '1'); } catch (error) { warnings.push('failed to set debugStreaming localStorage: ' + String(error)); }
661
+ if (options.startBackendFixture && options.fixturePreludeMessages > 0) {
662
+ const piboSessionId = selectedSessionId();
663
+ if (!piboSessionId) {
664
+ backendPreludeError = 'selected Chat session not found in DOM';
665
+ warnings.push('backend streaming fixture prelude was requested but selected Chat session was not found');
666
+ } else {
667
+ try {
668
+ const response = await fetchWithTimeout('/api/chat/debug/streaming-fixture', {
669
+ method: 'POST',
670
+ headers: { 'content-type': 'application/json' },
671
+ body: JSON.stringify({ piboSessionId, preludeOnly: true, preludeMessages: options.fixturePreludeMessages }),
672
+ }, 10000);
673
+ const payload = await response.json().catch(() => ({}));
674
+ if (!response.ok) throw new Error(payload && payload.error ? payload.error : response.status + ' ' + response.statusText);
675
+ backendPreludeConfig = payload.fixture || payload;
676
+ await new Promise((resolve) => setTimeout(resolve, Math.min(8000, Math.max(1000, options.fixturePreludeMessages * 5))));
677
+ await waitForAssistantDomSettle(Math.min(8000, Math.max(1000, options.fixturePreludeMessages * 5)));
678
+ } catch (error) {
679
+ backendPreludeError = String(error && error.message ? error.message : error);
680
+ warnings.push('failed to start backend streaming fixture prelude: ' + backendPreludeError);
681
+ }
682
+ }
683
+ }
684
+ const fixtureDomInitialTargets = options.startBackendFixture ? new WeakSet(assistantTargets()) : undefined;
685
+ const ignorePreludeDomTargets = Boolean(options.startBackendFixture && options.fixturePreludeMessages > 0);
686
+ const startedAt = performance.now();
687
+ const debugStateBeforeReset = cloneDebugSnapshot(window.__piboStreamingDebug);
688
+ if (typeof window.__piboStreamingDebugReset === 'function') {
689
+ try { window.__piboStreamingDebugReset(); reset = true; } catch (error) { warnings.push('failed to reset __piboStreamingDebug: ' + String(error)); }
690
+ }
691
+ const overlayDrop = installOverlayDropSimulation(Boolean(options.simulateOverlayDrop));
692
+
693
+ const debugBefore = cloneDebugSnapshot(window.__piboStreamingDebug);
694
+ const initialText = selectedAssistantText(fixtureDomInitialTargets, ignorePreludeDomTargets);
695
+ const targetCountStart = assistantTargets().length;
696
+ const updates = [];
697
+ const positiveJumps = [];
698
+ let currentLength = initialText.length;
699
+ let maxLength = initialText.length;
700
+ let lastPositiveAt;
701
+ let firstPositiveUpdateMs;
702
+ const sample = () => {
703
+ const text = selectedAssistantText(fixtureDomInitialTargets, ignorePreludeDomTargets);
704
+ const length = text.length;
705
+ if (length === currentLength) return;
706
+ maxLength = Math.max(maxLength, length);
707
+ const t = performance.now() - startedAt;
708
+ const delta = length - currentLength;
709
+ updates.push({ t, length, delta });
710
+ if (delta > 0) {
711
+ positiveJumps.push(delta);
712
+ firstPositiveUpdateMs ??= t;
713
+ lastPositiveAt = t;
714
+ }
715
+ currentLength = length;
716
+ };
717
+ const observer = new MutationObserver(sample);
718
+ observer.observe(document.body, { childList: true, subtree: true, characterData: true });
719
+
720
+ const rafGaps = [];
721
+ let rafCount = 0;
722
+ let lastRaf;
723
+ let rafHandle;
724
+ const onRaf = (t) => {
725
+ rafCount += 1;
726
+ if (lastRaf !== undefined) rafGaps.push(t - lastRaf);
727
+ lastRaf = t;
728
+ rafHandle = requestAnimationFrame(onRaf);
729
+ };
730
+ rafHandle = requestAnimationFrame(onRaf);
731
+
732
+ const longTasks = [];
733
+ let perfObserver;
734
+ if (typeof PerformanceObserver !== 'undefined') {
735
+ try {
736
+ perfObserver = new PerformanceObserver((list) => {
737
+ for (const entry of list.getEntries()) longTasks.push(entry.duration || 0);
738
+ });
739
+ perfObserver.observe({ entryTypes: ['longtask'] });
740
+ } catch {
741
+ warnings.push('longtask PerformanceObserver unavailable');
742
+ }
743
+ } else {
744
+ warnings.push('PerformanceObserver unavailable');
745
+ }
746
+
747
+ let fixtureStarted = false;
748
+ let fixtureConfig;
749
+ let backendFixtureError;
750
+ let traceProbe;
751
+ let sseProbe;
752
+ if (options.startFixture) {
753
+ if (typeof window.__piboStreamingFixtureStart === 'function') {
754
+ try { fixtureConfig = window.__piboStreamingFixtureStart(); fixtureStarted = true; } catch (error) { warnings.push('failed to start streaming fixture: ' + String(error)); }
755
+ } else {
756
+ warnings.push('streaming fixture was requested but window.__piboStreamingFixtureStart is unavailable');
757
+ }
758
+ } else if (options.startBackendFixture) {
759
+ if (options.simulateReconnect && typeof window.__piboStreamingBenchmarkForceReconnect === 'function') {
760
+ setTimeout(() => {
761
+ try { window.__piboStreamingBenchmarkForceReconnect(); } catch (error) { warnings.push('failed to force EventSource reconnect: ' + String(error)); }
762
+ }, options.reconnectAtMs || 325);
763
+ } else if (options.simulateReconnect) {
764
+ warnings.push('EventSource reconnect simulation was requested but the probe is unavailable');
765
+ }
766
+ if (options.simulateTraceCatchup && typeof window.__piboStreamingBenchmarkMarkTextDropRequested === 'function') {
767
+ try { window.__piboStreamingBenchmarkMarkTextDropRequested(options.traceCatchupDropMs || 1300); } catch (error) { warnings.push('failed to mark EventSource text drop request: ' + String(error)); }
768
+ } else if (options.simulateTraceCatchup) {
769
+ warnings.push('trace catch-up simulation was requested but the EventSource probe is unavailable');
770
+ }
771
+ const piboSessionId = selectedSessionId();
772
+ if (options.simulateTraceCatchup && piboSessionId) {
773
+ traceProbe = createTraceProbe(piboSessionId, startedAt, 250);
774
+ await traceProbe.sample();
775
+ }
776
+ if (!piboSessionId) {
777
+ backendFixtureError = 'selected Chat session not found in DOM';
778
+ warnings.push('backend streaming fixture was requested but selected Chat session was not found');
779
+ } else {
780
+ sseProbe = createSseProbe(piboSessionId, startedAt);
781
+ await waitForSseProbeReady(sseProbe.result, 500);
782
+ try {
783
+ const response = await fetchWithTimeout('/api/chat/debug/streaming-fixture', {
784
+ method: 'POST',
785
+ headers: { 'content-type': 'application/json' },
786
+ body: JSON.stringify({ piboSessionId, profile: options.fixtureProfile, mix: options.fixtureMix, ...((options.simulateReconnect || options.simulateTraceCatchup) ? { cadenceMs: 150 } : {}), ...(options.simulateTraceCatchup ? { traceSnapshots: true, suppressLiveDeltas: true } : {}) }),
787
+ }, options.simulateTraceCatchup ? 15000 : 5000);
788
+ const payload = await response.json().catch(() => ({}));
789
+ if (!response.ok) throw new Error(payload && payload.error ? payload.error : response.status + ' ' + response.statusText);
790
+ fixtureConfig = payload.fixture || payload;
791
+ fixtureStarted = true;
792
+ } catch (error) {
793
+ backendFixtureError = String(error && error.message ? error.message : error);
794
+ warnings.push('failed to start backend streaming fixture: ' + backendFixtureError);
795
+ }
796
+ }
797
+ }
798
+
799
+ await new Promise((resolve) => setTimeout(resolve, options.durationMs));
800
+ sample();
801
+ if (traceProbe) {
802
+ await traceProbe.sample();
803
+ traceProbe.stop();
804
+ }
805
+ const sseSummary = sseProbe ? await sseProbe.stop() : undefined;
806
+ observer.disconnect();
807
+ if (rafHandle !== undefined) cancelAnimationFrame(rafHandle);
808
+ try { perfObserver && perfObserver.disconnect(); } catch {}
809
+
810
+ const debugAfter = cloneDebugSnapshot(window.__piboStreamingDebug);
811
+ const overlayDropSummary = overlayDrop ? cloneDebugSnapshot(window.__piboStreamingBenchmarkOverlayDrop) : undefined;
812
+ installOverlayDropSimulation(false);
813
+ if (!debugAfter) warnings.push('window.__piboStreamingDebug was absent; run with ?debugStreaming=1 or start a fresh stream after this command enables localStorage');
814
+ const positiveUpdates = updates.filter((update) => update.delta > 0);
815
+ const positiveGaps = [];
816
+ for (let i = 1; i < positiveUpdates.length; i++) positiveGaps.push(positiveUpdates[i].t - positiveUpdates[i - 1].t);
817
+ const debugDelta = numericDelta(debugBefore, debugAfter, [
818
+ 'liveOpenCount',
819
+ 'liveErrorCount',
820
+ 'eventCount',
821
+ 'textDeltaCount',
822
+ 'textDeltaBytes',
823
+ 'reasoningDeltaCount',
824
+ 'reasoningDeltaBytes',
825
+ 'enqueueCount',
826
+ 'flushCount',
827
+ 'flushedEventCount',
828
+ 'overlayUpdateCount',
829
+ 'liveTraceComputeCount',
830
+ 'liveTraceComputeDurationMsTotal',
831
+ 'markdownRenderCount',
832
+ 'markdownRenderPlainCount',
833
+ 'markdownRenderFullCount',
834
+ 'markdownRenderCommonMarkCount',
835
+ 'markdownRenderGfmCount',
836
+ 'markdownRenderGfmFastCount',
837
+ 'markdownRenderDurationMsTotal',
838
+ 'markdownRenderCommonMarkDurationMsTotal',
839
+ 'markdownRenderGfmDurationMsTotal',
840
+ 'markdownRenderGfmFastDurationMsTotal',
841
+ 'traceRefreshStartedCount',
842
+ 'traceRefreshCompletedCount',
843
+ 'traceRefreshFailedCount',
844
+ 'traceBaseUpdateCount',
845
+ ]);
846
+ const domGaps = stats(positiveGaps);
847
+ const domJumps = stats(positiveJumps);
848
+ const fixtureScheduleMs = numberArray(fixtureConfig && fixtureConfig.scheduleMs);
849
+ const fixtureReasoningScheduleMs = numberArray(fixtureConfig && fixtureConfig.reasoningScheduleMs);
850
+ const fixtureSummary = (options.startFixture || options.startBackendFixture) ? {
851
+ requested: true,
852
+ mode: options.startBackendFixture ? 'backend' : 'browser',
853
+ profile: fixtureConfig && typeof fixtureConfig.profile === 'string' ? fixtureConfig.profile : options.fixtureProfile,
854
+ mix: fixtureConfig && typeof fixtureConfig.mix === 'string' ? fixtureConfig.mix : options.fixtureMix,
855
+ simulation: options.simulateTraceCatchup ? 'trace-catchup' : (options.simulateReconnect ? 'reconnect' : (options.simulateOverlayDrop ? 'overlay-drop' : undefined)),
856
+ available: options.startBackendFixture ? !backendFixtureError : typeof window.__piboStreamingFixtureStart === 'function',
857
+ started: fixtureStarted,
858
+ deltaCount: fixtureConfig && typeof fixtureConfig.deltaCount === 'number' ? fixtureConfig.deltaCount : undefined,
859
+ reasoningDeltaCount: fixtureConfig && typeof fixtureConfig.reasoningDeltaCount === 'number' ? fixtureConfig.reasoningDeltaCount : undefined,
860
+ cadenceMs: fixtureConfig && typeof fixtureConfig.cadenceMs === 'number' ? fixtureConfig.cadenceMs : undefined,
861
+ scheduleMs: fixtureScheduleMs.length ? fixtureScheduleMs : undefined,
862
+ scheduleGapsMs: fixtureScheduleMs.length ? stats(scheduleGaps(fixtureScheduleMs)) : undefined,
863
+ reasoningScheduleMs: fixtureReasoningScheduleMs.length ? fixtureReasoningScheduleMs : undefined,
864
+ reasoningScheduleGapsMs: fixtureReasoningScheduleMs.length ? stats(scheduleGaps(fixtureReasoningScheduleMs)) : undefined,
865
+ textBytes: fixtureConfig && typeof fixtureConfig.textBytes === 'number' ? fixtureConfig.textBytes : undefined,
866
+ reasoningBytes: fixtureConfig && typeof fixtureConfig.reasoningBytes === 'number' ? fixtureConfig.reasoningBytes : undefined,
867
+ piboSessionId: fixtureConfig && typeof fixtureConfig.piboSessionId === 'string' ? fixtureConfig.piboSessionId : undefined,
868
+ preludeMessages: backendPreludeConfig && typeof backendPreludeConfig.preludeMessages === 'number' ? backendPreludeConfig.preludeMessages : (options.fixturePreludeMessages || undefined),
869
+ error: backendPreludeError || backendFixtureError,
870
+ } : undefined;
871
+ const eventSourceSummary = summarizeEventSourceProbe(startedAt, Boolean(options.startBackendFixture), options.reconnectAtMs, Boolean(options.simulateTraceCatchup), options.traceCatchupDropMs);
872
+ const traceSummary = traceProbe && traceProbe.result;
873
+ const regressions = streamingBenchmarkRegressions({
874
+ debugAfter,
875
+ debugDelta,
876
+ fixture: fixtureSummary,
877
+ eventSource: eventSourceSummary,
878
+ sse: sseSummary,
879
+ trace: traceSummary,
880
+ dom: { lengthStart: initialText.length, lengthEnd: currentLength, lengthMax: maxLength, positiveUpdateCount: positiveUpdates.length, gapsMs: domGaps, positiveCharJumps: domJumps, firstPositiveUpdateMs },
881
+ longTasks,
882
+ });
883
+ return {
884
+ kind: 'streaming-benchmark',
885
+ createdAt: nowIso(),
886
+ url: location.href,
887
+ title: document.title,
888
+ durationMs: options.durationMs,
889
+ debug: {
890
+ enabledRequested: true,
891
+ available: Boolean(debugAfter),
892
+ reset,
893
+ before: debugBefore,
894
+ stateBeforeReset: debugStateBeforeReset,
895
+ after: debugAfter,
896
+ delta: debugDelta,
897
+ },
898
+ dom: {
899
+ selector: ASSISTANT_SELECTOR,
900
+ targetCountStart,
901
+ targetCountEnd: assistantTargets().length,
902
+ lengthStart: initialText.length,
903
+ lengthEnd: currentLength,
904
+ lengthMax: maxLength,
905
+ updateCount: updates.length,
906
+ positiveUpdateCount: positiveUpdates.length,
907
+ firstPositiveUpdateMs: firstPositiveUpdateMs === undefined ? undefined : Math.round(firstPositiveUpdateMs),
908
+ lastPositiveUpdateMs: lastPositiveAt === undefined ? undefined : Math.round(lastPositiveAt),
909
+ gapsMs: domGaps,
910
+ positiveCharJumps: domJumps,
911
+ },
912
+ raf: { count: rafCount, gapsMs: stats(rafGaps) },
913
+ longTasks: {
914
+ count: longTasks.length,
915
+ totalMs: Math.round(longTasks.reduce((sum, value) => sum + value, 0) * 1000) / 1000,
916
+ maxMs: Math.round((longTasks.length ? Math.max(...longTasks) : 0) * 1000) / 1000,
917
+ },
918
+ fixture: fixtureSummary,
919
+ eventSource: eventSourceSummary,
920
+ sse: sseSummary,
921
+ trace: traceSummary,
922
+ overlayDrop: overlayDropSummary,
923
+ regressions,
924
+ warnings,
925
+ };
926
+ }
927
+ `;
928
+ }