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
@@ -0,0 +1,88 @@
1
+ import { isSensitiveFieldName } from "./redaction-fields.js";
2
+ const SENSITIVE_QUERY_PARAM_PATTERN = /^(?:access(?:_|-)?token|api(?:_|-)?key|auth|authorization|authorization(?:_|-)?session(?:_|-)?id|bearer|client(?:_|-)?secret|code|cookie|id(?:_|-)?token|key|pass(?:word)?|refresh(?:_|-)?token|relay(?:_|-)?state|saml(?:_|-)?request|saml(?:_|-)?response|secret|sentry(?:_|-)?key|session(?:_|-)?id|sig(?:nature)?|token|write(?:_|-)?key)$/i;
3
+ const AUTH_STATE_QUERY_PARAM_PATTERN = /^(?:nonce|state)$/i;
4
+ const AUTH_URL_CONTEXT_PATTERN = /(?:^|[./_-])(?:auth|authorize|callback|login|oauth2?|oidc|saml|sso)(?:[./?#_-]|$)/i;
5
+ function shouldRedactQueryParam(name) {
6
+ return SENSITIVE_QUERY_PARAM_PATTERN.test(name) || isSensitiveFieldName(name);
7
+ }
8
+ function isSensitiveParameter(name, authContext) {
9
+ return shouldRedactQueryParam(name) || (authContext && AUTH_STATE_QUERY_PARAM_PATTERN.test(name));
10
+ }
11
+ function redactParameters(params, authContext) {
12
+ let mutated = false;
13
+ for (const [name] of params) {
14
+ if (isSensitiveParameter(name, authContext)) {
15
+ params.set(name, "[REDACTED]");
16
+ mutated = true;
17
+ }
18
+ }
19
+ return mutated;
20
+ }
21
+ function getHashParameters(hash) {
22
+ const text = hash.startsWith("#") ? hash.slice(1) : hash;
23
+ return text.includes("=") ? new URLSearchParams(text) : undefined;
24
+ }
25
+ export function redactUrlToken(token) {
26
+ let parsed;
27
+ try {
28
+ parsed = new URL(token);
29
+ }
30
+ catch {
31
+ return token;
32
+ }
33
+ const originalHref = parsed.href;
34
+ if (parsed.username.length > 0) {
35
+ parsed.username = "[REDACTED]";
36
+ }
37
+ if (parsed.password.length > 0) {
38
+ parsed.password = "[REDACTED]";
39
+ }
40
+ const hashParams = getHashParameters(parsed.hash);
41
+ const authContext = AUTH_URL_CONTEXT_PATTERN.test(`${parsed.hostname}${parsed.pathname}`) ||
42
+ [...parsed.searchParams.keys(), ...(hashParams?.keys() ?? [])].some(shouldRedactQueryParam);
43
+ redactParameters(parsed.searchParams, authContext);
44
+ if (hashParams && redactParameters(hashParams, authContext)) {
45
+ parsed.hash = `#${hashParams.toString()}`;
46
+ }
47
+ return parsed.href === originalHref ? token : parsed.href;
48
+ }
49
+ function decodeParameterName(raw) {
50
+ try {
51
+ return decodeURIComponent(raw.replace(/\+/g, " "));
52
+ }
53
+ catch {
54
+ return raw;
55
+ }
56
+ }
57
+ function redactLooseUrlParameterText(text) {
58
+ return text.replace(/(?<![^\s"'`<>\])}])[^\s"'`<>\])}]*[?#&][^\s"'`<>\])}]*/g, (token) => {
59
+ const queryNames = [...token.matchAll(/[?#&]([^=&#\s"'`<>\])}]+)=/g)].map((match) => decodeParameterName(match[1]));
60
+ const authContext = AUTH_URL_CONTEXT_PATTERN.test(token) || queryNames.some(shouldRedactQueryParam);
61
+ return token.replace(/([?#&])([^=&#\s"'`<>\])}]+)=([^&#\s"'`<>\])}]*)/g, (match, separator, rawName, rawValue) => {
62
+ if (rawValue === "[REDACTED" ||
63
+ rawValue === "[REDACTED]" ||
64
+ /%5Bredacted%5D/i.test(rawValue)) {
65
+ return match;
66
+ }
67
+ if (!isSensitiveParameter(decodeParameterName(rawName), authContext)) {
68
+ return match;
69
+ }
70
+ return `${separator}${rawName}=[REDACTED]`;
71
+ });
72
+ });
73
+ }
74
+ function redactLooseUrlUserinfo(text) {
75
+ return text.replace(/\b([A-Za-z][A-Za-z0-9+.-]*:\/\/)([^\s"'`/@]+)@([^\s"'`]+)/g, (match, prefix, userinfo, suffix) => {
76
+ if (/%5Bredacted%5D/i.test(userinfo)) {
77
+ return match;
78
+ }
79
+ if (userinfo.includes("[REDACTED]")) {
80
+ return redactLooseUrlParameterText(match);
81
+ }
82
+ return redactLooseUrlParameterText(`${prefix}${userinfo.includes(":") ? "[REDACTED]:[REDACTED]" : "[REDACTED]"}@${suffix}`);
83
+ });
84
+ }
85
+ export function redactLooseUrls(text) {
86
+ const urls = text.replace(/\b[A-Za-z][A-Za-z0-9+.-]*:\/\/[^\s"'`<>\])]+/g, (match) => redactUrlToken(match));
87
+ return redactLooseUrlParameterText(redactLooseUrlUserinfo(urls));
88
+ }
@@ -1,281 +1,38 @@
1
1
  import { isOpenNavigationCommand, isPageMutationCommand } from "../command-taxonomy.js";
2
- import { isPendingRecordingArtifact } from "./artifact-manifest.js";
3
- import { applySessionToNextActions, buildInspectOverlayStateAction, buildNextToolAction } from "./next-actions.js";
4
- import { AGENT_BROWSER_RECOVERY_NEXT_ACTION_IDS, buildRecoveryNextActions, } from "./recovery-actions.js";
5
- function buildArtifactAction(path) {
6
- return {
7
- artifactPath: path,
8
- id: "use-saved-artifact",
9
- reason: "Use the saved artifact path from the structured result instead of scraping it from text.",
10
- safety: "Verify artifact metadata such as exists/status before treating the file as durable.",
11
- tool: "agent_browser",
12
- };
13
- }
14
- function buildArtifactVerificationAction(artifact) {
15
- return {
16
- artifactPath: artifact.path,
17
- id: "verify-artifact-path",
18
- reason: "The wrapper has artifact metadata but did not verify this file as present on disk.",
19
- safety: "Check details.artifactVerification and the filesystem before treating the artifact as durable.",
20
- tool: "agent_browser",
21
- };
22
- }
23
- function buildElectronToolAction(options) {
24
- return {
25
- id: options.id,
26
- params: { action: options.action, launchId: options.launchId },
27
- reason: options.reason,
28
- ...(options.safety ? { safety: options.safety } : {}),
29
- tool: "agent_browser_electron",
30
- };
31
- }
32
- function getDownloadRetryPath(args, fallback) {
33
- if (fallback)
34
- return fallback;
35
- if (!args || args.length === 0)
36
- return undefined;
37
- const downloadFlagIndex = args.indexOf("--download");
38
- if (downloadFlagIndex >= 0) {
39
- const candidate = args[downloadFlagIndex + 1];
40
- return candidate && !candidate.startsWith("-") ? candidate : undefined;
41
- }
42
- const downloadCommandIndex = args.indexOf("download");
43
- if (downloadCommandIndex >= 0 && args.length > downloadCommandIndex + 2) {
44
- return args[args.length - 1];
45
- }
46
- return undefined;
47
- }
48
- export function buildAgentBrowserNextActions(options) {
49
- const actions = [];
50
- if (options.recovery) {
51
- actions.push(...buildRecoveryNextActions(options.recovery));
52
- }
53
- if (options.electron?.launchId) {
54
- const { launchId, sessionName, status } = options.electron;
55
- if (options.resultCategory === "success" && status !== "cleaned") {
56
- actions.push(buildElectronToolAction({
57
- action: "status",
58
- id: "status-electron-launch",
59
- launchId,
60
- reason: "Check the wrapper-tracked Electron launch liveness and current CDP targets without mutating the app.",
61
- }), buildElectronToolAction({
62
- action: "probe",
63
- id: "probe-electron-launch",
64
- launchId,
65
- reason: "Probe the attached Electron managed session and carry the wrapper launchId for follow-up diagnostics.",
66
- }), buildElectronToolAction({
67
- action: "cleanup",
68
- id: "cleanup-electron-launch",
69
- launchId,
70
- reason: "Clean the wrapper-owned Electron process and isolated userDataDir when the run is complete.",
71
- safety: "Only operates on the launchId created by electron.launch; explicit artifacts and manually launched apps remain host-owned.",
72
- }));
73
- if (sessionName) {
74
- actions.push(buildNextToolAction({
75
- args: ["--session", sessionName, "tab", "list"],
76
- id: "list-electron-tabs",
77
- reason: "Inspect attached Electron page/webview targets before choosing the active tab.",
78
- }), buildNextToolAction({
79
- args: ["--session", sessionName, "snapshot", "-i"],
80
- id: "snapshot-electron-session",
81
- reason: "Refresh interactive refs for the attached Electron session.",
82
- safety: "Use current Electron refs only after a fresh snapshot for this session.",
83
- }));
84
- }
85
- }
86
- else if (options.resultCategory === "failure" && options.failureCategory === "cleanup-failed") {
87
- actions.push(buildElectronToolAction({
88
- action: "status",
89
- id: "status-electron-launch",
90
- launchId,
91
- reason: "Inspect which wrapper-tracked Electron resources remain after partial cleanup.",
92
- }), buildElectronToolAction({
93
- action: "cleanup",
94
- id: "retry-electron-cleanup",
95
- launchId,
96
- reason: "Retry cleanup for the same wrapper-owned Electron launch after reviewing remaining resources.",
97
- safety: "Only retry for the same launchId; do not use cleanup for manually launched Electron apps.",
98
- }));
99
- }
100
- }
101
- if (options.resultCategory === "success") {
102
- if (isOpenNavigationCommand(options.command)) {
103
- actions.push(buildNextToolAction({
2
+ import { applySessionToNextActions, buildNextToolAction } from "./next-actions.js";
3
+ import { buildRecoveryNextActions } from "./recovery-actions.js";
4
+ import { buildElectronNextActions } from "./electron-recommendations.js";
5
+ import { buildPendingRecordingNextActions, buildSavedArtifactNextActions, } from "./artifact-recommendations.js";
6
+ import { buildFailureNextActions } from "./failure-recommendations.js";
7
+ function buildSuccessNavigationActions(options) {
8
+ if (isOpenNavigationCommand(options.command)) {
9
+ return [
10
+ buildNextToolAction({
104
11
  args: ["snapshot", "-i"],
105
12
  id: "inspect-opened-page",
106
13
  reason: "Inspect the opened page before choosing interactive refs.",
107
- }));
108
- }
109
- else if (isPageMutationCommand(options.command, options.subcommand)) {
110
- actions.push(buildNextToolAction({
14
+ }),
15
+ ];
16
+ }
17
+ return isPageMutationCommand(options.command, options.subcommand)
18
+ ? [
19
+ buildNextToolAction({
111
20
  args: ["snapshot", "-i"],
112
21
  id: "inspect-after-mutation",
113
22
  reason: "Refresh interactive refs after a browser mutation, navigation, scroll, or rerender.",
114
23
  safety: "Do not reuse prior @refs until a fresh snapshot confirms they still exist.",
115
- }));
116
- }
117
- const artifacts = options.artifacts ?? [];
118
- const savedFileArtifact = options.savedFilePath ? artifacts.find((artifact) => artifact.path === options.savedFilePath) : undefined;
119
- if (options.savedFilePath && savedFileArtifact?.exists !== false) {
120
- actions.push(buildArtifactAction(options.savedFilePath));
121
- }
122
- for (const artifact of artifacts) {
123
- if (isPendingRecordingArtifact(artifact))
124
- continue;
125
- if (artifact.exists === false) {
126
- if (artifact.kind === "download") {
127
- actions.push(buildNextToolAction({
128
- args: ["wait", "--download", artifact.path],
129
- id: "wait-for-download",
130
- reason: "Upstream reported a download path, but the wrapper did not verify the file on disk.",
131
- safety: "Use an explicit wait timeout; if you set top-level timeoutMs, keep it above the wait duration plus a small grace window.",
132
- }));
133
- }
134
- else {
135
- actions.push(buildArtifactVerificationAction(artifact));
136
- }
137
- continue;
138
- }
139
- if (artifact.path !== options.savedFilePath) {
140
- actions.push(buildArtifactAction(artifact.path));
141
- }
142
- }
143
- }
144
- else {
145
- switch (options.failureCategory) {
146
- case "artifact-missing":
147
- for (const artifact of options.artifacts ?? []) {
148
- if (isPendingRecordingArtifact(artifact) || (artifact.exists !== false && artifact.status !== "stale"))
149
- continue;
150
- if (artifact.kind === "download") {
151
- actions.push(buildNextToolAction({
152
- args: ["wait", "--download", artifact.path],
153
- id: "wait-for-download",
154
- reason: "The requested download artifact was not found on disk after upstream reported completion.",
155
- safety: "Use an explicit wait timeout; if you set top-level timeoutMs, keep it above the wait duration plus a small grace window.",
156
- }));
157
- }
158
- else {
159
- actions.push(buildArtifactVerificationAction(artifact));
160
- }
161
- }
162
- break;
163
- case "confirmation-required":
164
- if (options.confirmationId) {
165
- actions.push(buildNextToolAction({
166
- args: ["confirm", options.confirmationId],
167
- id: "approve-confirmation",
168
- reason: "Approve the pending upstream confirmation when the requested action is safe.",
169
- safety: "Only confirm after reviewing the guarded action shown in the result.",
170
- }), buildNextToolAction({
171
- args: ["deny", options.confirmationId],
172
- id: "deny-confirmation",
173
- reason: "Deny the pending upstream confirmation when the guarded action is unsafe or unintended.",
174
- }));
175
- }
176
- break;
177
- case "stale-ref":
178
- case "selector-not-found":
179
- case "selector-unsupported":
180
- actions.push(buildNextToolAction({
181
- args: ["snapshot", "-i"],
182
- id: "refresh-interactive-refs",
183
- reason: "Get current interactive refs before retrying the element action.",
184
- safety: "Prefer a current @ref or a stable find locator; do not retry stale refs blindly.",
185
- }));
186
- break;
187
- case "download-not-verified":
188
- {
189
- const retryPath = getDownloadRetryPath(options.args, options.savedFilePath);
190
- actions.push(buildNextToolAction({
191
- args: retryPath ? ["wait", "--download", retryPath] : ["wait", "--download"],
192
- id: "wait-for-download",
193
- reason: "Wait for the browser download and let the wrapper verify saved-file metadata.",
194
- safety: "Use an explicit wait timeout; if you set top-level timeoutMs, keep it above the wait duration plus a small grace window.",
195
- }));
196
- }
197
- break;
198
- case "timeout":
199
- {
200
- if (options.command === "session" && options.subcommand === "info") {
201
- actions.push(buildNextToolAction({
202
- args: ["session", "info"],
203
- id: "retry-session-info",
204
- reason: "Retry the same session status check without opening a browser or inspecting its page.",
205
- }));
206
- break;
207
- }
208
- const textAssertion = options.command === "wait" && options.args?.includes("--text") === true;
209
- const urlAssertion = options.command === "wait" && options.args?.includes("--url") === true;
210
- actions.push(buildNextToolAction({
211
- args: ["snapshot", "-i"],
212
- id: textAssertion ? "inspect-after-text-assertion-failure" : "inspect-after-timeout",
213
- reason: textAssertion
214
- ? "Inspect the current page after the text assertion failed before concluding the expected text is absent."
215
- : options.command === "wait"
216
- ? "Inspect the current page after the wait condition timed out before retrying with a different selector or timeout."
217
- : "Inspect the current page after the timed-out browser operation.",
218
- safety: textAssertion
219
- ? "Read-only snapshot; use current refs or visible text from this page before retrying the assertion."
220
- : "Read-only snapshot; do not assume the timed-out interaction completed.",
221
- }));
222
- if (urlAssertion) {
223
- actions.push(buildNextToolAction({
224
- args: ["open", "about:blank"],
225
- id: "fresh-session-after-url-wait-timeout",
226
- reason: "If a preceding click or form submit reported success but the page never navigated, upstream click dispatch may have silently missed (observed with agent-browser 0.34 after many spaced commands); replace about:blank with the target URL and replay the flow as one batch in a fresh session instead of retrying the wait.",
227
- safety: "Abandons the current browser session; capture page evidence with the inspect action first, and only abandon when the wait target is not simply wrong or slow.",
228
- sessionMode: "fresh",
229
- }));
230
- }
231
- }
232
- break;
233
- case "upstream-error":
234
- if (options.overlayBlockedClick) {
235
- actions.push(buildInspectOverlayStateAction(options.sessionName));
236
- }
237
- else if (isOpenNavigationCommand(options.command)) {
238
- actions.push(buildNextToolAction({
239
- args: ["get", "url"],
240
- id: "inspect-page-after-navigation-error",
241
- reason: "Check which page, if any, remains active after the navigation or network error.",
242
- safety: "Read-only URL inspection; verify connectivity and the target URL before retrying navigation.",
243
- }));
244
- }
245
- break;
246
- case "tab-gone":
247
- actions.push(buildNextToolAction({
248
- args: ["tab", "list"],
249
- id: AGENT_BROWSER_RECOVERY_NEXT_ACTION_IDS.tabGoneListTabs,
250
- reason: "The pinned bound tab is gone; inspect remaining tabs before acting on a neighbor.",
251
- safety: "Read-only. Prefer a listed tab id, label, or CDP targetId, or open a new tab to rebind.",
252
- }), buildNextToolAction({
253
- args: ["tab", "new"],
254
- id: AGENT_BROWSER_RECOVERY_NEXT_ACTION_IDS.tabGoneNewTab,
255
- reason: "Bind a fresh tab after tab_gone instead of continuing on another session's page.",
256
- safety: "Opens a new tab in this session and rebinds the pin; pass a URL if you know the intended page.",
257
- }));
258
- break;
259
- case "tab-drift":
260
- if (options.recovery?.kind === "about-blank" || options.recovery?.kind === "tab-drift") {
261
- break;
262
- }
263
- actions.push(buildNextToolAction({
264
- args: ["tab", "list"],
265
- id: AGENT_BROWSER_RECOVERY_NEXT_ACTION_IDS.genericTabDriftListTabs,
266
- reason: "Inspect available tabs before selecting the intended target.",
267
- safety: "Read-only. Retry snapshot only after selecting or confirming the intended stable tab.",
268
- }));
269
- break;
270
- }
271
- }
272
- if ((options.artifacts ?? []).some(isPendingRecordingArtifact)) {
273
- actions.push(buildNextToolAction({
274
- args: ["record", "stop"],
275
- id: "stop-pending-recording",
276
- reason: "Stop the active recording so the requested video can be finalized and verified on disk.",
277
- safety: "The file remains pending until record stop succeeds; verify details.artifactVerification afterward.",
278
- }));
279
- }
24
+ }),
25
+ ]
26
+ : [];
27
+ }
28
+ export function buildAgentBrowserNextActions(options) {
29
+ const actions = [
30
+ ...(options.recovery ? buildRecoveryNextActions(options.recovery) : []),
31
+ ...buildElectronNextActions(options),
32
+ ...(options.resultCategory === "success"
33
+ ? [...buildSuccessNavigationActions(options), ...buildSavedArtifactNextActions(options)]
34
+ : buildFailureNextActions(options)),
35
+ ...buildPendingRecordingNextActions(options.artifacts),
36
+ ];
280
37
  return applySessionToNextActions(actions.length > 0 ? actions : undefined, options.sessionName);
281
38
  }
@@ -0,0 +1,133 @@
1
+ import { isRecord } from "../parsing.js";
2
+ function finiteNonnegative(value) {
3
+ return typeof value === "number" && Number.isFinite(value) && value >= 0;
4
+ }
5
+ function safeCount(value) {
6
+ return finiteNonnegative(value) && Number.isSafeInteger(value);
7
+ }
8
+ function optionalStrings(value, keys) {
9
+ return keys.every((key) => value[key] === undefined || typeof value[key] === "string");
10
+ }
11
+ function nullableStrings(value, keys) {
12
+ return keys.every((key) => value[key] === null || typeof value[key] === "string");
13
+ }
14
+ function nullableNumbers(value, keys) {
15
+ return keys.every((key) => value[key] === null || finiteNonnegative(value[key]));
16
+ }
17
+ function nullableBoolean(value) {
18
+ return value === null || typeof value === "boolean";
19
+ }
20
+ function captureIsValid(value) {
21
+ return (nullableStrings(value, [
22
+ "startedAt",
23
+ "endedAt",
24
+ "firstFrameAt",
25
+ "lastFrameAt",
26
+ "timestampSource",
27
+ ]) &&
28
+ nullableNumbers(value, [
29
+ "durationMs",
30
+ "firstFrameAfterMs",
31
+ "lastFrameAfterMs",
32
+ "averageFps",
33
+ "maxFrameGapMs",
34
+ ]));
35
+ }
36
+ function outputIsValid(value) {
37
+ return (nullableStrings(value, ["durationSource"]) &&
38
+ nullableNumbers(value, [
39
+ "frames",
40
+ "fps",
41
+ "encodedFrames",
42
+ "durationMs",
43
+ "heldFrames",
44
+ "droppedFrames",
45
+ "skippedFrames",
46
+ ]) &&
47
+ nullableBoolean(value.encoderSucceeded));
48
+ }
49
+ function recordingIsValid(value) {
50
+ if (!isRecord(value) ||
51
+ !isRecord(value.capture) ||
52
+ !isRecord(value.output) ||
53
+ !isRecord(value.file)) {
54
+ return false;
55
+ }
56
+ return (recordingScalarsAreValid(value) &&
57
+ captureIsValid(value.capture) &&
58
+ outputIsValid(value.output) &&
59
+ nullableBoolean(value.file.exists) &&
60
+ nullableNumbers(value.file, ["sizeBytes"]));
61
+ }
62
+ function recordingScalarsAreValid(value) {
63
+ return (typeof value.warning === "string" &&
64
+ typeof value.path === "string" &&
65
+ nullableStrings(value, ["recordingId", "error"]) &&
66
+ nullableBoolean(value.success) &&
67
+ nullableNumbers(value, ["frames", "capturedFrames", "fps"]));
68
+ }
69
+ function optionalNumbersAreValid(value) {
70
+ return (["evictedAtMs", "recordingStartedAtMs"].every((key) => value[key] === undefined || (typeof value[key] === "number" && Number.isFinite(value[key]))) &&
71
+ (value.sizeBytes === undefined || finiteNonnegative(value.sizeBytes)));
72
+ }
73
+ function optionalRecordingIsValid(value) {
74
+ return ((value.recordingState === undefined || value.recordingState === "openRecording") &&
75
+ (value.recording === undefined || recordingIsValid(value.recording)) &&
76
+ (value.status === undefined ||
77
+ [
78
+ "failed",
79
+ "missing",
80
+ "pending",
81
+ "repaired-from-temp",
82
+ "saved",
83
+ "stale",
84
+ "unverified",
85
+ "upstream-temp-only",
86
+ ].some((status) => status === value.status)));
87
+ }
88
+ function optionalEvidenceIsValid(value) {
89
+ return (optionalStrings(value, [
90
+ "absolutePath",
91
+ "command",
92
+ "cwd",
93
+ "extension",
94
+ "mediaType",
95
+ "namespace",
96
+ "requestedPath",
97
+ "session",
98
+ "subcommand",
99
+ ]) &&
100
+ (value.exists === undefined || typeof value.exists === "boolean") &&
101
+ optionalNumbersAreValid(value) &&
102
+ optionalRecordingIsValid(value));
103
+ }
104
+ function isManifestEntry(value) {
105
+ if (!isRecord(value)) {
106
+ return false;
107
+ }
108
+ return (typeof value.path === "string" &&
109
+ value.path.trim().length > 0 &&
110
+ typeof value.createdAtMs === "number" &&
111
+ Number.isFinite(value.createdAtMs) &&
112
+ ["evicted", "ephemeral", "live", "missing"].some((state) => state === value.retentionState) &&
113
+ ["explicit-path", "persistent-session", "process-temp"].some((scope) => scope === value.storageScope) &&
114
+ ["download", "file", "har", "image", "pdf", "profile", "trace", "video", "spill"].some((kind) => kind === value.kind) &&
115
+ optionalEvidenceIsValid(value));
116
+ }
117
+ function manifestCountsAreValid(value) {
118
+ return (safeCount(value.maxEntries) &&
119
+ value.maxEntries !== 0 &&
120
+ safeCount(value.liveCount) &&
121
+ safeCount(value.evictedCount));
122
+ }
123
+ export function isSessionArtifactManifest(value) {
124
+ if (!isRecord(value)) {
125
+ return false;
126
+ }
127
+ return (value.version === 1 &&
128
+ Array.isArray(value.entries) &&
129
+ value.entries.every(isManifestEntry) &&
130
+ typeof value.updatedAtMs === "number" &&
131
+ Number.isFinite(value.updatedAtMs) &&
132
+ manifestCountsAreValid(value));
133
+ }