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,303 @@
1
+ import { format } from "node:util";
2
+ import { extractUpstreamCommandTokens, isPlainTextInspectionArgs } from "../runtime.js";
3
+ import { extractExplicitSessionName, resolveAgentBrowserNamespace, scanUpstreamGlobalFlagOccurrences, } from "../argv-grammar.js";
4
+ import { parseArgvDescriptor } from "../argv-descriptor.js";
5
+ import { needsManagedSession } from "../command-policy.js";
6
+ import { isRecord } from "../parsing.js";
7
+ import { getAgentBrowserProcessTimeoutMs } from "../process.js";
8
+ import { getCommandAwareProcessTimeoutMs } from "./browser-run/prepare/wait-timeouts.js";
9
+ import { getAgentBrowserProcessEnvironment } from "../process-environment.js";
10
+ import { withNativeSessionDefaults } from "./native-session-defaults.js";
11
+ import { getBrowserCwdError, resolveExecutionCwd } from "../execution-cwd.js";
12
+ import { resolveOperationPaths } from "./operation-paths.js";
13
+ import { isCloseCommand } from "../command-taxonomy.js";
14
+ import { getSessionContextKey } from "./browser-run/session-state.js";
15
+ import { buildValidationFailureResult, resolveAgentBrowserInput, } from "./input-plan.js";
16
+ import { applyAgentBrowserOutputPath } from "./output-file.js";
17
+ import { loadAgentBrowserConfigSync } from "../config.js";
18
+ import { scopeReadConfirmationArgs } from "../read-confirmation.js";
19
+ import { getArtifactPreflightValidationError, commandClosesAllSessions, } from "./extension-artifact-preflight.js";
20
+ import { browserExecutionFailure } from "./extension-result-state.js";
21
+ import { shouldSerializeBrowserCommand } from "./extension-managed-ownership.js";
22
+ import { shouldSerializeElectronHostInput } from "./extension-electron-ownership.js";
23
+ import { shouldIncludeProjectConfig } from "./extension-prompt.js";
24
+ import { validateUpstreamVersion } from "./extension-version-check.js";
25
+ import { applyUnserializedOutputPath } from "./extension-command-output.js";
26
+ import { runCoordinatedElectronHostInput } from "./extension-host-coordination.js";
27
+ import { runWithinSessionQueue } from "./extension-execution-queue.js";
28
+ function validationFailure(input, validationError) {
29
+ return buildValidationFailureResult({
30
+ ...input,
31
+ attemptedKind: input.kind,
32
+ kind: "invalid",
33
+ status: "invalid",
34
+ validationError,
35
+ });
36
+ }
37
+ // tool_call hooks can mutate input before the canonical input planner validates it.
38
+ function requestedOutputPath(params) {
39
+ return isRecord(params) && typeof params.outputPath === "string" ? params.outputPath : undefined;
40
+ }
41
+ function operationTimeout(call, input) {
42
+ const electronTimeout = input.kind === "electron" && "timeoutMs" in input.compiledElectron
43
+ ? input.compiledElectron.timeoutMs
44
+ : undefined;
45
+ return (electronTimeout ??
46
+ call.params.timeoutMs ??
47
+ getCommandAwareProcessTimeoutMs(extractUpstreamCommandTokens(input.toolArgs), input.toolStdin) ??
48
+ getAgentBrowserProcessTimeoutMs());
49
+ }
50
+ class BrowserAdmission {
51
+ runtime;
52
+ invocation;
53
+ constructor(runtime, invocation) {
54
+ this.runtime = runtime;
55
+ this.invocation = invocation;
56
+ }
57
+ admit() {
58
+ const { runtime, invocation } = this;
59
+ const branch = invocation.selectedBranch ?? runtime.branch.capture(invocation.ctx);
60
+ let operationCwd;
61
+ try {
62
+ operationCwd = invocation.capturedCwd ?? resolveExecutionCwd(runtime.pi, invocation.ctx);
63
+ }
64
+ catch (error) {
65
+ return {
66
+ failure: buildValidationFailureResult({
67
+ kind: "invalid",
68
+ status: "invalid",
69
+ redactedArgs: [],
70
+ toolArgs: [],
71
+ validationError: error instanceof Error ? error.message : format("%s", error),
72
+ }),
73
+ };
74
+ }
75
+ return this.validateInvocation(branch, operationCwd);
76
+ }
77
+ validateInvocation(branch, operationCwd) {
78
+ const { runtime, invocation } = this;
79
+ const promptPolicy = runtime.prompt.policy(invocation.ctx);
80
+ const outputPath = requestedOutputPath(invocation.params);
81
+ const input = resolveAgentBrowserInput({
82
+ getBatchPreflightValidationError: (args, stdin) => getArtifactPreflightValidationError({ args, cwd: operationCwd, outputPath, stdin }),
83
+ params: invocation.params,
84
+ });
85
+ if (input.status === "invalid") {
86
+ return { failure: buildValidationFailureResult(input) };
87
+ }
88
+ const replayError = this.replayFailure(input);
89
+ if (replayError) {
90
+ return { failure: replayError };
91
+ }
92
+ const explicitConfig = scanUpstreamGlobalFlagOccurrences(input.toolArgs, "--config").length > 0 ||
93
+ getAgentBrowserProcessEnvironment().AGENT_BROWSER_CONFIG !== undefined;
94
+ const session = extractExplicitSessionName(input.toolArgs);
95
+ const managedAtAdmission = input.kind !== "electron" && (session === undefined || session === "") && !explicitConfig;
96
+ return {
97
+ call: {
98
+ ...invocation,
99
+ branch,
100
+ operationCwd,
101
+ promptPolicy,
102
+ outputPath,
103
+ admittedInput: input,
104
+ explicitConfig,
105
+ managedAtAdmission,
106
+ },
107
+ };
108
+ }
109
+ replayFailure(input) {
110
+ const error = this.runtime.branch.replayError;
111
+ if (error === undefined || error === "" || isPlainTextInspectionArgs(input.toolArgs)) {
112
+ return undefined;
113
+ }
114
+ return browserExecutionFailure(new Error(error), this.invocation.signal, "validation-error");
115
+ }
116
+ selectBrowserCwd(call) {
117
+ const session = extractExplicitSessionName(call.admittedInput.toolArgs);
118
+ if (call.explicitConfig) {
119
+ return call.operationCwd;
120
+ }
121
+ if (session !== undefined && session !== "") {
122
+ const namespace = resolveAgentBrowserNamespace(call.admittedInput.toolArgs, getAgentBrowserProcessEnvironment().AGENT_BROWSER_NAMESPACE);
123
+ return (this.runtime.managed.owned.get(getSessionContextKey(session, namespace) ?? session)?.cwd ??
124
+ call.ctx.cwd);
125
+ }
126
+ if (call.params.sessionMode === "fresh") {
127
+ return call.operationCwd;
128
+ }
129
+ return this.runtime.managed.active ? this.runtime.managed.cwd : call.ctx.cwd;
130
+ }
131
+ prepare(call) {
132
+ const browserCwd = this.selectBrowserCwd(call);
133
+ const input = call.admittedInput;
134
+ const error = input.kind === "electron" ? undefined : getBrowserCwdError(browserCwd);
135
+ if (error !== undefined && error !== "") {
136
+ return { failure: validationFailure(input, error) };
137
+ }
138
+ const resolvedInput = this.bindOperationPaths(call, browserCwd);
139
+ return {
140
+ call: {
141
+ ...call,
142
+ browserCwd,
143
+ resolvedInput,
144
+ executionTimeoutMs: operationTimeout(call, resolvedInput),
145
+ },
146
+ };
147
+ }
148
+ bindOperationPaths(call, browserCwd) {
149
+ const input = call.admittedInput;
150
+ if (isPlainTextInspectionArgs(input.toolArgs) ||
151
+ (call.operationCwd === browserCwd && call.operationCwd === call.ctx.cwd)) {
152
+ return input;
153
+ }
154
+ const bound = resolveOperationPaths(input.toolArgs, input.toolStdin, call.operationCwd);
155
+ return { ...input, toolArgs: bound.args, toolStdin: bound.stdin };
156
+ }
157
+ canSelectNativeRoot(call) {
158
+ if (this.runtime.managed.active ||
159
+ this.runtime.managed.freshOrdinal > 0 ||
160
+ call.params.sessionMode === "fresh") {
161
+ return false;
162
+ }
163
+ return (this.runtime.sessions.pages.findReadConfirmation([...call.resolvedInput.toolArgs], resolveAgentBrowserNamespace(call.resolvedInput.toolArgs, getAgentBrowserProcessEnvironment().AGENT_BROWSER_NAMESPACE), call.resolvedInput.toolStdin) === undefined);
164
+ }
165
+ nativeRoot(call, config) {
166
+ if (!this.canSelectNativeRoot(call)) {
167
+ return undefined;
168
+ }
169
+ const root = process.env.PI_SUBAGENT_ROOT_SESSION_ID;
170
+ const id = process.env.PI_SUBAGENT_CHILD === "1" && root !== undefined && root !== ""
171
+ ? root
172
+ : call.ctx.sessionManager.getSessionId();
173
+ const profile = config.trustedBrowserDefaultProfile;
174
+ return {
175
+ id,
176
+ profile: profile?.policy === "always" && !/[\\/~]/.test(profile.name) ? profile.name : undefined,
177
+ executablePath: config.trustedBrowserExecutablePath,
178
+ };
179
+ }
180
+ async executeAdmitted(admitted) {
181
+ const prepared = this.prepare(admitted);
182
+ if ("failure" in prepared) {
183
+ return prepared.failure;
184
+ }
185
+ const { call } = prepared;
186
+ await this.runtime.beforeExecute?.(call.nativeToolCallId, { ...call.ctx, signal: call.signal });
187
+ const config = loadAgentBrowserConfigSync({
188
+ cwd: call.ctx.cwd,
189
+ includeProjectConfig: shouldIncludeProjectConfig(call.ctx),
190
+ });
191
+ return withNativeSessionDefaults(call.resolvedInput, { cwd: call.browserCwd, signal: call.signal, root: this.nativeRoot(call, config) }, (input, defaults) => this.executeNative(call, input, defaults));
192
+ }
193
+ prepareNative(call, input, defaults) {
194
+ const readConfirmation = this.runtime.sessions.pages.findReadConfirmation([...input.toolArgs], resolveAgentBrowserNamespace(input.toolArgs, getAgentBrowserProcessEnvironment().AGENT_BROWSER_NAMESPACE), input.toolStdin);
195
+ const resolvedInput = readConfirmation
196
+ ? { ...input, toolArgs: scopeReadConfirmationArgs(input.toolArgs, readConfirmation) }
197
+ : input;
198
+ const qaFailure = this.attachedQaFailure(resolvedInput);
199
+ if (qaFailure) {
200
+ return { failure: qaFailure };
201
+ }
202
+ return {
203
+ call: {
204
+ ...call,
205
+ resolvedInput,
206
+ readConfirmation,
207
+ withLaunchDefaults: defaults,
208
+ toolArgs: resolvedInput.toolArgs,
209
+ compiledElectron: resolvedInput.kind === "electron" ? resolvedInput.compiledElectron : undefined,
210
+ redactedCompiledElectron: resolvedInput.kind === "electron" ? resolvedInput.redactedCompiledElectron : undefined,
211
+ },
212
+ };
213
+ }
214
+ attachedQaFailure(input) {
215
+ if (input.kind !== "qa" ||
216
+ !input.compiledQaPreset.checks.attached ||
217
+ this.runtime.managed.active) {
218
+ return undefined;
219
+ }
220
+ const session = extractExplicitSessionName(input.toolArgs);
221
+ if (session !== undefined && session !== "") {
222
+ return undefined;
223
+ }
224
+ return validationFailure(input, "qa.attached requires an active attached session. Run electron.launch or connect to an Electron debug port first, or configure a native shared session.");
225
+ }
226
+ needsVersionCheck(call) {
227
+ if (call.compiledElectron &&
228
+ ["cleanup", "list", "status"].includes(call.compiledElectron.action)) {
229
+ return false;
230
+ }
231
+ if (call.readConfirmation?.capabilities?.readRequiresConfirmation === true) {
232
+ return false;
233
+ }
234
+ if (!needsManagedSession(parseArgvDescriptor(call.toolArgs), call.resolvedInput.toolStdin)) {
235
+ return false;
236
+ }
237
+ return (!isPlainTextInspectionArgs(call.toolArgs) &&
238
+ !isCloseCommand(extractUpstreamCommandTokens(call.toolArgs)[0]) &&
239
+ call.signal?.aborted !== true);
240
+ }
241
+ coordinate(call) {
242
+ const explicitSessionName = extractExplicitSessionName(call.toolArgs);
243
+ const namespace = explicitSessionName !== undefined && explicitSessionName !== ""
244
+ ? resolveAgentBrowserNamespace(call.toolArgs, getAgentBrowserProcessEnvironment().AGENT_BROWSER_NAMESPACE)
245
+ : undefined;
246
+ const serializeBrowserCommand = shouldSerializeBrowserCommand(this.runtime.managed.owned, this.runtime.electron.ownedRecords, {
247
+ namespace,
248
+ explicitSessionName,
249
+ managedSessionName: this.runtime.managed.name,
250
+ });
251
+ const callerOwnedSessionQueueKey = !serializeBrowserCommand && explicitSessionName !== undefined && explicitSessionName !== ""
252
+ ? (getSessionContextKey(explicitSessionName, namespace) ?? explicitSessionName)
253
+ : undefined;
254
+ return {
255
+ ...call,
256
+ explicitSessionName,
257
+ callerOwnedSessionNamespace: namespace,
258
+ serializeBrowserCommand,
259
+ callerOwnedSessionQueueKey,
260
+ closesAllSessions: commandClosesAllSessions(call.toolArgs, call.resolvedInput.toolStdin),
261
+ };
262
+ }
263
+ async executeNative(prepared, input, defaults) {
264
+ const admitted = this.prepareNative(prepared, input, defaults);
265
+ if ("failure" in admitted) {
266
+ return admitted.failure;
267
+ }
268
+ const { call } = admitted;
269
+ if (this.needsVersionCheck(call)) {
270
+ const failure = await validateUpstreamVersion(this.runtime.validatedUpstreamPathKeys, call.browserCwd, call.signal);
271
+ if (failure) {
272
+ return applyAgentBrowserOutputPath({
273
+ cwd: call.operationCwd,
274
+ outputPath: call.outputPath,
275
+ result: failure,
276
+ });
277
+ }
278
+ }
279
+ const runHost = () => runCoordinatedElectronHostInput(this.runtime, call);
280
+ const hostResult = await (shouldSerializeElectronHostInput(call.compiledElectron)
281
+ ? this.runtime.managedSessionExecutionQueue.run(runHost, call.signal)
282
+ : runHost());
283
+ if (hostResult) {
284
+ return call.compiledElectron?.action === "cleanup"
285
+ ? hostResult
286
+ : applyUnserializedOutputPath(this.runtime, call, hostResult);
287
+ }
288
+ return runWithinSessionQueue(this.runtime, this.coordinate(call));
289
+ }
290
+ async run() {
291
+ const admitted = this.admit();
292
+ if ("failure" in admitted) {
293
+ return admitted.failure;
294
+ }
295
+ const { call } = admitted;
296
+ return call.managedAtAdmission
297
+ ? this.runtime.managedSessionExecutionQueue.run(() => this.executeAdmitted(call), call.signal)
298
+ : this.executeAdmitted(call);
299
+ }
300
+ }
301
+ export function executeBrowserInvocation(runtime, invocation) {
302
+ return new BrowserAdmission(runtime, invocation).run();
303
+ }
@@ -0,0 +1,36 @@
1
+ import { buildValidationFailureResult } from "./input-plan.js";
2
+ import { applyAgentBrowserOutputPath, canWriteAgentBrowserOutput } from "./output-file.js";
3
+ import { getArtifactPreflightValidationError } from "./extension-artifact-preflight.js";
4
+ import { warnRecordingPersistence, } from "./extension-recording.js";
5
+ export async function applyUnserializedOutputPath(resources, call, result, preserveTextContent = false) {
6
+ if (!(call.outputPath !== undefined && call.outputPath !== "") ||
7
+ !canWriteAgentBrowserOutput(result)) {
8
+ return warnRecordingPersistence(resources.recordings.dirty, result);
9
+ }
10
+ return resources.artifacts.queue.run(async () => {
11
+ resources.recordings.flush();
12
+ const reservationError = getArtifactPreflightValidationError({
13
+ activeRecordingReservations: [...resources.recordings.active.values()],
14
+ args: [],
15
+ cwd: call.operationCwd,
16
+ outputPath: call.outputPath,
17
+ });
18
+ if (reservationError !== undefined && reservationError !== "") {
19
+ return warnRecordingPersistence(resources.recordings.dirty, buildValidationFailureResult({
20
+ attemptedKind: call.resolvedInput.kind,
21
+ kind: "invalid",
22
+ redactedArgs: call.resolvedInput.redactedArgs,
23
+ status: "invalid",
24
+ toolArgs: call.resolvedInput.toolArgs,
25
+ toolStdin: call.resolvedInput.toolStdin,
26
+ validationError: reservationError,
27
+ }));
28
+ }
29
+ return applyAgentBrowserOutputPath({
30
+ cwd: call.operationCwd,
31
+ outputPath: call.outputPath,
32
+ preserveTextContent,
33
+ result: warnRecordingPersistence(resources.recordings.dirty, result),
34
+ });
35
+ });
36
+ }
@@ -0,0 +1,335 @@
1
+ import { getSuccessfulBatchCloseLifecycle } from "../batch-lifecycle.js";
2
+ import { appendBrowserTransition, applyArtifactChanges, artifactChanges, browserStateEffects, } from "../browser-transcript.js";
3
+ import { appendBrowserRecord, hasPublishedBrowserJournal } from "../browser-journal.js";
4
+ import { extractUpstreamCommandTokens } from "../runtime.js";
5
+ import { isBooleanFlagEnabled, deleteIdentityKeysInNamespace, extractExplicitSessionName, getAgentBrowserSessionIdentityKey, isAgentBrowserSessionIdentityKeyInNamespace, } from "../argv-grammar.js";
6
+ import { isRecord } from "../parsing.js";
7
+ import { mergeBrowserRunArtifactManifest } from "./browser-run/artifact-merge.js";
8
+ import { isCloseCommand } from "../command-taxonomy.js";
9
+ import { getSessionContextKey } from "./browser-run/session-state.js";
10
+ import { applyAgentBrowserOutputPath } from "./output-file.js";
11
+ import { formatSessionArtifactRetentionSummary } from "../results/artifact-manifest.js";
12
+ import { isSuccessfulNativeConfirmedClose } from "../read-confirmation.js";
13
+ import { getArtifactCommandSteps } from "./extension-artifact-preflight.js";
14
+ import { browserExecutionFailure, invocationArtifactManifest, browserPageChanges, } from "./extension-result-state.js";
15
+ import { untrackOwnedManagedSession, syncOwnedManagedSessionsFromResult, } from "./extension-managed-ownership.js";
16
+ import { getTouchedElectronLaunchIds } from "./extension-electron-ownership.js";
17
+ import { warnRecordingPersistence, appendActiveRecordingCleanupAction, } from "./extension-recording.js";
18
+ export class BrowserCommandResult {
19
+ runtime;
20
+ call;
21
+ prepared;
22
+ dispatch;
23
+ result;
24
+ branchRestoreStillCurrent;
25
+ resultDetails;
26
+ resultSessionName;
27
+ resultNamespace;
28
+ constructor(runtime, call, prepared, dispatch) {
29
+ this.runtime = runtime;
30
+ this.call = call;
31
+ this.prepared = prepared;
32
+ this.dispatch = dispatch;
33
+ this.result = dispatch.result;
34
+ this.branchRestoreStillCurrent = call.branch.isCurrent();
35
+ this.resultDetails = isRecord(this.result.details) ? this.result.details : undefined;
36
+ this.resultSessionName =
37
+ typeof this.resultDetails?.sessionName === "string"
38
+ ? this.resultDetails.sessionName
39
+ : extractExplicitSessionName(call.toolArgs);
40
+ this.resultNamespace =
41
+ typeof this.resultDetails?.namespace === "string"
42
+ ? this.resultDetails.namespace
43
+ : prepared.selectedPlan.namespace;
44
+ }
45
+ reconcileNativeIdentity() {
46
+ const { prepared } = this;
47
+ if (prepared.browserRunState.confirmationPolicyMayBeEstablished === false) {
48
+ prepared.workingPageState.setConfirmActions(prepared.selectedKey, prepared.priorPages.get(prepared.selectedKey)?.confirmActions);
49
+ }
50
+ this.annotateManagedIdentity();
51
+ }
52
+ resultMatchesManagedIdentity() {
53
+ const details = this.resultDetails;
54
+ if (!details ||
55
+ typeof details.sessionName !== "string" ||
56
+ !this.prepared.browserRunState.managedSessionActive) {
57
+ return false;
58
+ }
59
+ return (getAgentBrowserSessionIdentityKey(details.sessionName, typeof details.namespace === "string" ? details.namespace : undefined) ===
60
+ getAgentBrowserSessionIdentityKey(this.prepared.browserRunState.managedSessionName, this.prepared.browserRunState.managedSessionNamespace));
61
+ }
62
+ annotateManagedIdentity() {
63
+ if (this.resultDetails && this.prepared.begin.event.state.wrapperManaged === true) {
64
+ this.resultDetails.managedSessionSocketDir =
65
+ this.prepared.begin.event.state.managedSessionSocketDir;
66
+ }
67
+ if (this.resultDetails && this.resultMatchesManagedIdentity()) {
68
+ this.resultDetails.managedSessionCwd = this.prepared.browserRunState.managedSessionCwd;
69
+ }
70
+ }
71
+ attachmentRemainsActive() {
72
+ const outcome = isRecord(this.resultDetails?.managedSessionOutcome)
73
+ ? this.resultDetails.managedSessionOutcome
74
+ : undefined;
75
+ return (this.result.isError !== true ||
76
+ ((this.dispatch.attachedSessionRequested || this.dispatch.attachedSessionKnown) &&
77
+ outcome?.activeAfter === true));
78
+ }
79
+ closesAttachment() {
80
+ const tokens = extractUpstreamCommandTokens(this.call.toolArgs);
81
+ return ((this.result.isError !== true &&
82
+ (isCloseCommand(tokens[0]) ||
83
+ isSuccessfulNativeConfirmedClose(tokens, this.resultDetails?.data))) ||
84
+ getSuccessfulBatchCloseLifecycle(this.resultDetails?.batchSteps)?.endsClosed === true);
85
+ }
86
+ retainAttachment(key) {
87
+ this.runtime.sessions.attached.add(key);
88
+ this.result = {
89
+ ...this.result,
90
+ details: { ...this.resultDetails, attachedBrowserSession: true },
91
+ };
92
+ }
93
+ shouldRetainAttachment() {
94
+ return (this.attachmentRemainsActive() &&
95
+ (this.dispatch.attachedSessionRequested || this.dispatch.attachedSessionKnown));
96
+ }
97
+ retainAfterCloseAll(key) {
98
+ if (this.shouldRetainAttachment() &&
99
+ getSuccessfulBatchCloseLifecycle(this.resultDetails?.batchSteps)?.endsClosed === false) {
100
+ this.retainAttachment(key);
101
+ }
102
+ }
103
+ reconcileAttachments() {
104
+ if (!this.branchRestoreStillCurrent) {
105
+ return;
106
+ }
107
+ const closeAll = this.resultDetails?.closeAllApplied === true;
108
+ if (closeAll) {
109
+ deleteIdentityKeysInNamespace(this.runtime.sessions.attached, this.resultNamespace);
110
+ }
111
+ const key = getSessionContextKey(this.resultSessionName, this.resultNamespace) ?? this.resultSessionName;
112
+ if (key === undefined || key === "") {
113
+ return;
114
+ }
115
+ if (closeAll) {
116
+ this.retainAfterCloseAll(key);
117
+ return;
118
+ }
119
+ if (this.closesAttachment()) {
120
+ this.runtime.sessions.attached.delete(key);
121
+ }
122
+ else if (this.shouldRetainAttachment()) {
123
+ this.retainAttachment(key);
124
+ }
125
+ }
126
+ mergeRoutes() {
127
+ const updated = this.prepared.browserRunState.networkRoutesBySession;
128
+ const initial = this.dispatch.initialNetworkRoutesBySession;
129
+ if (updated === initial) {
130
+ return;
131
+ }
132
+ const merged = new Map(this.runtime.sessions.routes);
133
+ for (const [key, value] of updated) {
134
+ if (!initial.has(key) || initial.get(key) !== value) {
135
+ merged.set(key, value);
136
+ }
137
+ }
138
+ for (const key of initial.keys()) {
139
+ if (!updated.has(key)) {
140
+ merged.delete(key);
141
+ }
142
+ }
143
+ this.runtime.sessions.routes = merged;
144
+ }
145
+ retireClosedRecordings() {
146
+ const handled = this.runtime.recordings.syncResult(this.result);
147
+ if (this.resultDetails?.closeAllApplied === true) {
148
+ // Snapshot reservations because retiring an identity deletes from the live index.
149
+ for (const [key, reservation] of Array.from(this.runtime.recordings.active)) {
150
+ if (isAgentBrowserSessionIdentityKeyInNamespace(key, this.resultNamespace)) {
151
+ this.runtime.recordings.retire(reservation.sessionName, reservation.namespace);
152
+ }
153
+ }
154
+ }
155
+ for (const key of this.prepared.browserRunState.closedManagedSessionNames) {
156
+ if (handled.has(key)) {
157
+ continue;
158
+ }
159
+ const reservation = this.runtime.recordings.active.get(key);
160
+ if (reservation) {
161
+ this.runtime.recordings.retire(reservation.sessionName, reservation.namespace);
162
+ }
163
+ }
164
+ }
165
+ appendRecordingCleanup() {
166
+ if (this.resultSessionName === undefined || this.resultSessionName === "") {
167
+ return;
168
+ }
169
+ const reservation = this.runtime.recordings.active.get(getAgentBrowserSessionIdentityKey(this.resultSessionName, this.resultNamespace));
170
+ if (reservation) {
171
+ this.result = appendActiveRecordingCleanupAction(this.result, reservation);
172
+ }
173
+ }
174
+ mergeResultArtifacts() {
175
+ if (!this.branchRestoreStillCurrent) {
176
+ return;
177
+ }
178
+ this.mergeRoutes();
179
+ this.runtime.artifacts.manifest = mergeBrowserRunArtifactManifest(this.runtime.artifacts.manifest, this.dispatch.initialArtifactManifest, this.prepared.browserRunState.artifactManifest);
180
+ this.retireClosedRecordings();
181
+ this.appendRecordingCleanup();
182
+ if (this.runtime.artifacts.manifest && isRecord(this.result.details)) {
183
+ this.result.details.artifactRetentionSummary = formatSessionArtifactRetentionSummary(this.runtime.artifacts.manifest);
184
+ }
185
+ }
186
+ adoptRuntime() {
187
+ const branchStateStillCurrent = this.prepared.generationAtStart === this.runtime.branch.stateGeneration &&
188
+ this.call.branch.isCurrent();
189
+ if (this.call.serializeBrowserCommand || branchStateStillCurrent) {
190
+ this.runtime.managed.freshOrdinal = Math.max(this.runtime.managed.freshOrdinal, this.prepared.browserRunState.freshSessionOrdinal);
191
+ this.runtime.managed.active = this.prepared.browserRunState.managedSessionActive;
192
+ this.runtime.managed.compatibilityWorkaround =
193
+ this.prepared.browserRunState.managedSessionCompatibilityWorkaround;
194
+ this.runtime.managed.headedAutosaveDisabled =
195
+ this.prepared.browserRunState.managedSessionHeadedAutosaveDisabled === true;
196
+ this.runtime.managed.headedAutosaveInterval =
197
+ this.prepared.browserRunState.managedSessionHeadedAutosaveInterval;
198
+ this.runtime.managed.cwd = this.prepared.browserRunState.managedSessionCwd;
199
+ this.runtime.managed.name = this.prepared.browserRunState.managedSessionName;
200
+ this.runtime.managed.namespace = this.prepared.browserRunState.managedSessionNamespace;
201
+ for (const closedSessionName of this.prepared.browserRunState.closedManagedSessionNames) {
202
+ untrackOwnedManagedSession(this.runtime.managed.owned, closedSessionName);
203
+ }
204
+ syncOwnedManagedSessionsFromResult(this.runtime.managed.owned, this.result, this.prepared.browserRunState.managedSessionCwd);
205
+ this.runtime.electron.mergeActive(this.runtime.electron.records, {
206
+ ownerSessionId: this.call.ctx.sessionManager.getSessionId(),
207
+ touchedLaunchIds: !(this.result.isError === true)
208
+ ? getTouchedElectronLaunchIds(this.call.explicitSessionName ?? this.prepared.browserRunState.managedSessionName, this.runtime.electron.records, this.resultNamespace)
209
+ : undefined,
210
+ });
211
+ if (this.call.serializeBrowserCommand) {
212
+ this.runtime.branch.advanceState();
213
+ }
214
+ }
215
+ }
216
+ finishState() {
217
+ return {
218
+ ...browserStateEffects(isRecord(this.result.details) ? this.result.details : {}),
219
+ ...this.prepared.browserRunState.observedBrowserEffects,
220
+ ownerSessionId: this.call.ctx.sessionManager.getSessionId(),
221
+ ...(this.prepared.begin.event.state.wrapperManaged === true
222
+ ? {
223
+ managedSessionDaemon: this.runtime.managed.restore.getDaemonReceipt(this.resultSessionName, this.resultNamespace),
224
+ }
225
+ : {}),
226
+ };
227
+ }
228
+ needsFinish(pagesChanged, artifactsChanged) {
229
+ return (this.prepared.browserAffecting ||
230
+ pagesChanged ||
231
+ (artifactsChanged && hasPublishedBrowserJournal(this.call.ctx.sessionManager)) ||
232
+ this.resultDetails?.readConfirmation !== undefined ||
233
+ this.prepared.browserRunState.observedBrowserEffects?.readConfirmation !== undefined);
234
+ }
235
+ buildFinish() {
236
+ if (this.prepared.selectedPlan.plainTextInspection || !this.branchRestoreStillCurrent) {
237
+ return undefined;
238
+ }
239
+ const changes = browserPageChanges(this.prepared.workingPageState, this.prepared.priorPages, [
240
+ ...this.prepared.browserRunState.closedManagedSessionNames,
241
+ ...(this.prepared.browserAffecting ? [this.prepared.selectedKey] : []),
242
+ ]);
243
+ const artifacts = artifactChanges(this.dispatch.initialArtifactManifest, this.runtime.artifacts.manifest);
244
+ const requiresFinish = this.needsFinish(changes.pages.length > 0, artifacts !== undefined);
245
+ if (!requiresFinish) {
246
+ return undefined;
247
+ }
248
+ return {
249
+ event: {
250
+ version: 1,
251
+ phase: this.prepared.browserAffecting ? "finish" : "state",
252
+ operationId: this.prepared.operationId,
253
+ toolCallId: this.call.toolCallId,
254
+ commandIndex: this.call.commandIndex ?? 0,
255
+ isError: this.result.isError === true,
256
+ state: this.finishState(),
257
+ pages: changes.pages,
258
+ artifacts,
259
+ },
260
+ ...(changes.snapshot ? { snapshot: changes.snapshot } : {}),
261
+ };
262
+ }
263
+ persistenceFailure(error) {
264
+ return {
265
+ ...this.result,
266
+ ...browserExecutionFailure(new Error("The browser command finished, but its state could not be persisted. Changes may already have happened; inspect the current page before retrying.", { cause: error }), this.prepared.executionSignal),
267
+ details: {
268
+ ...(isRecord(this.result.details) ? this.result.details : {}),
269
+ resultCategory: "failure",
270
+ failureCategory: "upstream-error",
271
+ browserStatePersistence: "finish-unconfirmed",
272
+ nextActions: [
273
+ {
274
+ id: "inspect-after-browser-state-persistence-failure",
275
+ tool: "agent_browser",
276
+ params: {
277
+ args: [
278
+ "--session",
279
+ this.prepared.selectedPlan.sessionName ?? "default",
280
+ "--namespace",
281
+ this.prepared.selectedPlan.namespace ?? "",
282
+ "batch",
283
+ "--bail",
284
+ ],
285
+ stdin: JSON.stringify([
286
+ ["get", "url"],
287
+ ["snapshot", "-i"],
288
+ ]),
289
+ },
290
+ reason: "The effect may already have happened. Verify the current URL and inspect before deciding whether to retry.",
291
+ safety: "Read-only inspection; no mutation is replayed.",
292
+ },
293
+ ],
294
+ },
295
+ };
296
+ }
297
+ async persistFinish() {
298
+ const finish = this.buildFinish();
299
+ if (!finish) {
300
+ return undefined;
301
+ }
302
+ try {
303
+ if (!(await appendBrowserRecord(this.call.ctx.sessionManager, () => appendBrowserTransition(this.runtime.pi, finish), finish, this.call.branch)) ||
304
+ !this.call.branch.isCurrent()) {
305
+ throw new Error("The selected Pi branch changed before browser-state confirmation.");
306
+ }
307
+ }
308
+ catch (error) {
309
+ return this.persistenceFailure(error);
310
+ }
311
+ this.runtime.sessions.pages.applyBrowserRecord(finish);
312
+ this.runtime.artifacts.manifest = applyArtifactChanges(this.runtime.artifacts.manifest, finish.event.artifacts);
313
+ return undefined;
314
+ }
315
+ async complete() {
316
+ if (isRecord(this.result.details)) {
317
+ this.result.details.browserEventVersion = 1;
318
+ if (!(this.call.compiledElectron?.action === "launch" &&
319
+ this.call.compiledElectron.handoff === "snapshot") &&
320
+ !getArtifactCommandSteps(this.call.toolArgs, this.call.resolvedInput.toolStdin).steps.some((step) => step[0] === "snapshot")) {
321
+ delete this.result.details.refSnapshot;
322
+ }
323
+ this.result.details.artifactManifest = invocationArtifactManifest(this.call.branch.isCurrent()
324
+ ? this.runtime.artifacts.manifest
325
+ : this.prepared.browserRunState.artifactManifest, this.dispatch.initialArtifactManifest, this.result.details);
326
+ }
327
+ return applyAgentBrowserOutputPath({
328
+ cwd: this.call.operationCwd,
329
+ outputPath: this.call.outputPath,
330
+ preserveTextContent: Array.isArray(this.call.params.args) &&
331
+ isBooleanFlagEnabled(this.call.params.args, "--json"),
332
+ result: warnRecordingPersistence(this.runtime.recordings.dirty, this.result),
333
+ });
334
+ }
335
+ }