pi-agent-browser-native 0.9.3 → 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 (391) hide show
  1. package/CHANGELOG.md +77 -5
  2. package/README.md +103 -81
  3. package/dist/extensions/agent-browser/index.js +43057 -2031
  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 +112 -51
  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 -82
  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 +43 -9
  82. package/dist/extensions/agent-browser/lib/orchestration/batch-stdin.js +106 -59
  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 +164 -60
  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 +199 -154
  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 -205
  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 -1123
  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 -968
  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 -765
  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 -821
  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 -157
  228. package/dist/extensions/agent-browser/lib/orchestration/operation-paths.js +124 -58
  229. package/dist/extensions/agent-browser/lib/orchestration/output-file.js +197 -99
  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 +55 -246
  236. package/dist/extensions/agent-browser/lib/parsing.js +13 -4
  237. package/dist/extensions/agent-browser/lib/pi-tool-rendering.js +133 -68
  238. package/dist/extensions/agent-browser/lib/playbook.js +16 -12
  239. package/dist/extensions/agent-browser/lib/process-child.js +284 -0
  240. package/dist/extensions/agent-browser/lib/process-environment.js +13 -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 +145 -536
  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 +131 -68
  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 -13
  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 +90 -67
  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 -555
  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 -1052
  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 +116 -240
  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 -261
  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 +119 -119
  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 -1041
  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 +178 -333
  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 +17 -5
  360. package/docs/CODE_QUALITY.md +242 -0
  361. package/docs/COMMAND_REFERENCE.md +251 -220
  362. package/docs/ELECTRON.md +53 -44
  363. package/docs/RELEASE.md +18 -15
  364. package/docs/REQUIREMENTS.md +1 -0
  365. package/docs/SUPPORT_MATRIX.md +76 -75
  366. package/docs/TOOL_CONTRACT.md +145 -116
  367. package/docs/platform-smoke.md +5 -5
  368. package/package.json +143 -120
  369. package/scripts/agent-browser-capability-baseline.mjs +361 -957
  370. package/scripts/agent-browser-target.mjs +6 -2
  371. package/scripts/build.mjs +37 -8
  372. package/scripts/capability-core-commands.mjs +193 -0
  373. package/scripts/capability-options.mjs +283 -0
  374. package/scripts/capability-samples.mjs +133 -0
  375. package/scripts/capability-section.mjs +11 -0
  376. package/scripts/config.mjs +213 -114
  377. package/scripts/convert-browser-session.mjs +30 -9
  378. package/scripts/doctor-sources.mjs +195 -0
  379. package/scripts/doctor.mjs +92 -247
  380. package/scripts/platform-smoke/artifacts.mjs +38 -11
  381. package/scripts/platform-smoke/commands.mjs +104 -0
  382. package/scripts/platform-smoke/crabbox-runner.mjs +167 -80
  383. package/scripts/platform-smoke/doctor-support.mjs +157 -0
  384. package/scripts/platform-smoke/doctor-windows.mjs +230 -0
  385. package/scripts/platform-smoke/doctor.mjs +212 -320
  386. package/scripts/platform-smoke/lease-evidence.mjs +134 -0
  387. package/scripts/platform-smoke/suite-checks.mjs +98 -0
  388. package/scripts/platform-smoke/suite-evidence.mjs +281 -0
  389. package/scripts/platform-smoke/targets.mjs +158 -472
  390. package/scripts/platform-smoke.mjs +55 -40
  391. package/scripts/prepare.mjs +16 -7
@@ -0,0 +1,70 @@
1
+ import { isAgentBrowserBatchResultArray } from "./batch.js";
2
+ import { redactModelFacingText } from "./common.js";
3
+ import { redactPresentationData } from "./diagnostics.js";
4
+ import { buildErrorPresentation } from "./errors.js";
5
+ import { compactLargePresentationOutput } from "./large-output.js";
6
+ import { stringifyUnknown } from "../text.js";
7
+ function getNativeTextSummary(text) {
8
+ const first = text.split("\n", 1).at(0);
9
+ return first !== undefined && first.length > 0 ? first : "Native text command completed.";
10
+ }
11
+ export function sanitizeModelFacingPresentation(presentation) {
12
+ return {
13
+ ...presentation,
14
+ content: presentation.content.map((item) => item.type === "text" ? { ...item, text: redactModelFacingText(item.text) } : item),
15
+ summary: redactModelFacingText(presentation.summary),
16
+ };
17
+ }
18
+ async function buildNativeTextPresentation(options, commandInfo) {
19
+ const value = redactPresentationData(commandInfo, typeof options.envelope?.data === "string" ? options.envelope.data : "", options.stdin);
20
+ const text = typeof value === "string" ? value : stringifyUnknown(value);
21
+ const failure = options.errorText !== undefined && options.errorText.length > 0
22
+ ? buildErrorPresentation({
23
+ args: options.args,
24
+ commandInfo: options.commandInfo,
25
+ errorText: options.errorText,
26
+ sessionName: options.sessionName,
27
+ })
28
+ : undefined;
29
+ const presentation = {
30
+ ...failure,
31
+ content: options.modelVisible === false
32
+ ? []
33
+ : [{ type: "text", text: [options.errorText, text].filter(Boolean).join("\n\n") }],
34
+ data: text,
35
+ summary: failure?.summary ?? getNativeTextSummary(text),
36
+ };
37
+ return sanitizeModelFacingPresentation(options.modelVisible === false
38
+ ? presentation
39
+ : await compactLargePresentationOutput({
40
+ artifactManifest: options.artifactManifest,
41
+ commandInfo: options.commandInfo,
42
+ data: presentation.data,
43
+ persistentArtifactStore: options.persistentArtifactStore,
44
+ presentation,
45
+ }));
46
+ }
47
+ export async function buildEarlyPresentation(options, commands) {
48
+ if (options.textOutput === true) {
49
+ return buildNativeTextPresentation(options, commands.commandInfo);
50
+ }
51
+ const recordingBatch = options.commandInfo.command === "batch" &&
52
+ isAgentBrowserBatchResultArray(options.envelope?.data) &&
53
+ options.envelope.data.some((row) => row.command?.[0] === "record");
54
+ if (options.errorText !== undefined &&
55
+ options.errorText.length > 0 &&
56
+ options.commandInfo.command !== "record" &&
57
+ !recordingBatch) {
58
+ return {
59
+ ...buildErrorPresentation({
60
+ args: options.args,
61
+ commandInfo: options.commandInfo,
62
+ errorText: options.errorText,
63
+ presentationCommand: commands.presentationCommandInfo.command,
64
+ sessionName: options.sessionName,
65
+ }),
66
+ data: redactPresentationData(commands.commandInfo, options.envelope?.data),
67
+ };
68
+ }
69
+ return undefined;
70
+ }
@@ -1,5 +1,7 @@
1
1
  import { isOpenNavigationCommand } from "../../command-taxonomy.js";
2
- import { extractUpstreamCommandTokens, redactSensitiveText } from "../../runtime.js";
2
+ import { isRecord } from "../../parsing.js";
3
+ import { extractUpstreamCommandTokens } from "../../argv-descriptor.js";
4
+ import { redactSensitiveText } from "../../runtime-redaction.js";
3
5
  import { buildBrowserProfileConfigRecovery } from "./browser-profile-recovery.js";
4
6
  import { redactModelFacingText } from "./common.js";
5
7
  import { buildAgentBrowserNextActions } from "../action-recommendations.js";
@@ -23,13 +25,11 @@ const KEYBOARD_PRESS_ERROR_HINT = [
23
25
  "Agent-browser keyboard hint: upstream keyboard commands are `keyboard type <text>` and `keyboard inserttext <text>`; `keyboard press` is not a supported subcommand in the targeted upstream version.",
24
26
  'For Enter in text fields, use `keyboard type "\\n"` after focusing the intended control, then verify with a fresh snapshot, URL, or page-state check.',
25
27
  ].join(" ");
26
- function isRecord(value) {
27
- return typeof value === "object" && value !== null;
28
- }
29
28
  function getSelectorRecoveryHint(errorText) {
30
29
  const normalized = errorText.trim();
31
- if (normalized.length === 0)
30
+ if (normalized.length === 0) {
32
31
  return undefined;
32
+ }
33
33
  if (/\bUnknown ref\b|\bstale ref\b|\bref\b.*\b(?:not found|missing|expired)\b/i.test(normalized)) {
34
34
  return STALE_REF_ERROR_HINT;
35
35
  }
@@ -45,90 +45,143 @@ function getSelectorRecoveryHint(errorText) {
45
45
  return undefined;
46
46
  }
47
47
  function getClipboardPermissionHint(commandInfo, errorText) {
48
- if (commandInfo.command !== "clipboard")
48
+ if (commandInfo.command !== "clipboard") {
49
49
  return undefined;
50
+ }
50
51
  if (!/\bNotAllowedError\b|\bclipboard\b.*\bpermission denied\b|\bpermission denied\b.*\bclipboard\b/i.test(errorText)) {
51
52
  return undefined;
52
53
  }
53
54
  return CLIPBOARD_PERMISSION_ERROR_HINT;
54
55
  }
55
56
  function getKeyboardPressHint(commandInfo, errorText) {
56
- if (commandInfo.command !== "keyboard" || commandInfo.subcommand !== "press")
57
+ if (commandInfo.command !== "keyboard" || commandInfo.subcommand !== "press") {
57
58
  return undefined;
58
- if (!/\bunknown\s+subcommand\b|\bvalid options?\b/i.test(errorText))
59
+ }
60
+ if (!/\bunknown\s+subcommand\b|\bvalid options?\b/i.test(errorText)) {
59
61
  return undefined;
62
+ }
60
63
  return KEYBOARD_PRESS_ERROR_HINT;
61
64
  }
62
65
  export function isOverlayBlockedClickError(command, errorText, args) {
63
66
  const tokens = args ? extractUpstreamCommandTokens(args) : [];
64
67
  const action = tokens[0] === "find"
65
- ? tokens[tokens[1] === "nth" ? 4 : 3] ?? "click"
66
- : tokens[0] ?? command;
67
- return action === "click" && errorText !== undefined && /\bis covered by\b[\s\S]*\bat its click point\b/i.test(errorText);
68
+ ? (tokens[tokens[1] === "nth" ? 4 : 3] ?? "click")
69
+ : (tokens[0] ?? command);
70
+ return (action === "click" &&
71
+ errorText !== undefined &&
72
+ /\bis covered by\b[\s\S]*\bat its click point\b/i.test(errorText));
68
73
  }
69
74
  export function redactClipboardPermissionEcho(commandInfo, errorText) {
70
- if (commandInfo.command !== "clipboard")
75
+ if (commandInfo.command !== "clipboard") {
71
76
  return errorText;
77
+ }
72
78
  return errorText
73
79
  .replace(/(\b(?:read|write)\s+permission denied\b(?:\s+for)?\s+)([\s\S]+)$/gi, "$1[REDACTED]")
74
80
  .replace(/(\bFailed to execute '[^']+' on 'Clipboard':\s*)([\s\S]+)$/gi, (match, prefix, suffix) => {
75
- if (!/\bpermission denied\b/i.test(suffix))
81
+ if (!/\bpermission denied\b/i.test(suffix)) {
76
82
  return match;
83
+ }
77
84
  return `${prefix}${suffix.replace(/(\bpermission denied\b(?:\s+for)?\s+)([\s\S]+)$/i, "$1[REDACTED]")}`;
78
85
  });
79
86
  }
80
87
  export function getClipboardWritePayloadCandidates(commandTokens) {
81
- if (commandTokens[0] !== "clipboard" || commandTokens[1] !== "write")
88
+ if (commandTokens[0] !== "clipboard" || commandTokens[1] !== "write") {
82
89
  return [];
90
+ }
83
91
  const payloadTokens = commandTokens.slice(2).filter((value) => value.length > 0);
84
- return [...new Set([...payloadTokens, payloadTokens.join(" ")].filter((value) => value.length > 0))];
92
+ return [
93
+ ...new Set([...payloadTokens, payloadTokens.join(" ")].filter((value) => value.length > 0)),
94
+ ];
85
95
  }
86
96
  function shouldRedactClipboardPayloadField(key, value, payloadCandidates) {
87
97
  return payloadCandidates.some((candidate) => {
88
- if (value === candidate)
98
+ if (value === candidate) {
89
99
  return true;
90
- if (candidate.length < 8 || !/payload|clipboard|argument/i.test(key))
100
+ }
101
+ if (candidate.length < 8 || !/payload|clipboard|argument/i.test(key)) {
91
102
  return false;
103
+ }
92
104
  return value.includes(candidate);
93
105
  });
94
106
  }
95
107
  export function redactClipboardPermissionErrorValue(commandInfo, value, payloadCandidates = []) {
96
- if (commandInfo.command !== "clipboard")
108
+ if (commandInfo.command !== "clipboard") {
97
109
  return value;
98
- if (typeof value === "string")
99
- return payloadCandidates.includes(value) ? "[REDACTED]" : redactClipboardPermissionEcho(commandInfo, value);
100
- if (Array.isArray(value))
110
+ }
111
+ if (typeof value === "string") {
112
+ return payloadCandidates.includes(value)
113
+ ? "[REDACTED]"
114
+ : redactClipboardPermissionEcho(commandInfo, value);
115
+ }
116
+ if (Array.isArray(value)) {
101
117
  return value.map((item) => redactClipboardPermissionErrorValue(commandInfo, item, payloadCandidates));
102
- if (!isRecord(value))
118
+ }
119
+ if (!isRecord(value)) {
103
120
  return value;
121
+ }
104
122
  return Object.fromEntries(Object.entries(value).map(([key, entryValue]) => [
105
123
  key,
106
- typeof entryValue === "string" && shouldRedactClipboardPayloadField(key, entryValue, payloadCandidates)
124
+ typeof entryValue === "string" &&
125
+ shouldRedactClipboardPayloadField(key, entryValue, payloadCandidates)
107
126
  ? "[REDACTED]"
108
127
  : redactClipboardPermissionErrorValue(commandInfo, entryValue, payloadCandidates),
109
128
  ]));
110
129
  }
111
130
  const UNKNOWN_COMMAND_SUGGESTIONS = {
112
- attr: [{ description: "Use `get attr <selector> <name>` to read an attribute from a selector or current `@ref`." }],
131
+ attr: [
132
+ {
133
+ description: "Use `get attr <selector> <name>` to read an attribute from a selector or current `@ref`.",
134
+ },
135
+ ],
113
136
  count: [{ description: "Use `get count <selector>` to count matching elements." }],
114
- html: [{ description: "Use `get html <selector>` to read element HTML from a selector or current `@ref`; use `get html body` when you need whole-page body HTML." }],
115
- text: [{ description: "Use `get text <selector>` to read text from a selector or current `@ref`; run `snapshot -i` first when you need a safe `@ref`." }],
116
- title: [{ args: ["get", "title"], description: "Use `get title` to read the current page title.", id: "use-get-title" }],
117
- url: [{ args: ["get", "url"], description: "Use `get url` to read the current page URL.", id: "use-get-url" }],
118
- value: [{ description: "Use `get value <selector>` to read form control value from a selector or current `@ref`." }],
137
+ html: [
138
+ {
139
+ description: "Use `get html <selector>` to read element HTML from a selector or current `@ref`; use `get html body` when you need whole-page body HTML.",
140
+ },
141
+ ],
142
+ text: [
143
+ {
144
+ description: "Use `get text <selector>` to read text from a selector or current `@ref`; run `snapshot -i` first when you need a safe `@ref`.",
145
+ },
146
+ ],
147
+ title: [
148
+ {
149
+ args: ["get", "title"],
150
+ description: "Use `get title` to read the current page title.",
151
+ id: "use-get-title",
152
+ },
153
+ ],
154
+ url: [
155
+ {
156
+ args: ["get", "url"],
157
+ description: "Use `get url` to read the current page URL.",
158
+ id: "use-get-url",
159
+ },
160
+ ],
161
+ value: [
162
+ {
163
+ description: "Use `get value <selector>` to read form control value from a selector or current `@ref`.",
164
+ },
165
+ ],
119
166
  };
120
167
  function getUnknownCommandSuggestions(command, errorText) {
121
- if (!command)
168
+ if (command === undefined || command.length === 0) {
122
169
  return [];
170
+ }
123
171
  const normalizedCommand = command.trim().toLowerCase();
124
- if (!/\bunknown\s+command\b|\bunknown\s+subcommand\b|\bunrecognized\s+command\b/i.test(errorText))
172
+ if (!/\bunknown\s+command\b|\bunknown\s+subcommand\b|\bunrecognized\s+command\b/i.test(errorText)) {
125
173
  return [];
174
+ }
126
175
  return UNKNOWN_COMMAND_SUGGESTIONS[normalizedCommand] ?? [];
127
176
  }
128
177
  function formatUnknownCommandSuggestionText(suggestions) {
129
- if (suggestions.length === 0)
178
+ if (suggestions.length === 0) {
130
179
  return undefined;
131
- return ["Agent-browser hint: This looks like a getter shortcut, but upstream getter commands are grouped under `get`.", ...suggestions.map((suggestion) => suggestion.description)].join(" ");
180
+ }
181
+ return [
182
+ "Agent-browser hint: This looks like a getter shortcut, but upstream getter commands are grouped under `get`.",
183
+ ...suggestions.map((suggestion) => suggestion.description),
184
+ ].join(" ");
132
185
  }
133
186
  function buildUnknownCommandSuggestionActions(suggestions, sessionName) {
134
187
  const actions = suggestions
@@ -143,10 +196,14 @@ function buildUnknownCommandSuggestionActions(suggestions, sessionName) {
143
196
  return actions.length > 0 ? actions : undefined;
144
197
  }
145
198
  function getLocalhostNavigationHint(commandInfo, errorText) {
146
- if (!commandInfo.command || !isOpenNavigationCommand(commandInfo.command) || !commandInfo.subcommand)
199
+ if (!isOpenNavigationCommand(commandInfo.command) ||
200
+ commandInfo.subcommand === undefined ||
201
+ commandInfo.subcommand.length === 0) {
147
202
  return undefined;
148
- if (!/\bnet::ERR_(?:EMPTY_RESPONSE|CONNECTION_REFUSED|ADDRESS_UNREACHABLE|TIMED_OUT|CONNECTION_RESET)\b/i.test(errorText))
203
+ }
204
+ if (!/\bnet::ERR_(?:EMPTY_RESPONSE|CONNECTION_REFUSED|ADDRESS_UNREACHABLE|TIMED_OUT|CONNECTION_RESET)\b/i.test(errorText)) {
149
205
  return undefined;
206
+ }
150
207
  let targetUrl;
151
208
  try {
152
209
  targetUrl = new URL(commandInfo.subcommand);
@@ -154,8 +211,9 @@ function getLocalhostNavigationHint(commandInfo, errorText) {
154
211
  catch {
155
212
  return undefined;
156
213
  }
157
- if (!["localhost", "127.0.0.1", "::1", "[::1]"].includes(targetUrl.hostname.toLowerCase()))
214
+ if (!["localhost", "127.0.0.1", "::1", "[::1]"].includes(targetUrl.hostname.toLowerCase())) {
158
215
  return undefined;
216
+ }
159
217
  return [
160
218
  "Agent-browser local fixture hint: the browser process could not read a loopback URL from its own network namespace or browser host.",
161
219
  "Verify the server is still running and bound to an address the browser host can reach; if curl works from the shell but browser navigation fails, try the other loopback alias, add a proxy bypass for localhost/127.0.0.1 if a proxy is configured, or use a browser-host-reachable URL.",
@@ -164,29 +222,39 @@ function getLocalhostNavigationHint(commandInfo, errorText) {
164
222
  }
165
223
  export function appendSelectorRecoveryHint(errorText) {
166
224
  const hint = getSelectorRecoveryHint(errorText);
167
- if (!hint || errorText.includes("Agent-browser hint:"))
225
+ if (hint === undefined || hint.length === 0 || errorText.includes("Agent-browser hint:")) {
168
226
  return errorText;
227
+ }
169
228
  return `${errorText}\n\n${hint}`;
170
229
  }
230
+ function buildHintedErrorText(commandInfo, errorText, unknownSuggestion, profileHint) {
231
+ const selectorHinted = appendSelectorRecoveryHint(errorText);
232
+ return [
233
+ selectorHinted,
234
+ unknownSuggestion !== undefined &&
235
+ unknownSuggestion.length > 0 &&
236
+ !selectorHinted.includes("Agent-browser hint:")
237
+ ? unknownSuggestion
238
+ : undefined,
239
+ profileHint,
240
+ getLocalhostNavigationHint(commandInfo, errorText),
241
+ getClipboardPermissionHint(commandInfo, errorText),
242
+ getKeyboardPressHint(commandInfo, errorText),
243
+ ]
244
+ .filter((part) => part !== undefined && part.length > 0)
245
+ .join("\n\n");
246
+ }
171
247
  export function buildErrorPresentation(options) {
172
248
  const { args, commandInfo, errorText, presentationCommand, sessionName } = options;
173
249
  const safeErrorText = redactModelFacingText(redactSensitiveText(redactClipboardPermissionEcho(commandInfo, errorText)));
174
- const selectorHintedErrorText = appendSelectorRecoveryHint(safeErrorText);
175
250
  const unknownCommandSuggestions = getUnknownCommandSuggestions(commandInfo.command, safeErrorText);
176
251
  const unknownCommandSuggestionText = formatUnknownCommandSuggestionText(unknownCommandSuggestions);
177
- const browserProfileConfigRecovery = buildBrowserProfileConfigRecovery({ args, commandInfo, errorText: safeErrorText });
178
- const localhostNavigationHint = getLocalhostNavigationHint(commandInfo, safeErrorText);
179
- const clipboardPermissionHint = getClipboardPermissionHint(commandInfo, safeErrorText);
180
- const keyboardPressHint = getKeyboardPressHint(commandInfo, safeErrorText);
181
- const hintedErrorParts = [
182
- selectorHintedErrorText,
183
- unknownCommandSuggestionText && !selectorHintedErrorText.includes("Agent-browser hint:") ? unknownCommandSuggestionText : undefined,
184
- browserProfileConfigRecovery?.hint,
185
- localhostNavigationHint,
186
- clipboardPermissionHint,
187
- keyboardPressHint,
188
- ].filter((part) => Boolean(part));
189
- const hintedErrorText = hintedErrorParts.join("\n\n");
252
+ const browserProfileConfigRecovery = buildBrowserProfileConfigRecovery({
253
+ args,
254
+ commandInfo,
255
+ errorText: safeErrorText,
256
+ });
257
+ const hintedErrorText = buildHintedErrorText(commandInfo, safeErrorText, unknownCommandSuggestionText, browserProfileConfigRecovery?.hint);
190
258
  const categoryDetails = buildAgentBrowserResultCategoryDetails({
191
259
  args: [commandInfo.command, commandInfo.subcommand].filter((item) => item !== undefined),
192
260
  command: commandInfo.command,
@@ -196,15 +264,17 @@ export function buildErrorPresentation(options) {
196
264
  const nextActions = [
197
265
  ...(buildUnknownCommandSuggestionActions(unknownCommandSuggestions, sessionName) ?? []),
198
266
  ...(browserProfileConfigRecovery?.actions ?? []),
199
- ...(browserProfileConfigRecovery ? [] : buildAgentBrowserNextActions({
200
- args,
201
- command: commandInfo.command,
202
- failureCategory: categoryDetails.failureCategory,
203
- overlayBlockedClick: isOverlayBlockedClickError(presentationCommand ?? commandInfo.command, safeErrorText, args ?? commandInfo.commandTokens),
204
- resultCategory: "failure",
205
- sessionName,
206
- subcommand: commandInfo.subcommand,
207
- }) ?? []),
267
+ ...(browserProfileConfigRecovery
268
+ ? []
269
+ : (buildAgentBrowserNextActions({
270
+ args,
271
+ command: commandInfo.command,
272
+ failureCategory: categoryDetails.failureCategory,
273
+ overlayBlockedClick: isOverlayBlockedClickError(presentationCommand ?? commandInfo.command, safeErrorText, args ?? commandInfo.commandTokens),
274
+ resultCategory: "failure",
275
+ sessionName,
276
+ subcommand: commandInfo.subcommand,
277
+ }) ?? [])),
208
278
  ];
209
279
  return {
210
280
  ...categoryDetails,
@@ -1,29 +1,22 @@
1
- import { writePersistentSessionArtifactFile, writeSecureTempFile, } from "../../temp.js";
2
- import { buildEvictedSessionArtifactEntries } from "../artifact-manifest.js";
3
- import { countLines, truncateText } from "../text.js";
1
+ import { countLines, stringifyUnknown, truncateText } from "../text.js";
4
2
  import { applyArtifactManifest } from "./artifacts.js";
5
- import { getPresentationText, projectAgentBrowserObservation, OBSERVATION_INLINE_MAX_CHARS } from "./content.js";
6
- import { redactModelFacingText, stringifyModelFacing } from "./common.js";
7
- const LARGE_OUTPUT_INLINE_MAX_CHARS = 8_000;
8
- const LARGE_OUTPUT_INLINE_MAX_LINES = 120;
9
- const LARGE_OUTPUT_PREVIEW_MAX_CHARS = 2_500;
10
- const LARGE_OUTPUT_PREVIEW_MAX_LINES = 40;
11
- const LARGE_OUTPUT_PREVIEW_MAX_LINE_CHARS = 240;
12
- const LARGE_OUTPUT_FAILURE_COMMAND_MAX_CHARS = 240;
13
- const LARGE_OUTPUT_FILE_PREFIX = "pi-agent-browser-output";
3
+ import { getPresentationText } from "./content.js";
4
+ import { buildSpillArtifactEntries, writeLargeOutputSpillFile, } from "./output-spill.js";
5
+ export { OBSERVATION_INLINE_MAX_CHARS } from "./content.js";
6
+ export { renderAgentBrowserObservation } from "./observation-rendering.js";
14
7
  function shouldCompactLargeOutput(text) {
15
- return text.length > LARGE_OUTPUT_INLINE_MAX_CHARS || countLines(text) > LARGE_OUTPUT_INLINE_MAX_LINES;
8
+ return text.length > 8_000 || countLines(text) > 120;
16
9
  }
17
10
  function buildLargeOutputPreview(text) {
18
11
  const lines = text.split("\n");
19
12
  const previewLines = [];
20
13
  let previewChars = 0;
21
14
  for (const line of lines) {
22
- if (previewLines.length >= LARGE_OUTPUT_PREVIEW_MAX_LINES || previewChars >= LARGE_OUTPUT_PREVIEW_MAX_CHARS) {
15
+ if (previewLines.length >= 40 || previewChars >= 2_500) {
23
16
  break;
24
17
  }
25
- const remainingChars = LARGE_OUTPUT_PREVIEW_MAX_CHARS - previewChars;
26
- const previewLine = truncateText(line, Math.min(Math.max(40, remainingChars), LARGE_OUTPUT_PREVIEW_MAX_LINE_CHARS));
18
+ const remainingChars = 2_500 - previewChars;
19
+ const previewLine = truncateText(line, Math.min(Math.max(40, remainingChars), 240));
27
20
  previewLines.push(previewLine);
28
21
  previewChars += previewLine.length + 1;
29
22
  }
@@ -34,132 +27,44 @@ function buildLargeOutputPreview(text) {
34
27
  }
35
28
  function buildLargeOutputFailureContext(presentation) {
36
29
  const failure = presentation.batchFailure;
37
- if (!failure)
30
+ if (!failure) {
38
31
  return [];
32
+ }
39
33
  const failedStep = failure.failedStep;
40
- const commandText = truncateText(failedStep.commandText, LARGE_OUTPUT_FAILURE_COMMAND_MAX_CHARS);
34
+ const commandText = truncateText(failedStep.commandText, 240);
41
35
  const lines = [
42
36
  "Failure context:",
43
37
  `- First failing step: ${failedStep.index + 1} — ${commandText}`,
44
38
  `- Batch result: ${failure.successCount}/${failure.totalCount} succeeded${failure.failureCount > 1 ? `; ${failure.failureCount} failed` : ""}`,
45
39
  ];
46
- if (failedStep.failureCategory)
40
+ if (failedStep.failureCategory !== undefined) {
47
41
  lines.push(`- Failure category: ${failedStep.failureCategory}`);
48
- const failureText = (failedStep.text || failedStep.summary).replace(/\s+/g, " ").trim();
49
- if (failureText)
42
+ }
43
+ const failureText = (failedStep.text.length > 0 ? failedStep.text : failedStep.summary)
44
+ .replace(/\s+/g, " ")
45
+ .trim();
46
+ if (failureText.length > 0) {
50
47
  lines.push(`- Failure detail: ${truncateText(failureText, 700)}`);
48
+ }
51
49
  const stepPaths = [failedStep.fullOutputPath, ...(failedStep.fullOutputPaths ?? [])].filter((path, index, paths) => typeof path === "string" && path.length > 0 && paths.indexOf(path) === index);
52
- if (stepPaths.length > 0)
50
+ if (stepPaths.length > 0) {
53
51
  lines.push(`- Failed-step spill path${stepPaths.length === 1 ? "" : "s"}: ${stepPaths.join(", ")}`);
54
- return lines;
55
- }
56
- async function writeLargeOutputSpillFile(options) {
57
- const payload = typeof options.data === "string"
58
- ? redactModelFacingText(options.data)
59
- : typeof options.data === "number" || typeof options.data === "boolean"
60
- ? String(options.data)
61
- : options.data === undefined
62
- ? redactModelFacingText(options.text)
63
- : stringifyModelFacing(options.data);
64
- const isStructuredPayload = typeof options.data !== "string" && typeof options.data !== "number" && typeof options.data !== "boolean";
65
- const fileOptions = {
66
- content: payload,
67
- prefix: LARGE_OUTPUT_FILE_PREFIX,
68
- suffix: isStructuredPayload ? ".json" : ".txt",
69
- };
70
- if (options.persistentArtifactStore) {
71
- const result = await writePersistentSessionArtifactFile({ ...fileOptions, store: options.persistentArtifactStore });
72
- return { ...result, storageScope: "persistent-session" };
73
52
  }
74
- return { evictedArtifacts: [], path: await writeSecureTempFile(fileOptions), storageScope: "process-temp" };
75
- }
76
- function buildSpillArtifactEntries(options) {
77
- const nowMs = Date.now();
78
- return [
79
- {
80
- command: options.commandInfo.command,
81
- createdAtMs: nowMs,
82
- kind: "spill",
83
- path: options.path,
84
- retentionState: options.storageScope === "persistent-session" ? "live" : "ephemeral",
85
- storageScope: options.storageScope,
86
- subcommand: options.commandInfo.subcommand,
87
- },
88
- ...buildEvictedSessionArtifactEntries(options.evictedArtifacts, nowMs),
89
- ];
90
- }
91
- export { OBSERVATION_INLINE_MAX_CHARS } from "./content.js";
92
- /** Bound the final model-visible result, after recovery/diagnostic assembly. Never truncate executable actions. */
93
- export async function renderAgentBrowserObservation(options) {
94
- const observation = projectAgentBrowserObservation(options.details, options.succeeded);
95
- let structuredContent = observation;
96
- const images = options.content.filter(part => part.type === "image");
97
- const prose = options.content.filter(part => part.type === "text").map(part => part.text).join("\n\n");
98
- const { data: _data, error: _error, summary: _summary, ...metadata } = observation;
99
- let text = options.json ? JSON.stringify(observation, null, 2) : `${prose}\n\nObservation: ${JSON.stringify(metadata)}`;
100
- let artifactManifest = options.details.artifactManifest;
101
- if (text.length > OBSERVATION_INLINE_MAX_CHARS || JSON.stringify(observation).length > OBSERVATION_INLINE_MAX_CHARS) {
102
- let spill;
103
- let spillError;
104
- try {
105
- const write = () => writeLargeOutputSpillFile({ data: { ...observation, ...(!options.json ? { text: prose } : {}) }, persistentArtifactStore: options.persistentArtifactStore, text });
106
- spill = await (options.withArtifactWrite ? options.withArtifactWrite(write) : write());
107
- artifactManifest = applyArtifactManifest({ content: [], summary: "" }, artifactManifest, buildSpillArtifactEntries({
108
- commandInfo: { command: typeof options.details.command === "string" ? options.details.command : undefined },
109
- evictedArtifacts: spill.evictedArtifacts, path: spill.path, storageScope: spill.storageScope,
110
- })).artifactManifest;
111
- }
112
- catch (error) {
113
- spillError = error instanceof Error ? error.message : String(error);
114
- }
115
- const compact = {
116
- success: options.succeeded, resultCategory: observation.resultCategory,
117
- failureCategory: observation.failureCategory, successCategory: observation.successCategory,
118
- summary: typeof observation.summary === "string" ? truncateText(observation.summary, 700)
119
- : typeof observation.error === "string" ? truncateText(observation.error, 700) : undefined,
120
- compacted: true,
121
- ...(spill ? { observationPath: spill.path, retrieve: "Read observationPath for the complete redacted observation, including exact recovery actions and requested data." }
122
- : { observationUnavailable: truncateText(redactModelFacingText(spillError ?? "Spill could not be written; request a smaller result."), 1_000) }),
123
- };
124
- for (const key of ["sessionName", "namespace", "codeRun", "error", "failures", "nextActions", "artifactVerification", "imageObservations", "data", "fullOutputPath", "fullOutputPaths"]) {
125
- if (observation[key] !== undefined && JSON.stringify({ ...compact, [key]: observation[key] }, null, 2).length <= OBSERVATION_INLINE_MAX_CHARS - 500)
126
- compact[key] = observation[key];
127
- }
128
- structuredContent = compact;
129
- if (options.preserveContent)
130
- text = prose;
131
- else {
132
- text = JSON.stringify(compact, null, 2);
133
- if (!options.json)
134
- text = `Browser observation compacted.\n${text}`;
135
- }
136
- }
137
- return { content: [{ type: "text", text }, ...images], artifactManifest, structuredContent: JSON.parse(JSON.stringify(structuredContent)) };
53
+ return lines;
138
54
  }
139
- export async function compactLargePresentationOutput(options) {
140
- const text = getPresentationText(options.presentation);
141
- if (text.length === 0 || !shouldCompactLargeOutput(text)) {
142
- return options.presentation;
143
- }
144
- let fullOutputPath;
145
- let spill;
146
- let spillErrorText;
55
+ async function tryWritePresentationSpill(options) {
147
56
  try {
148
- spill = await writeLargeOutputSpillFile({
149
- data: options.data,
150
- persistentArtifactStore: options.persistentArtifactStore,
151
- text,
152
- });
153
- fullOutputPath = spill.path;
57
+ return { spill: await writeLargeOutputSpillFile(options) };
154
58
  }
155
59
  catch (error) {
156
- spillErrorText = error instanceof Error ? error.message : String(error);
60
+ return { error: error instanceof Error ? error.message : stringifyUnknown(error) };
157
61
  }
62
+ }
63
+ function buildCompactedText(command, text, presentation, persisted) {
158
64
  const { omittedLineCount, previewText } = buildLargeOutputPreview(text);
159
- const commandLabel = options.commandInfo.command ?? "agent-browser";
160
- const failureContext = buildLargeOutputFailureContext(options.presentation);
65
+ const failureContext = buildLargeOutputFailureContext(presentation);
161
66
  const lines = [
162
- `Large ${commandLabel} output compacted.`,
67
+ `Large ${command ?? "agent-browser"} output compacted.`,
163
68
  ...(failureContext.length > 0 ? ["", ...failureContext] : []),
164
69
  "",
165
70
  "Preview:",
@@ -168,35 +73,45 @@ export async function compactLargePresentationOutput(options) {
168
73
  if (omittedLineCount > 0) {
169
74
  lines.push(`- ... (${omittedLineCount} additional lines omitted)`);
170
75
  }
171
- lines.push("", fullOutputPath
172
- ? `Full output path: ${fullOutputPath}`
173
- : `Full output unavailable: ${spillErrorText ?? "spill file could not be created."}`);
174
- const firstTextIndex = options.presentation.content.findIndex((part) => part.type === "text");
175
- const compactedText = lines.join("\n");
76
+ lines.push("", persisted.spill
77
+ ? `Full output path: ${persisted.spill.path}`
78
+ : `Full output unavailable: ${persisted.error ?? "spill file could not be created."}`);
79
+ return { compactedText: lines.join("\n"), previewText };
80
+ }
81
+ // The presentation owner supplies its mutable assembly draft; compaction preserves that identity.
82
+ function applyCompactedPresentation(draft, text, rendered, persisted) {
83
+ const firstTextIndex = draft.content.findIndex((part) => part.type === "text");
176
84
  if (firstTextIndex >= 0) {
177
- options.presentation.content[firstTextIndex] = { type: "text", text: compactedText };
85
+ draft.content[firstTextIndex] = { type: "text", text: rendered.compactedText };
178
86
  }
179
87
  else {
180
- options.presentation.content.unshift({ type: "text", text: compactedText });
88
+ draft.content.unshift({ type: "text", text: rendered.compactedText });
181
89
  }
182
- options.presentation.data = {
90
+ draft.data = {
183
91
  compacted: true,
184
- fullOutputPath,
92
+ fullOutputPath: persisted.spill?.path,
185
93
  outputCharCount: text.length,
186
94
  outputLineCount: countLines(text),
187
- previewCharCount: previewText.length,
188
- previewLineCount: countLines(previewText),
189
- spillError: spillErrorText,
95
+ previewCharCount: rendered.previewText.length,
96
+ previewLineCount: countLines(rendered.previewText),
97
+ spillError: persisted.error,
190
98
  };
191
- options.presentation.fullOutputPath = fullOutputPath;
192
- options.presentation.summary = `${options.presentation.summary} (compact)`;
193
- if (fullOutputPath && spill) {
194
- return applyArtifactManifest(options.presentation, options.presentation.artifactManifest ?? options.artifactManifest, buildSpillArtifactEntries({
195
- commandInfo: options.commandInfo,
196
- evictedArtifacts: spill.evictedArtifacts,
197
- path: fullOutputPath,
198
- storageScope: spill.storageScope,
199
- }));
99
+ draft.fullOutputPath = persisted.spill?.path;
100
+ draft.summary = `${draft.summary} (compact)`;
101
+ }
102
+ export async function compactLargePresentationOutput(options) {
103
+ const text = getPresentationText(options.presentation);
104
+ if (text.length === 0 || !shouldCompactLargeOutput(text)) {
105
+ return options.presentation;
200
106
  }
201
- return options.presentation;
107
+ const persisted = await tryWritePresentationSpill({
108
+ data: options.data,
109
+ persistentArtifactStore: options.persistentArtifactStore,
110
+ text,
111
+ });
112
+ const rendered = buildCompactedText(options.commandInfo.command, text, options.presentation, persisted);
113
+ applyCompactedPresentation(options.presentation, text, rendered, persisted);
114
+ return persisted.spill
115
+ ? applyArtifactManifest(options.presentation, options.presentation.artifactManifest ?? options.artifactManifest, buildSpillArtifactEntries({ ...persisted.spill, commandInfo: options.commandInfo }))
116
+ : options.presentation;
202
117
  }