pi-agent-browser-native 0.9.2 → 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (392) hide show
  1. package/CHANGELOG.md +91 -5
  2. package/README.md +120 -86
  3. package/dist/extensions/agent-browser/index.js +43065 -2016
  4. package/dist/extensions/agent-browser/lib/argv-descriptor.js +49 -26
  5. package/dist/extensions/agent-browser/lib/argv-grammar.js +82 -93
  6. package/dist/extensions/agent-browser/lib/bash-guard.js +129 -126
  7. package/dist/extensions/agent-browser/lib/batch-lifecycle.js +113 -49
  8. package/dist/extensions/agent-browser/lib/browser-execution-claim-codec.js +61 -0
  9. package/dist/extensions/agent-browser/lib/browser-execution-claim-storage.js +232 -0
  10. package/dist/extensions/agent-browser/lib/browser-execution-claims.js +202 -0
  11. package/dist/extensions/agent-browser/lib/browser-execution-identity.js +77 -0
  12. package/dist/extensions/agent-browser/lib/browser-journal-branch.js +98 -0
  13. package/dist/extensions/agent-browser/lib/browser-journal-contracts.js +1 -0
  14. package/dist/extensions/agent-browser/lib/browser-journal-projection.js +221 -0
  15. package/dist/extensions/agent-browser/lib/browser-journal-reader.js +89 -0
  16. package/dist/extensions/agent-browser/lib/browser-journal-replay.js +246 -0
  17. package/dist/extensions/agent-browser/lib/browser-journal.js +103 -394
  18. package/dist/extensions/agent-browser/lib/browser-legacy-pages.js +220 -0
  19. package/dist/extensions/agent-browser/lib/browser-legacy-projection.js +282 -0
  20. package/dist/extensions/agent-browser/lib/browser-legacy-types.js +1 -0
  21. package/dist/extensions/agent-browser/lib/browser-session-conversion-stream.js +217 -0
  22. package/dist/extensions/agent-browser/lib/browser-session-conversion.js +80 -335
  23. package/dist/extensions/agent-browser/lib/browser-transcript-contracts.js +35 -0
  24. package/dist/extensions/agent-browser/lib/browser-transcript-validation.js +166 -0
  25. package/dist/extensions/agent-browser/lib/browser-transcript.js +137 -81
  26. package/dist/extensions/agent-browser/lib/browser-value-parsing.js +15 -0
  27. package/dist/extensions/agent-browser/lib/command-capabilities.js +340 -0
  28. package/dist/extensions/agent-browser/lib/command-policy.js +107 -88
  29. package/dist/extensions/agent-browser/lib/command-taxonomy.js +49 -322
  30. package/dist/extensions/agent-browser/lib/config-policy.js +138 -343
  31. package/dist/extensions/agent-browser/lib/config-providers.js +71 -0
  32. package/dist/extensions/agent-browser/lib/config-validation.js +218 -0
  33. package/dist/extensions/agent-browser/lib/config.js +19 -7
  34. package/dist/extensions/agent-browser/lib/electron/cdp.js +15 -7
  35. package/dist/extensions/agent-browser/lib/electron/cleanup.js +134 -55
  36. package/dist/extensions/agent-browser/lib/electron/discovery-darwin.js +109 -0
  37. package/dist/extensions/agent-browser/lib/electron/discovery-desktop.js +136 -0
  38. package/dist/extensions/agent-browser/lib/electron/discovery-evidence.js +89 -0
  39. package/dist/extensions/agent-browser/lib/electron/discovery-linux.js +93 -0
  40. package/dist/extensions/agent-browser/lib/electron/discovery-packages.js +162 -0
  41. package/dist/extensions/agent-browser/lib/electron/discovery-types.js +2 -0
  42. package/dist/extensions/agent-browser/lib/electron/discovery.js +140 -549
  43. package/dist/extensions/agent-browser/lib/electron/launch-monitor.js +102 -0
  44. package/dist/extensions/agent-browser/lib/electron/launch-process.js +209 -0
  45. package/dist/extensions/agent-browser/lib/electron/launch-types.js +2 -0
  46. package/dist/extensions/agent-browser/lib/electron/launch.js +249 -354
  47. package/dist/extensions/agent-browser/lib/executable-path.js +21 -12
  48. package/dist/extensions/agent-browser/lib/execution-cwd.js +35 -18
  49. package/dist/extensions/agent-browser/lib/input-modes/electron.js +162 -121
  50. package/dist/extensions/agent-browser/lib/input-modes/job.js +116 -313
  51. package/dist/extensions/agent-browser/lib/input-modes/lookup-network-evidence.js +104 -0
  52. package/dist/extensions/agent-browser/lib/input-modes/lookup-plan.js +132 -0
  53. package/dist/extensions/agent-browser/lib/input-modes/lookup-redaction.js +57 -0
  54. package/dist/extensions/agent-browser/lib/input-modes/lookup-source-evidence.js +151 -0
  55. package/dist/extensions/agent-browser/lib/input-modes/lookup-workspace.js +142 -0
  56. package/dist/extensions/agent-browser/lib/input-modes/lookups.js +57 -412
  57. package/dist/extensions/agent-browser/lib/input-modes/params.js +63 -17
  58. package/dist/extensions/agent-browser/lib/input-modes/qa-analysis.js +268 -0
  59. package/dist/extensions/agent-browser/lib/input-modes/qa-presentation.js +117 -0
  60. package/dist/extensions/agent-browser/lib/input-modes/script-child.js +396 -0
  61. package/dist/extensions/agent-browser/lib/input-modes/script-protocol.js +86 -0
  62. package/dist/extensions/agent-browser/lib/input-modes/script-types.js +1 -0
  63. package/dist/extensions/agent-browser/lib/input-modes/script-validation.js +60 -0
  64. package/dist/extensions/agent-browser/lib/input-modes/script.js +60 -409
  65. package/dist/extensions/agent-browser/lib/input-modes/semantic-action.js +218 -128
  66. package/dist/extensions/agent-browser/lib/input-modes/shared.js +15 -4
  67. package/dist/extensions/agent-browser/lib/input-modes/types.js +56 -7
  68. package/dist/extensions/agent-browser/lib/json-schema.js +22 -10
  69. package/dist/extensions/agent-browser/lib/launch-scoped-flags.js +17 -5
  70. package/dist/extensions/agent-browser/lib/managed-session-policy-lock.js +92 -425
  71. package/dist/extensions/agent-browser/lib/managed-session-posix-storage.js +58 -0
  72. package/dist/extensions/agent-browser/lib/managed-session-project-identity.js +244 -0
  73. package/dist/extensions/agent-browser/lib/managed-session-restore-context.js +84 -0
  74. package/dist/extensions/agent-browser/lib/managed-session-restore-policy.js +119 -0
  75. package/dist/extensions/agent-browser/lib/managed-session-restore-state.js +83 -0
  76. package/dist/extensions/agent-browser/lib/managed-session-restore.js +168 -300
  77. package/dist/extensions/agent-browser/lib/managed-session-snapshot-records.js +277 -0
  78. package/dist/extensions/agent-browser/lib/managed-session-snapshots.js +128 -305
  79. package/dist/extensions/agent-browser/lib/managed-session-storage.js +56 -253
  80. package/dist/extensions/agent-browser/lib/native-confirmation.js +140 -0
  81. package/dist/extensions/agent-browser/lib/native-output.js +44 -9
  82. package/dist/extensions/agent-browser/lib/orchestration/batch-stdin.js +107 -66
  83. package/dist/extensions/agent-browser/lib/orchestration/browser-run/artifact-merge.js +14 -6
  84. package/dist/extensions/agent-browser/lib/orchestration/browser-run/artifact-paths.js +109 -57
  85. package/dist/extensions/agent-browser/lib/orchestration/browser-run/browser-observation-result.js +82 -0
  86. package/dist/extensions/agent-browser/lib/orchestration/browser-run/click-dispatch.js +171 -57
  87. package/dist/extensions/agent-browser/lib/orchestration/browser-run/diagnostic-values.js +31 -0
  88. package/dist/extensions/agent-browser/lib/orchestration/browser-run/diagnostics.js +152 -781
  89. package/dist/extensions/agent-browser/lib/orchestration/browser-run/electron-observation.js +202 -0
  90. package/dist/extensions/agent-browser/lib/orchestration/browser-run/electron-text-diagnostics.js +109 -0
  91. package/dist/extensions/agent-browser/lib/orchestration/browser-run/fill-diagnostics.js +119 -0
  92. package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-action-recovery.js +147 -0
  93. package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-actions.js +144 -0
  94. package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-content.js +123 -0
  95. package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-contracts.js +1 -0
  96. package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-details.js +156 -0
  97. package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-electron.js +179 -0
  98. package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-evidence.js +39 -0
  99. package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-missing-binary.js +89 -0
  100. package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-recovery.js +97 -0
  101. package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-redaction.js +106 -0
  102. package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-timeout.js +110 -0
  103. package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result.js +41 -538
  104. package/dist/extensions/agent-browser/lib/orchestration/browser-run/index.js +204 -108
  105. package/dist/extensions/agent-browser/lib/orchestration/browser-run/interaction-diagnostics.js +290 -0
  106. package/dist/extensions/agent-browser/lib/orchestration/browser-run/managed-session-close.js +167 -0
  107. package/dist/extensions/agent-browser/lib/orchestration/browser-run/managed-session-daemon-inspection.js +108 -0
  108. package/dist/extensions/agent-browser/lib/orchestration/browser-run/managed-session-daemon-policy.js +127 -199
  109. package/dist/extensions/agent-browser/lib/orchestration/browser-run/native-helper-observation.js +65 -0
  110. package/dist/extensions/agent-browser/lib/orchestration/browser-run/observation-types.js +1 -0
  111. package/dist/extensions/agent-browser/lib/orchestration/browser-run/overlay-diagnostics.js +120 -0
  112. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare/network-page-filter.js +113 -30
  113. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare/scroll-shims.js +109 -28
  114. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare/snapshot-filter-data.js +150 -0
  115. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare/snapshot-filter.js +138 -253
  116. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare/snapshot-rendered-text.js +147 -0
  117. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare/wait-timeouts.js +59 -24
  118. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-artifacts.js +159 -0
  119. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-command.js +131 -0
  120. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-contracts.js +1 -0
  121. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-daemon.js +93 -0
  122. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-failure.js +42 -0
  123. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-guards.js +242 -0
  124. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-input.js +75 -0
  125. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-observations.js +92 -0
  126. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-page-selection.js +254 -0
  127. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-page-state.js +121 -0
  128. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-refs.js +130 -0
  129. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-resources.js +114 -0
  130. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-semantic.js +121 -0
  131. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-session-plan.js +222 -0
  132. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-timeouts.js +68 -0
  133. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare.js +176 -1114
  134. package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-analysis.js +191 -0
  135. package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-confirmation.js +152 -0
  136. package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-diagnostics.js +182 -0
  137. package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-electron.js +150 -0
  138. package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-lifecycle-contracts.js +1 -0
  139. package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-lifecycle-phase-contracts.js +1 -0
  140. package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-lifecycle-phase.js +115 -0
  141. package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-lifecycle.js +256 -0
  142. package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-managed-contracts.js +1 -0
  143. package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-managed.js +256 -0
  144. package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-native-phase-contracts.js +1 -0
  145. package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-native-phase.js +93 -0
  146. package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-native.js +113 -0
  147. package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-navigation-contracts.js +1 -0
  148. package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-navigation.js +316 -0
  149. package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-ownership.js +28 -0
  150. package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-page-phase-contracts.js +1 -0
  151. package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-page-phase.js +142 -0
  152. package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-presentation-contracts.js +1 -0
  153. package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-presentation.js +333 -0
  154. package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-publication-phase-contracts.js +1 -0
  155. package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-publication-phase.js +71 -0
  156. package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-publication.js +201 -0
  157. package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-receipts.js +183 -0
  158. package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-refs.js +200 -0
  159. package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-tabs.js +142 -0
  160. package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output.js +18 -910
  161. package/dist/extensions/agent-browser/lib/orchestration/browser-run/prompt-guards.js +23 -13
  162. package/dist/extensions/agent-browser/lib/orchestration/browser-run/recording-receipt-reconciliation.js +198 -0
  163. package/dist/extensions/agent-browser/lib/orchestration/browser-run/recording-recovery-contracts.js +1 -0
  164. package/dist/extensions/agent-browser/lib/orchestration/browser-run/recording-recovery-presentation.js +154 -0
  165. package/dist/extensions/agent-browser/lib/orchestration/browser-run/recording-recovery.js +68 -151
  166. package/dist/extensions/agent-browser/lib/orchestration/browser-run/screenshot-capture.js +14 -0
  167. package/dist/extensions/agent-browser/lib/orchestration/browser-run/screenshot-observation.js +169 -46
  168. package/dist/extensions/agent-browser/lib/orchestration/browser-run/session-state-commands.js +130 -0
  169. package/dist/extensions/agent-browser/lib/orchestration/browser-run/session-state-electron.js +210 -0
  170. package/dist/extensions/agent-browser/lib/orchestration/browser-run/session-state-observations.js +61 -0
  171. package/dist/extensions/agent-browser/lib/orchestration/browser-run/session-state-outcomes.js +187 -0
  172. package/dist/extensions/agent-browser/lib/orchestration/browser-run/session-state-refs.js +171 -0
  173. package/dist/extensions/agent-browser/lib/orchestration/browser-run/session-state-tabs.js +228 -0
  174. package/dist/extensions/agent-browser/lib/orchestration/browser-run/session-state.js +77 -753
  175. package/dist/extensions/agent-browser/lib/orchestration/browser-run/text-visibility-diagnostics.js +182 -0
  176. package/dist/extensions/agent-browser/lib/orchestration/browser-run/timeout-diagnostics.js +256 -0
  177. package/dist/extensions/agent-browser/lib/orchestration/browser-run/timeout-progress.js +108 -0
  178. package/dist/extensions/agent-browser/lib/orchestration/code-artifact-observation.js +39 -0
  179. package/dist/extensions/agent-browser/lib/orchestration/code-image-observation.js +119 -0
  180. package/dist/extensions/agent-browser/lib/orchestration/electron-host/branch.js +92 -0
  181. package/dist/extensions/agent-browser/lib/orchestration/electron-host/cleanup-result.js +58 -0
  182. package/dist/extensions/agent-browser/lib/orchestration/electron-host/cleanup.js +78 -0
  183. package/dist/extensions/agent-browser/lib/orchestration/electron-host/contracts.js +1 -0
  184. package/dist/extensions/agent-browser/lib/orchestration/electron-host/discovery.js +106 -0
  185. package/dist/extensions/agent-browser/lib/orchestration/electron-host/index.js +48 -816
  186. package/dist/extensions/agent-browser/lib/orchestration/electron-host/policy.js +86 -0
  187. package/dist/extensions/agent-browser/lib/orchestration/electron-host/probe-collection.js +69 -0
  188. package/dist/extensions/agent-browser/lib/orchestration/electron-host/probe-data.js +167 -0
  189. package/dist/extensions/agent-browser/lib/orchestration/electron-host/probe-presentation.js +164 -0
  190. package/dist/extensions/agent-browser/lib/orchestration/electron-host/probe.js +161 -0
  191. package/dist/extensions/agent-browser/lib/orchestration/electron-host/status.js +165 -0
  192. package/dist/extensions/agent-browser/lib/orchestration/execution-queue.js +21 -9
  193. package/dist/extensions/agent-browser/lib/orchestration/extension-artifact-preflight.js +211 -0
  194. package/dist/extensions/agent-browser/lib/orchestration/extension-artifacts.js +23 -0
  195. package/dist/extensions/agent-browser/lib/orchestration/extension-attachment-replay.js +99 -0
  196. package/dist/extensions/agent-browser/lib/orchestration/extension-branch-restore.js +275 -0
  197. package/dist/extensions/agent-browser/lib/orchestration/extension-code.js +280 -0
  198. package/dist/extensions/agent-browser/lib/orchestration/extension-command-admission.js +303 -0
  199. package/dist/extensions/agent-browser/lib/orchestration/extension-command-output.js +36 -0
  200. package/dist/extensions/agent-browser/lib/orchestration/extension-command-result.js +335 -0
  201. package/dist/extensions/agent-browser/lib/orchestration/extension-command-run.js +227 -0
  202. package/dist/extensions/agent-browser/lib/orchestration/extension-command-state.js +1 -0
  203. package/dist/extensions/agent-browser/lib/orchestration/extension-electron-ownership.js +204 -0
  204. package/dist/extensions/agent-browser/lib/orchestration/extension-execution-locks.js +139 -0
  205. package/dist/extensions/agent-browser/lib/orchestration/extension-execution-queue.js +24 -0
  206. package/dist/extensions/agent-browser/lib/orchestration/extension-host-coordination.js +98 -0
  207. package/dist/extensions/agent-browser/lib/orchestration/extension-host-run.js +295 -0
  208. package/dist/extensions/agent-browser/lib/orchestration/extension-intent-replay.js +41 -0
  209. package/dist/extensions/agent-browser/lib/orchestration/extension-invocation.js +7 -0
  210. package/dist/extensions/agent-browser/lib/orchestration/extension-lifecycle.js +102 -0
  211. package/dist/extensions/agent-browser/lib/orchestration/extension-managed-ownership.js +133 -0
  212. package/dist/extensions/agent-browser/lib/orchestration/extension-observation.js +120 -0
  213. package/dist/extensions/agent-browser/lib/orchestration/extension-prompt.js +180 -0
  214. package/dist/extensions/agent-browser/lib/orchestration/extension-recording.js +290 -0
  215. package/dist/extensions/agent-browser/lib/orchestration/extension-resource-contracts.js +1 -0
  216. package/dist/extensions/agent-browser/lib/orchestration/extension-resource-replay.js +269 -0
  217. package/dist/extensions/agent-browser/lib/orchestration/extension-result-state.js +113 -0
  218. package/dist/extensions/agent-browser/lib/orchestration/extension-runtime.js +146 -0
  219. package/dist/extensions/agent-browser/lib/orchestration/extension-script-leases.js +58 -0
  220. package/dist/extensions/agent-browser/lib/orchestration/extension-tool-boundary.js +62 -0
  221. package/dist/extensions/agent-browser/lib/orchestration/extension-version-check.js +54 -0
  222. package/dist/extensions/agent-browser/lib/orchestration/input-plan-types.js +1 -0
  223. package/dist/extensions/agent-browser/lib/orchestration/input-plan.js +261 -185
  224. package/dist/extensions/agent-browser/lib/orchestration/input-redaction.js +62 -0
  225. package/dist/extensions/agent-browser/lib/orchestration/native-config.js +144 -0
  226. package/dist/extensions/agent-browser/lib/orchestration/native-root-launch.js +77 -0
  227. package/dist/extensions/agent-browser/lib/orchestration/native-session-defaults.js +210 -139
  228. package/dist/extensions/agent-browser/lib/orchestration/operation-paths.js +124 -58
  229. package/dist/extensions/agent-browser/lib/orchestration/output-file.js +198 -98
  230. package/dist/extensions/agent-browser/lib/orchestration/script-mode.js +199 -96
  231. package/dist/extensions/agent-browser/lib/owned-managed-session-context.js +55 -0
  232. package/dist/extensions/agent-browser/lib/page-target-batch.js +118 -0
  233. package/dist/extensions/agent-browser/lib/page-target-guards.js +50 -0
  234. package/dist/extensions/agent-browser/lib/page-target-navigation.js +104 -0
  235. package/dist/extensions/agent-browser/lib/page-target-validation.js +59 -243
  236. package/dist/extensions/agent-browser/lib/parsing.js +13 -4
  237. package/dist/extensions/agent-browser/lib/pi-tool-rendering.js +134 -68
  238. package/dist/extensions/agent-browser/lib/playbook.js +18 -14
  239. package/dist/extensions/agent-browser/lib/process-child.js +284 -0
  240. package/dist/extensions/agent-browser/lib/process-environment.js +22 -6
  241. package/dist/extensions/agent-browser/lib/process-errors.js +23 -0
  242. package/dist/extensions/agent-browser/lib/process-identity.js +47 -15
  243. package/dist/extensions/agent-browser/lib/process-socket-storage.js +256 -0
  244. package/dist/extensions/agent-browser/lib/process-stdout.js +74 -0
  245. package/dist/extensions/agent-browser/lib/process.js +146 -537
  246. package/dist/extensions/agent-browser/lib/prompt-artifacts.js +287 -0
  247. package/dist/extensions/agent-browser/lib/prompt-policy.js +15 -194
  248. package/dist/extensions/agent-browser/lib/read-command.js +41 -0
  249. package/dist/extensions/agent-browser/lib/read-confirmation.js +138 -35
  250. package/dist/extensions/agent-browser/lib/recording-reservations.js +118 -45
  251. package/dist/extensions/agent-browser/lib/redaction-fields.js +75 -0
  252. package/dist/extensions/agent-browser/lib/redaction-json.js +149 -0
  253. package/dist/extensions/agent-browser/lib/redaction-url.js +88 -0
  254. package/dist/extensions/agent-browser/lib/results/action-contracts.js +1 -0
  255. package/dist/extensions/agent-browser/lib/results/action-recommendations.js +28 -271
  256. package/dist/extensions/agent-browser/lib/results/artifact-contracts.js +1 -0
  257. package/dist/extensions/agent-browser/lib/results/artifact-manifest-validation.js +133 -0
  258. package/dist/extensions/agent-browser/lib/results/artifact-manifest.js +96 -94
  259. package/dist/extensions/agent-browser/lib/results/artifact-recommendations.js +73 -0
  260. package/dist/extensions/agent-browser/lib/results/categories.js +111 -54
  261. package/dist/extensions/agent-browser/lib/results/confirmation.js +29 -10
  262. package/dist/extensions/agent-browser/lib/results/editable-ref-evidence.js +62 -27
  263. package/dist/extensions/agent-browser/lib/results/electron-recommendations.js +83 -0
  264. package/dist/extensions/agent-browser/lib/results/envelope-decoding.js +48 -0
  265. package/dist/extensions/agent-browser/lib/results/envelope.js +93 -66
  266. package/dist/extensions/agent-browser/lib/results/evidence-contracts.js +1 -0
  267. package/dist/extensions/agent-browser/lib/results/failure-recommendations.js +180 -0
  268. package/dist/extensions/agent-browser/lib/results/network-routes.js +86 -45
  269. package/dist/extensions/agent-browser/lib/results/network.js +35 -12
  270. package/dist/extensions/agent-browser/lib/results/next-actions.js +49 -19
  271. package/dist/extensions/agent-browser/lib/results/presentation/artifact-files.js +320 -0
  272. package/dist/extensions/agent-browser/lib/results/presentation/artifact-format.js +138 -0
  273. package/dist/extensions/agent-browser/lib/results/presentation/artifact-images.js +113 -0
  274. package/dist/extensions/agent-browser/lib/results/presentation/artifact-verification.js +145 -0
  275. package/dist/extensions/agent-browser/lib/results/presentation/artifacts.js +99 -552
  276. package/dist/extensions/agent-browser/lib/results/presentation/batch-contracts.js +1 -0
  277. package/dist/extensions/agent-browser/lib/results/presentation/batch-recording.js +118 -0
  278. package/dist/extensions/agent-browser/lib/results/presentation/batch-redaction.js +68 -0
  279. package/dist/extensions/agent-browser/lib/results/presentation/batch-rendering.js +135 -0
  280. package/dist/extensions/agent-browser/lib/results/presentation/batch-step.js +227 -0
  281. package/dist/extensions/agent-browser/lib/results/presentation/batch-summary.js +91 -0
  282. package/dist/extensions/agent-browser/lib/results/presentation/batch.js +91 -460
  283. package/dist/extensions/agent-browser/lib/results/presentation/browser-profile-recovery.js +9 -5
  284. package/dist/extensions/agent-browser/lib/results/presentation/command-presenters.js +216 -0
  285. package/dist/extensions/agent-browser/lib/results/presentation/common.js +26 -9
  286. package/dist/extensions/agent-browser/lib/results/presentation/content.js +86 -29
  287. package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-a11y.js +67 -0
  288. package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-health.js +79 -0
  289. package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-identity.js +199 -0
  290. package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-logs.js +75 -0
  291. package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-network-actions.js +216 -0
  292. package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-network.js +124 -0
  293. package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-redaction.js +64 -0
  294. package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-storage.js +209 -0
  295. package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-stream.js +69 -0
  296. package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-summary.js +222 -0
  297. package/dist/extensions/agent-browser/lib/results/presentation/diagnostics.js +103 -1019
  298. package/dist/extensions/agent-browser/lib/results/presentation/early-result.js +70 -0
  299. package/dist/extensions/agent-browser/lib/results/presentation/errors.js +130 -60
  300. package/dist/extensions/agent-browser/lib/results/presentation/input-contracts.js +1 -0
  301. package/dist/extensions/agent-browser/lib/results/presentation/large-output.js +60 -145
  302. package/dist/extensions/agent-browser/lib/results/presentation/navigation.js +147 -88
  303. package/dist/extensions/agent-browser/lib/results/presentation/notices.js +75 -0
  304. package/dist/extensions/agent-browser/lib/results/presentation/observation-contracts.js +1 -0
  305. package/dist/extensions/agent-browser/lib/results/presentation/observation-rendering.js +127 -0
  306. package/dist/extensions/agent-browser/lib/results/presentation/outcomes.js +120 -0
  307. package/dist/extensions/agent-browser/lib/results/presentation/output-completion.js +77 -0
  308. package/dist/extensions/agent-browser/lib/results/presentation/output-spill.js +51 -0
  309. package/dist/extensions/agent-browser/lib/results/presentation/registry.js +117 -237
  310. package/dist/extensions/agent-browser/lib/results/presentation/semantic-action.js +35 -21
  311. package/dist/extensions/agent-browser/lib/results/presentation/skills.js +104 -73
  312. package/dist/extensions/agent-browser/lib/results/presentation/source.js +109 -0
  313. package/dist/extensions/agent-browser/lib/results/presentation.js +17 -248
  314. package/dist/extensions/agent-browser/lib/results/recommendation-contracts.js +1 -0
  315. package/dist/extensions/agent-browser/lib/results/recording.js +52 -14
  316. package/dist/extensions/agent-browser/lib/results/recovery-actions.js +14 -5
  317. package/dist/extensions/agent-browser/lib/results/recovery-next-actions.js +30 -22
  318. package/dist/extensions/agent-browser/lib/results/selector-recovery-target.js +83 -0
  319. package/dist/extensions/agent-browser/lib/results/selector-recovery.js +123 -123
  320. package/dist/extensions/agent-browser/lib/results/snapshot-compact.js +266 -0
  321. package/dist/extensions/agent-browser/lib/results/snapshot-content.js +32 -0
  322. package/dist/extensions/agent-browser/lib/results/snapshot-high-value-controls.js +104 -71
  323. package/dist/extensions/agent-browser/lib/results/snapshot-refs.js +31 -11
  324. package/dist/extensions/agent-browser/lib/results/snapshot-segments.js +125 -66
  325. package/dist/extensions/agent-browser/lib/results/snapshot-spill.js +26 -7
  326. package/dist/extensions/agent-browser/lib/results/snapshot.js +28 -248
  327. package/dist/extensions/agent-browser/lib/results/text.js +16 -5
  328. package/dist/extensions/agent-browser/lib/runtime-args-validation.js +133 -0
  329. package/dist/extensions/agent-browser/lib/runtime-compatibility.js +81 -0
  330. package/dist/extensions/agent-browser/lib/runtime-contracts.js +1 -0
  331. package/dist/extensions/agent-browser/lib/runtime-redaction.js +118 -0
  332. package/dist/extensions/agent-browser/lib/runtime-replay-events.js +144 -0
  333. package/dist/extensions/agent-browser/lib/runtime-session-identity.js +76 -0
  334. package/dist/extensions/agent-browser/lib/runtime-session-plan.js +114 -0
  335. package/dist/extensions/agent-browser/lib/runtime-session-replay.js +123 -0
  336. package/dist/extensions/agent-browser/lib/runtime-tab-correction.js +65 -0
  337. package/dist/extensions/agent-browser/lib/runtime-timeouts.js +28 -0
  338. package/dist/extensions/agent-browser/lib/runtime.js +137 -1037
  339. package/dist/extensions/agent-browser/lib/session-identity.js +51 -0
  340. package/dist/extensions/agent-browser/lib/session-page-observation.js +357 -0
  341. package/dist/extensions/agent-browser/lib/session-page-state.js +188 -324
  342. package/dist/extensions/agent-browser/lib/session-page-types.js +1 -0
  343. package/dist/extensions/agent-browser/lib/temp-artifact-budget.js +78 -0
  344. package/dist/extensions/agent-browser/lib/temp-mutation-queue.js +7 -0
  345. package/dist/extensions/agent-browser/lib/temp-root-ownership.js +234 -0
  346. package/dist/extensions/agent-browser/lib/temp-root.js +207 -0
  347. package/dist/extensions/agent-browser/lib/temp.js +33 -446
  348. package/dist/extensions/agent-browser/lib/tool-surface.js +94 -24
  349. package/dist/extensions/agent-browser/lib/upstream-version.js +3 -2
  350. package/dist/extensions/agent-browser/lib/web-search-providers.js +229 -0
  351. package/dist/extensions/agent-browser/lib/web-search-request.js +108 -0
  352. package/dist/extensions/agent-browser/lib/web-search-results.js +281 -0
  353. package/dist/extensions/agent-browser/lib/web-search-schema.js +82 -0
  354. package/dist/extensions/agent-browser/lib/web-search.js +109 -617
  355. package/dist/extensions/agent-browser/lib/webmcp-observation.js +13 -6
  356. package/dist/extensions/agent-browser/lib/windows-stock-launcher.js +63 -37
  357. package/dist/extensions/agent-browser/script-worker.js +80 -43
  358. package/dist/scripts/agent-browser-target.mjs +4 -2
  359. package/docs/ARCHITECTURE.md +22 -10
  360. package/docs/CODE_QUALITY.md +242 -0
  361. package/docs/COMMAND_REFERENCE.md +264 -229
  362. package/docs/ELECTRON.md +53 -44
  363. package/docs/RELEASE.md +21 -17
  364. package/docs/REQUIREMENTS.md +2 -0
  365. package/docs/SESSION_STORAGE.md +1 -1
  366. package/docs/SUPPORT_MATRIX.md +84 -77
  367. package/docs/TOOL_CONTRACT.md +165 -130
  368. package/docs/platform-smoke.md +5 -5
  369. package/package.json +143 -120
  370. package/scripts/agent-browser-capability-baseline.mjs +361 -957
  371. package/scripts/agent-browser-target.mjs +6 -2
  372. package/scripts/build.mjs +37 -8
  373. package/scripts/capability-core-commands.mjs +193 -0
  374. package/scripts/capability-options.mjs +283 -0
  375. package/scripts/capability-samples.mjs +133 -0
  376. package/scripts/capability-section.mjs +11 -0
  377. package/scripts/config.mjs +213 -114
  378. package/scripts/convert-browser-session.mjs +30 -9
  379. package/scripts/doctor-sources.mjs +195 -0
  380. package/scripts/doctor.mjs +92 -247
  381. package/scripts/platform-smoke/artifacts.mjs +38 -11
  382. package/scripts/platform-smoke/commands.mjs +104 -0
  383. package/scripts/platform-smoke/crabbox-runner.mjs +167 -80
  384. package/scripts/platform-smoke/doctor-support.mjs +157 -0
  385. package/scripts/platform-smoke/doctor-windows.mjs +230 -0
  386. package/scripts/platform-smoke/doctor.mjs +212 -320
  387. package/scripts/platform-smoke/lease-evidence.mjs +134 -0
  388. package/scripts/platform-smoke/suite-checks.mjs +98 -0
  389. package/scripts/platform-smoke/suite-evidence.mjs +281 -0
  390. package/scripts/platform-smoke/targets.mjs +158 -472
  391. package/scripts/platform-smoke.mjs +55 -40
  392. package/scripts/prepare.mjs +16 -7
@@ -1,90 +1,127 @@
1
1
  import { isRecord } from "../../parsing.js";
2
2
  import { getStringField, redactModelFacingText, stringifyModelFacing } from "./common.js";
3
3
  function formatSkillsListText(skills) {
4
- if (skills.length === 0)
4
+ if (skills.length === 0) {
5
5
  return "No agent-browser skills found.";
6
+ }
6
7
  return skills
7
8
  .map((item, index) => {
8
- if (!isRecord(item))
9
+ if (!isRecord(item)) {
9
10
  return `${index + 1}. ${stringifyModelFacing(item)}`;
11
+ }
10
12
  const name = redactModelFacingText(getStringField(item, "name") ?? `(skill ${index + 1})`);
11
13
  const description = getStringField(item, "description");
12
- return description ? `${index + 1}. ${name} — ${redactModelFacingText(description)}` : `${index + 1}. ${name}`;
14
+ return description !== undefined
15
+ ? `${index + 1}. ${name} — ${redactModelFacingText(description)}`
16
+ : `${index + 1}. ${name}`;
13
17
  })
14
18
  .join("\n");
15
19
  }
16
20
  function getSkillContent(data) {
17
- if (typeof data === "string")
21
+ if (typeof data === "string") {
18
22
  return data;
19
- if (isRecord(data) && typeof data.content === "string")
23
+ }
24
+ if (isRecord(data) && typeof data.content === "string") {
20
25
  return data.content;
21
- if (!Array.isArray(data))
26
+ }
27
+ if (!Array.isArray(data)) {
22
28
  return undefined;
23
- const content = data.flatMap((item) => (isRecord(item) && typeof item.content === "string" ? [item.content] : []));
29
+ }
30
+ const content = data.flatMap((item) => isRecord(item) && typeof item.content === "string" ? [item.content] : []);
24
31
  return content.length > 0 ? content.join("\n\n") : undefined;
25
32
  }
26
- function splitShellWords(input) {
27
- const words = [];
28
- let current = "";
29
- let quote;
30
- for (let index = 0; index < input.length; index += 1) {
31
- const char = input[index];
32
- if (quote === "single") {
33
- if (char === "'")
34
- quote = undefined;
35
- else
36
- current += char;
37
- continue;
33
+ class SkillShellWords {
34
+ words = [];
35
+ current = "";
36
+ quote;
37
+ index = 0;
38
+ input;
39
+ constructor(input) {
40
+ this.input = input;
41
+ }
42
+ flush() {
43
+ if (this.current.length > 0) {
44
+ this.words.push(this.current);
45
+ this.current = "";
38
46
  }
39
- if (quote === "double") {
40
- if (char === '"')
41
- quote = undefined;
42
- else if (char === "\\" && index + 1 < input.length) {
43
- index += 1;
44
- current += input[index];
45
- }
46
- else
47
- current += char;
48
- continue;
47
+ }
48
+ appendEscape() {
49
+ if (this.index + 1 < this.input.length) {
50
+ this.index += 1;
51
+ this.current += this.input[this.index];
49
52
  }
50
- if (char === "'") {
51
- quote = "single";
52
- continue;
53
+ else {
54
+ this.current += "\\";
53
55
  }
54
- if (char === '"') {
55
- quote = "double";
56
- continue;
56
+ }
57
+ consumeQuoted(char) {
58
+ const closing = this.quote === "single" ? "'" : '"';
59
+ if (char === closing) {
60
+ this.quote = undefined;
57
61
  }
58
- if (char === "\\" && index + 1 < input.length) {
59
- index += 1;
60
- current += input[index];
61
- continue;
62
+ else if (this.quote === "double" && char === "\\") {
63
+ this.appendEscape();
64
+ }
65
+ else {
66
+ this.current += char;
67
+ }
68
+ }
69
+ consumeUnquoted(char) {
70
+ if (char === "'" || char === '"') {
71
+ this.quote = char === "'" ? "single" : "double";
72
+ }
73
+ else if (char === "\\") {
74
+ this.appendEscape();
62
75
  }
63
- if (char === "#" && current.length === 0) {
64
- break;
76
+ else if (char === "#" && this.current.length === 0) {
77
+ return false;
65
78
  }
66
- if (/\s/.test(char)) {
67
- if (current.length > 0) {
68
- words.push(current);
69
- current = "";
79
+ else if (/\s/.test(char)) {
80
+ this.flush();
81
+ }
82
+ else {
83
+ this.current += char;
84
+ }
85
+ return true;
86
+ }
87
+ parse() {
88
+ for (; this.index < this.input.length; this.index += 1) {
89
+ const char = this.input[this.index];
90
+ if (this.quote !== undefined) {
91
+ this.consumeQuoted(char);
70
92
  }
71
- continue;
93
+ else if (!this.consumeUnquoted(char)) {
94
+ break;
95
+ }
96
+ }
97
+ if (this.quote !== undefined) {
98
+ return undefined;
72
99
  }
73
- current += char;
100
+ this.flush();
101
+ return this.words;
74
102
  }
75
- if (quote)
76
- return undefined;
77
- if (current.length > 0)
78
- words.push(current);
79
- return words;
80
103
  }
81
104
  function formatNativeAgentBrowserCall(args, stdin) {
82
105
  return stdin === undefined
83
106
  ? `agent_browser { "args": ${JSON.stringify(args)} }`
84
107
  : `agent_browser { "args": ${JSON.stringify(args)}, "stdin": ${JSON.stringify(stdin)} }`;
85
108
  }
109
+ function readSkillHeredoc(lines, startIndex, delimiter, stripsLeadingTabs) {
110
+ const stdinLines = [];
111
+ for (let cursor = startIndex; cursor < lines.length; cursor += 1) {
112
+ const candidate = stripsLeadingTabs ? lines[cursor].replace(/^\t+/, "") : lines[cursor];
113
+ if (candidate === delimiter) {
114
+ return { stdin: stdinLines.join("\n"), endIndex: cursor };
115
+ }
116
+ stdinLines.push(candidate);
117
+ }
118
+ return undefined;
119
+ }
86
120
  function formatNativeSkillContent(content) {
87
- const lines = content.replace(/^allowed-tools:.*agent-browser.*\n?/gim, "").replace(/^```bash\s*$/gim, "```text").split("\n");
121
+ const lines = content
122
+ .replace(/^allowed-tools:.*agent-browser.*\n?/gim, "")
123
+ .replace(/^```bash\s*$/gim, "```text")
124
+ .split("\n");
88
125
  const output = [];
89
126
  for (let index = 0; index < lines.length; index += 1) {
90
127
  const line = lines[index];
@@ -97,7 +134,7 @@ function formatNativeSkillContent(content) {
97
134
  const rawArgsText = commandMatch[2];
98
135
  const heredocMatch = /^(.*?)\s+(<<-?)['"]?([A-Za-z_][A-Za-z0-9_]*)['"]?\s*$/.exec(rawArgsText);
99
136
  const argsText = heredocMatch?.[1] ?? rawArgsText;
100
- const args = splitShellWords(argsText);
137
+ const args = new SkillShellWords(argsText).parse();
101
138
  if (!args || args.length === 0) {
102
139
  output.push(line);
103
140
  continue;
@@ -106,42 +143,36 @@ function formatNativeSkillContent(content) {
106
143
  output.push(`${indent}${formatNativeAgentBrowserCall(args)}`);
107
144
  continue;
108
145
  }
109
- const stripsLeadingTabs = heredocMatch[2] === "<<-";
110
- const delimiter = heredocMatch[3];
111
- const stdinLines = [];
112
- let cursor = index + 1;
113
- while (cursor < lines.length) {
114
- const candidate = stripsLeadingTabs ? lines[cursor].replace(/^\t+/, "") : lines[cursor];
115
- if (candidate === delimiter)
116
- break;
117
- stdinLines.push(candidate);
118
- cursor += 1;
119
- }
120
- if (cursor >= lines.length) {
146
+ const heredoc = readSkillHeredoc(lines, index + 1, heredocMatch[3], heredocMatch[2] === "<<-");
147
+ if (!heredoc) {
121
148
  output.push(line);
122
149
  continue;
123
150
  }
124
- output.push(`${indent}${formatNativeAgentBrowserCall(args, stdinLines.join("\n"))}`);
125
- index = cursor;
151
+ output.push(`${indent}${formatNativeAgentBrowserCall(args, heredoc.stdin)}`);
152
+ index = heredoc.endIndex;
126
153
  }
127
154
  return output.join("\n");
128
155
  }
129
156
  export function formatSkillsText(commandInfo, data) {
130
- if (commandInfo.command !== "skills")
157
+ if (commandInfo.command !== "skills") {
131
158
  return undefined;
132
- if (commandInfo.subcommand === "path")
159
+ }
160
+ if (commandInfo.subcommand === "path") {
133
161
  return typeof data === "string" ? redactModelFacingText(data) : undefined;
134
- if (commandInfo.subcommand === "list" && Array.isArray(data))
162
+ }
163
+ if (commandInfo.subcommand === "list" && Array.isArray(data)) {
135
164
  return formatSkillsListText(data);
165
+ }
136
166
  const content = getSkillContent(data);
137
- if (content) {
167
+ if (content !== undefined && content.length > 0) {
138
168
  const note = [
139
169
  "Pi native-tool note: upstream skill text was adapted for this native tool.",
140
170
  "Use args for CLI tokens and stdin only for batch, eval --stdin, or auth save --password-stdin; do not pipe heredocs through bash unless the user explicitly asks for a bash workflow.",
141
171
  ].join("\n");
142
172
  return `${note}\n\n${redactModelFacingText(formatNativeSkillContent(content))}`;
143
173
  }
144
- if (typeof data === "string")
174
+ if (typeof data === "string") {
145
175
  return redactModelFacingText(formatNativeSkillContent(data));
176
+ }
146
177
  return undefined;
147
178
  }
@@ -0,0 +1,109 @@
1
+ import { extractUpstreamCommandTokens, parseCommandInfo, } from "../../argv-descriptor.js";
2
+ import { isRecord } from "../../parsing.js";
3
+ import { nextReadConfirmation } from "../../read-confirmation.js";
4
+ import { redactInvocationArgs } from "../../runtime-redaction.js";
5
+ import { detectConfirmationRequired } from "../confirmation.js";
6
+ import { buildSnapshotPresentation } from "../snapshot.js";
7
+ import { formatArtifactMetadataLines, formatArtifactSummary } from "./artifacts.js";
8
+ import { buildBatchPresentation, isAgentBrowserBatchResultArray, redactBatchStepErrorData, } from "./batch.js";
9
+ import { isStringArray } from "./content.js";
10
+ import { enrichStreamStatusData, redactPresentationData } from "./diagnostics.js";
11
+ import { formatPresentationContentText, formatPresentationSummary } from "./registry.js";
12
+ import { resolvePresentationCommandInfo } from "./semantic-action.js";
13
+ export function resolvePresentationCommands(options) {
14
+ const commandInfo = options.commandInfo.commandTokens || !options.args
15
+ ? options.commandInfo
16
+ : { ...options.commandInfo, commandTokens: extractUpstreamCommandTokens(options.args) };
17
+ return {
18
+ commandInfo,
19
+ presentationCommandInfo: resolvePresentationCommandInfo(commandInfo, options.compiledSemanticAction),
20
+ };
21
+ }
22
+ function redactBatchSpillData(data) {
23
+ return data.map((row) => {
24
+ const command = isStringArray(row.command) ? row.command : undefined;
25
+ return {
26
+ ...row,
27
+ command: command ? redactInvocationArgs(command) : row.command,
28
+ error: row.error === undefined ? undefined : redactBatchStepErrorData(command, row.error),
29
+ result: row.result === undefined
30
+ ? undefined
31
+ : redactPresentationData(parseCommandInfo(command ?? []), row.result),
32
+ };
33
+ });
34
+ }
35
+ export function buildPresentationSource(options, commands) {
36
+ const { commandInfo } = commands;
37
+ const data = enrichPresentationSource(options, commandInfo);
38
+ return {
39
+ ...commands,
40
+ data,
41
+ presentationData: commandInfo.command === "batch" && isAgentBrowserBatchResultArray(data)
42
+ ? redactBatchSpillData(data)
43
+ : redactPresentationData(commandInfo, data),
44
+ recordingCommand: commandInfo.command === "record",
45
+ recordingBatch: isRecordingBatch(commandInfo, data),
46
+ confirmationRequired: detectConfirmationRequired(data),
47
+ readConfirmation: nextReadConfirmation({
48
+ commandTokens: commandInfo.commandTokens ?? [],
49
+ data,
50
+ namespace: options.namespace,
51
+ sessionName: options.sessionName ?? "default",
52
+ succeeded: options.envelope?.success !== false,
53
+ }),
54
+ };
55
+ }
56
+ function enrichPresentationSource(options, commandInfo) {
57
+ const data = enrichStreamStatusData(commandInfo, options.envelope?.data);
58
+ return commandInfo.command === "session" && commandInfo.subcommand === "info" && isRecord(data)
59
+ ? { ...data, piCleanupOwnership: options.piCleanupOwnership ?? "unknown" }
60
+ : data;
61
+ }
62
+ function isRecordingBatch(command, data) {
63
+ return (command.command === "batch" &&
64
+ isAgentBrowserBatchResultArray(data) &&
65
+ data.some((row) => row.command?.[0] === "record"));
66
+ }
67
+ function buildNativeContent(options, source, artifacts) {
68
+ if (options.modelVisible === false) {
69
+ return [];
70
+ }
71
+ const text = artifacts.length > 0
72
+ ? formatArtifactMetadataLines(artifacts).join("\n")
73
+ : formatPresentationContentText(source.commandInfo, source.data, options.compiledSemanticAction);
74
+ return [{ type: "text", text }];
75
+ }
76
+ export async function buildSourcePresentation(options, source, artifacts, buildNestedToolPresentation) {
77
+ const summary = formatArtifactSummary(artifacts) ??
78
+ formatPresentationSummary(source.commandInfo, source.data, options.compiledSemanticAction);
79
+ if (source.commandInfo.command === "batch" && isAgentBrowserBatchResultArray(source.data)) {
80
+ return buildBatchPresentation({
81
+ artifactManifest: options.artifactManifest,
82
+ artifactMaxUpdatedAtMs: options.artifactMaxUpdatedAtMs,
83
+ artifactMinUpdatedAtMs: options.artifactMinUpdatedAtMs,
84
+ artifactRequests: options.batchArtifactRequests,
85
+ buildNestedToolPresentation,
86
+ modelVisible: options.modelVisible,
87
+ cwd: options.cwd,
88
+ data: source.data,
89
+ namespace: options.namespace,
90
+ networkRoutes: options.networkRoutes,
91
+ persistentArtifactStore: options.persistentArtifactStore,
92
+ piCleanupOwnership: options.piCleanupOwnership,
93
+ sessionName: options.sessionName,
94
+ summary,
95
+ });
96
+ }
97
+ if (options.modelVisible !== false &&
98
+ source.commandInfo.command === "snapshot" &&
99
+ isRecord(source.data) &&
100
+ !source.confirmationRequired) {
101
+ return buildSnapshotPresentation(source.data, options.persistentArtifactStore, options.artifactManifest);
102
+ }
103
+ return {
104
+ artifacts: artifacts.length > 0 ? artifacts : undefined,
105
+ content: buildNativeContent(options, source, artifacts),
106
+ data: source.presentationData,
107
+ summary,
108
+ };
109
+ }
@@ -1,250 +1,19 @@
1
- import { getScreenshotCapture } from "../orchestration/browser-run/screenshot-observation.js";
2
- import { isRecord } from "../parsing.js";
3
- import { buildReadConfirmationNextActions, nextReadConfirmation } from "../read-confirmation.js";
4
- import { extractUpstreamCommandTokens, parseCommandInfo, redactInvocationArgs } from "../runtime.js";
5
- import { buildAgentBrowserNextActions } from "./action-recommendations.js";
6
- import { buildAgentBrowserResultCategoryDetails } from "./categories.js";
7
- import { detectConfirmationRequired } from "./confirmation.js";
8
- import { buildSnapshotPresentation } from "./snapshot.js";
9
- import { formatWebMcpCatalogUpdate, redactModelFacingText } from "./presentation/common.js";
10
- import { applyArtifactManifest, attachInlineImage, buildArtifactVerificationSummary, buildManifestEntriesForFileArtifacts, classifyPresentationSuccessCategory, extractFileArtifacts, extractImagePath, formatArtifactMetadataLines, formatArtifactSummary, formatMissingArtifactFailureText, getSavedFileDetails, hasMissingFileArtifact, isManifestFileArtifact, } from "./presentation/artifacts.js";
11
- import { buildBatchPresentation, isAgentBrowserBatchResultArray, redactBatchStepErrorData } from "./presentation/batch.js";
12
- import { getPresentationPaths, isStringArray } from "./presentation/content.js";
13
- import { buildNetworkRequestsNextActions, buildStreamNextActions, enrichStreamStatusData, formatNetworkRouteDiagnosticsText, redactPresentationData, } from "./presentation/diagnostics.js";
14
- import { buildErrorPresentation, isOverlayBlockedClickError } from "./presentation/errors.js";
15
- import { compactLargePresentationOutput } from "./presentation/large-output.js";
16
- import { buildPageChangeSummary } from "./presentation/navigation.js";
17
- import { formatPresentationContentText, formatPresentationSummary } from "./presentation/registry.js";
18
- import { resolvePresentationCommandInfo } from "./presentation/semantic-action.js";
19
- function sanitizeModelFacingPresentation(presentation) {
20
- presentation.content = presentation.content.map((item) => {
21
- if (item.type !== "text")
22
- return item;
23
- return { ...item, text: redactModelFacingText(item.text) };
24
- });
25
- presentation.summary = redactModelFacingText(presentation.summary);
26
- return presentation;
27
- }
28
- function mergeNextActions(...groups) {
29
- const merged = groups.flatMap((group) => group ?? []);
30
- return merged.length > 0 ? merged : undefined;
31
- }
32
- function shouldAddAnnotatedScreenshotGuidance(commandInfo, args) {
33
- return commandInfo.command === "screenshot" && (args?.includes("--annotate") ?? false);
34
- }
35
- function getKeyboardInsertTextWarning(commandInfo) {
36
- if (commandInfo.command !== "keyboard" || commandInfo.subcommand !== "inserttext")
37
- return undefined;
38
- return "Input dispatch warning: keyboard inserttext skips key events. A DOM value change does not prove a framework-controlled editor accepted it; verify application state before saving, or use keyboard type when real key events are required.";
39
- }
40
- function redactBatchSpillData(data) {
41
- return data.map((row) => {
42
- const command = isStringArray(row.command) ? row.command : undefined;
43
- const commandInfo = parseCommandInfo(command ?? []);
44
- return {
45
- ...row,
46
- command: command ? redactInvocationArgs(command) : row.command,
47
- error: row.error === undefined ? undefined : redactBatchStepErrorData(command, row.error),
48
- result: row.result === undefined ? undefined : redactPresentationData(commandInfo, row.result),
49
- };
50
- });
51
- }
1
+ import { completePresentationOutput, extractPresentationArtifacts, } from "./presentation/output-completion.js";
52
2
  export async function buildToolPresentation(options) {
53
- const { args, artifactManifest, artifactRequest, commandInfo, compiledSemanticAction, cwd, envelope, errorText, namespace, networkRouteDiagnostics, networkRoutes, persistentArtifactStore, sessionName, } = options;
54
- const commandInfoWithTokens = commandInfo.commandTokens || !args ? commandInfo : { ...commandInfo, commandTokens: extractUpstreamCommandTokens(args) };
55
- const presentationCommandInfo = resolvePresentationCommandInfo(commandInfoWithTokens, compiledSemanticAction);
56
- const recordingCommand = commandInfo.command === "record";
57
- const recordingBatch = commandInfo.command === "batch" && isAgentBrowserBatchResultArray(envelope?.data)
58
- && envelope.data.some((row) => row.command?.[0] === "record");
59
- if (errorText && !recordingCommand && !recordingBatch) {
60
- return { ...buildErrorPresentation({ args, commandInfo, errorText, presentationCommand: presentationCommandInfo.command, sessionName }),
61
- data: redactPresentationData(commandInfoWithTokens, envelope?.data),
62
- };
63
- }
64
- let data = enrichStreamStatusData(commandInfoWithTokens, envelope?.data);
65
- if (commandInfo.command === "session" && commandInfo.subcommand === "info" && isRecord(data)) {
66
- data = { ...data, piCleanupOwnership: options.piCleanupOwnership ?? "unknown" };
67
- }
68
- const readConfirmation = nextReadConfirmation({ commandTokens: commandInfoWithTokens.commandTokens ?? [], data, namespace, sessionName: sessionName ?? "default", succeeded: envelope?.success !== false });
69
- const presentationData = commandInfo.command === "batch" && isAgentBrowserBatchResultArray(data)
70
- ? redactBatchSpillData(data)
71
- : redactPresentationData(commandInfoWithTokens, data);
72
- const artifacts = await extractFileArtifacts({ artifactManifest, artifactMaxUpdatedAtMs: options.artifactMaxUpdatedAtMs, artifactMinUpdatedAtMs: options.artifactMinUpdatedAtMs, artifactRequest, commandInfo: presentationCommandInfo, cwd, data, namespace, recordingOutcome: recordingCommand ? envelope?.success : undefined, recordingPending: options.recordingPending, previousRecordingContactSheetPath: options.previousRecordingContactSheetPath, sessionName });
73
- const artifactVerification = buildArtifactVerificationSummary(artifacts);
74
- const artifactSummary = formatArtifactSummary(artifacts);
75
- const summary = artifactSummary ?? formatPresentationSummary(commandInfoWithTokens, data, compiledSemanticAction);
76
- const artifactText = artifacts.length > 0 ? formatArtifactMetadataLines(artifacts).join("\n") : undefined;
77
- let presentation;
78
- if (commandInfo.command === "batch" && isAgentBrowserBatchResultArray(data)) {
79
- presentation = await buildBatchPresentation({
80
- artifactManifest,
81
- artifactMaxUpdatedAtMs: options.artifactMaxUpdatedAtMs,
82
- artifactMinUpdatedAtMs: options.artifactMinUpdatedAtMs,
83
- artifactRequests: options.batchArtifactRequests,
84
- buildNestedToolPresentation: buildToolPresentation,
85
- modelVisible: options.modelVisible,
86
- cwd,
87
- data,
88
- namespace,
89
- networkRoutes,
90
- persistentArtifactStore,
91
- piCleanupOwnership: options.piCleanupOwnership,
92
- sessionName,
93
- summary,
94
- });
95
- }
96
- else if (options.modelVisible !== false && commandInfo.command === "snapshot" && isRecord(data)) {
97
- presentation = await buildSnapshotPresentation(data, persistentArtifactStore, artifactManifest);
98
- }
99
- else {
100
- presentation = {
101
- artifactVerification,
102
- artifacts: artifacts.length > 0 ? artifacts : undefined,
103
- content: options.modelVisible === false ? [] : [{ type: "text", text: artifactText ?? formatPresentationContentText(commandInfoWithTokens, data, compiledSemanticAction) }],
104
- data: presentationData,
105
- summary,
106
- };
107
- }
108
- if (errorText && (recordingCommand || recordingBatch)) {
109
- const errorPresentation = buildErrorPresentation({ args, commandInfo, errorText, presentationCommand: presentationCommandInfo.command, sessionName });
110
- presentation = { ...presentation, resultCategory: "failure", failureCategory: errorPresentation.failureCategory, summary: errorPresentation.summary,
111
- content: [{ type: "text", text: `${errorPresentation.content[0]?.type === "text" ? errorPresentation.content[0].text : errorText}\n\n${presentation.content[0]?.type === "text" ? presentation.content[0].text : ""}` }],
112
- };
113
- }
114
- if (networkRouteDiagnostics && networkRouteDiagnostics.length > 0 && presentation.content[0]?.type === "text") {
115
- const diagnosticText = formatNetworkRouteDiagnosticsText(networkRouteDiagnostics);
116
- if (diagnosticText)
117
- presentation.content[0] = { ...presentation.content[0], text: `${diagnosticText}\n\n${presentation.content[0].text}` };
118
- presentation.networkRouteDiagnostics = networkRouteDiagnostics;
119
- }
120
- if (artifacts.length > 0 && !presentation.artifacts) {
121
- presentation.artifacts = artifacts;
122
- }
123
- presentation.artifactVerification = presentation.artifactVerification ?? artifactVerification;
124
- if (isRecord(data)) {
125
- const savedFile = getSavedFileDetails(commandInfo, data);
126
- if (savedFile) {
127
- presentation.savedFile = savedFile;
128
- presentation.savedFilePath = savedFile.path;
129
- }
130
- }
131
- if (isRecord(presentationData) && isRecord(presentationData.webmcp) && (Array.isArray(presentationData.webmcp.tools) || presentationData.webmcp.status === "unavailable") && presentation.content[0]?.type === "text") {
132
- presentation.content[0] = { ...presentation.content[0], text: `${presentation.content[0].text}\n\n${formatWebMcpCatalogUpdate(presentationData.webmcp)}` };
133
- }
134
- if (shouldAddAnnotatedScreenshotGuidance(commandInfo, args) && presentation.content[0]?.type === "text") {
135
- const guidance = "Annotated screenshot note: dense pages can produce overlapping labels. If the labels are noisy, capture a scoped element screenshot, take a non-annotated screenshot, or use snapshot -i high-value refs as the machine-readable map.";
136
- presentation.content[0] = { ...presentation.content[0], text: `${presentation.content[0].text}\n\n${guidance}` };
137
- }
138
- const keyboardInsertTextWarning = getKeyboardInsertTextWarning(commandInfoWithTokens);
139
- if (keyboardInsertTextWarning && presentation.content[0]?.type === "text") {
140
- presentation.content[0] = { ...presentation.content[0], text: `${presentation.content[0].text}\n\n${keyboardInsertTextWarning}` };
141
- }
142
- const imagePath = artifactRequest?.absolutePath ?? extractImagePath(commandInfo, cwd, data)
143
- ?? (recordingCommand ? artifacts.find((artifact) => artifact.kind === "image" && artifact.status === "saved")?.absolutePath : undefined);
144
- const attachImage = imagePath && !(isRecord(data) && data.changed === false) && !artifacts.some(artifact => artifact.absolutePath === imagePath && ["missing", "stale", "failed"].includes(artifact.status ?? ""));
145
- const presentationWithImage = attachImage ? await attachInlineImage(presentation, imagePath, options.modelVisible) : presentation;
146
- if (commandInfo.command === "screenshot" && presentationWithImage.imageObservations) {
147
- for (const image of presentationWithImage.imageObservations)
148
- image.capture = getScreenshotCapture(commandInfoWithTokens.commandTokens ?? []).kind;
149
- }
150
- const compactedPresentation = options.modelVisible === false ? presentationWithImage : await compactLargePresentationOutput({
151
- artifactManifest,
152
- commandInfo,
153
- data: presentationData,
154
- persistentArtifactStore,
155
- presentation: presentationWithImage,
156
- });
157
- const presentationWithManifest = applyArtifactManifest(compactedPresentation, compactedPresentation.artifactManifest ?? artifactManifest, buildManifestEntriesForFileArtifacts(artifacts.filter(isManifestFileArtifact)));
158
- const currentSpillPaths = new Set(getPresentationPaths({
159
- primaryPath: presentationWithManifest.fullOutputPath,
160
- secondaryPaths: presentationWithManifest.fullOutputPaths,
161
- }));
162
- presentationWithManifest.artifactVerification = buildArtifactVerificationSummary(artifacts, presentationWithManifest.artifactManifest, currentSpillPaths) ?? presentationWithManifest.artifactVerification;
163
- const confirmationRequired = detectConfirmationRequired(data);
164
- const missingArtifactFailureText = formatMissingArtifactFailureText(presentationWithManifest.artifacts);
165
- if (!errorText && missingArtifactFailureText && hasMissingFileArtifact(presentationWithManifest.artifacts)) {
166
- presentationWithManifest.resultCategory = "failure";
167
- presentationWithManifest.failureCategory = "artifact-missing";
168
- presentationWithManifest.successCategory = undefined;
169
- presentationWithManifest.summary = missingArtifactFailureText;
170
- if (presentationWithManifest.content[0]?.type === "text") {
171
- presentationWithManifest.content[0] = { ...presentationWithManifest.content[0], text: `${missingArtifactFailureText}\n\n${presentationWithManifest.content[0].text}` };
172
- }
173
- else {
174
- presentationWithManifest.content.unshift({ type: "text", text: missingArtifactFailureText });
175
- }
176
- }
177
- const failedRecording = presentationWithManifest.artifacts?.find((artifact) => artifact.recording?.success === false || artifact.recording?.output.encoderSucceeded === false);
178
- if (failedRecording && !errorText) {
179
- const failure = `Recording failed: ${failedRecording.recording?.error ?? "native capture/encoder failure"}`;
180
- presentationWithManifest.resultCategory = "failure";
181
- presentationWithManifest.failureCategory = "upstream-error";
182
- presentationWithManifest.successCategory = undefined;
183
- presentationWithManifest.summary = failure;
184
- presentationWithManifest.content.unshift({ type: "text", text: failure });
185
- }
186
- if (readConfirmation?.state === "pending") {
187
- presentationWithManifest.readConfirmation = readConfirmation;
188
- presentationWithManifest.resultCategory = "failure";
189
- presentationWithManifest.failureCategory = "confirmation-required";
190
- presentationWithManifest.successCategory = undefined;
191
- }
192
- if (!presentationWithManifest.resultCategory) {
193
- const categoryDetails = buildAgentBrowserResultCategoryDetails({
194
- artifacts: presentationWithManifest.artifacts,
195
- command: presentationCommandInfo.command,
196
- confirmationRequired: confirmationRequired !== undefined,
197
- errorText: envelope?.success === false ? presentationWithManifest.summary : undefined,
198
- savedFile: presentationWithManifest.savedFile,
199
- succeeded: envelope?.success !== false && confirmationRequired === undefined,
200
- });
201
- presentationWithManifest.resultCategory = categoryDetails.resultCategory;
202
- presentationWithManifest.successCategory = categoryDetails.resultCategory === "success"
203
- ? classifyPresentationSuccessCategory({
204
- artifactVerification: presentationWithManifest.artifactVerification,
205
- artifacts: presentationWithManifest.artifacts,
206
- savedFile: presentationWithManifest.savedFile,
207
- })
208
- : categoryDetails.successCategory;
209
- presentationWithManifest.failureCategory = categoryDetails.failureCategory;
210
- }
211
- if (presentationWithManifest.resultCategory === "success") {
212
- presentationWithManifest.successCategory = classifyPresentationSuccessCategory({
213
- artifactVerification: presentationWithManifest.artifactVerification,
214
- artifacts: presentationWithManifest.artifacts,
215
- savedFile: presentationWithManifest.savedFile,
216
- });
217
- }
218
- const genericNextActions = presentationWithManifest.nextActions ? undefined : buildAgentBrowserNextActions({
219
- artifacts: presentationWithManifest.artifacts,
220
- args,
221
- command: presentationCommandInfo.command,
222
- confirmationId: confirmationRequired?.id,
223
- failureCategory: presentationWithManifest.failureCategory,
224
- overlayBlockedClick: isOverlayBlockedClickError(presentationCommandInfo.command, envelope?.success === false ? presentationWithManifest.summary : undefined, args ?? presentationCommandInfo.commandTokens),
225
- resultCategory: presentationWithManifest.resultCategory ?? "success",
226
- savedFilePath: presentationWithManifest.savedFilePath,
227
- sessionName,
228
- subcommand: presentationCommandInfo.subcommand,
229
- successCategory: presentationWithManifest.successCategory,
230
- });
231
- const networkNextActions = commandInfoWithTokens.command === "network" && commandInfoWithTokens.subcommand === "requests" && presentationWithManifest.resultCategory === "success"
232
- ? buildNetworkRequestsNextActions(data, sessionName, presentationWithManifest.networkRouteDiagnostics)
233
- : undefined;
234
- const streamNextActions = presentationWithManifest.resultCategory === "success" ? buildStreamNextActions(commandInfoWithTokens, data, sessionName) : undefined;
235
- presentationWithManifest.nextActions = readConfirmation ? buildReadConfirmationNextActions(readConfirmation, true) : mergeNextActions(presentationWithManifest.nextActions, genericNextActions, networkNextActions, streamNextActions);
236
- presentationWithManifest.pageChangeSummary = presentationWithManifest.pageChangeSummary ?? buildPageChangeSummary({
237
- artifacts: presentationWithManifest.artifacts,
238
- commandInfo: presentationCommandInfo,
239
- data,
240
- nextActions: presentationWithManifest.nextActions,
241
- savedFilePath: presentationWithManifest.savedFilePath,
242
- summary: presentationWithManifest.summary,
243
- });
244
- if (presentationWithManifest.pageChangeSummary?.observed === false && presentationCommandInfo.command !== "batch" && presentationWithManifest.content[0]?.type === "text") {
245
- presentationWithManifest.content[0] = { ...presentationWithManifest.content[0], text: `${presentationWithManifest.content[0].text}\n\nAction dispatched; application change unverified. Verify the expected URL, text, state, or external receipt before relying on it.` };
246
- }
247
- if (options.modelVisible === false)
248
- presentationWithManifest.content = [];
249
- return sanitizeModelFacingPresentation(presentationWithManifest);
3
+ const { buildPresentationSource, buildSourcePresentation, resolvePresentationCommands } = await import("./presentation/source.js");
4
+ const { buildEarlyPresentation, sanitizeModelFacingPresentation } = await import("./presentation/early-result.js");
5
+ const { applyPresentationNotices } = await import("./presentation/notices.js");
6
+ const { applyPresentationOutcome } = await import("./presentation/outcomes.js");
7
+ const commands = resolvePresentationCommands(options);
8
+ const early = await buildEarlyPresentation(options, commands);
9
+ if (early) {
10
+ return early;
11
+ }
12
+ const source = buildPresentationSource(options, commands);
13
+ const artifacts = await extractPresentationArtifacts(options, source);
14
+ const draft = await buildSourcePresentation(options, source, artifacts, buildToolPresentation);
15
+ applyPresentationNotices(draft, options, source);
16
+ const completed = await completePresentationOutput(draft, options, source, artifacts);
17
+ applyPresentationOutcome(completed, options, source);
18
+ return sanitizeModelFacingPresentation(completed);
250
19
  }