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.
- package/CHANGELOG.md +91 -5
- package/README.md +120 -86
- package/dist/extensions/agent-browser/index.js +43065 -2016
- package/dist/extensions/agent-browser/lib/argv-descriptor.js +49 -26
- package/dist/extensions/agent-browser/lib/argv-grammar.js +82 -93
- package/dist/extensions/agent-browser/lib/bash-guard.js +129 -126
- package/dist/extensions/agent-browser/lib/batch-lifecycle.js +113 -49
- package/dist/extensions/agent-browser/lib/browser-execution-claim-codec.js +61 -0
- package/dist/extensions/agent-browser/lib/browser-execution-claim-storage.js +232 -0
- package/dist/extensions/agent-browser/lib/browser-execution-claims.js +202 -0
- package/dist/extensions/agent-browser/lib/browser-execution-identity.js +77 -0
- package/dist/extensions/agent-browser/lib/browser-journal-branch.js +98 -0
- package/dist/extensions/agent-browser/lib/browser-journal-contracts.js +1 -0
- package/dist/extensions/agent-browser/lib/browser-journal-projection.js +221 -0
- package/dist/extensions/agent-browser/lib/browser-journal-reader.js +89 -0
- package/dist/extensions/agent-browser/lib/browser-journal-replay.js +246 -0
- package/dist/extensions/agent-browser/lib/browser-journal.js +103 -394
- package/dist/extensions/agent-browser/lib/browser-legacy-pages.js +220 -0
- package/dist/extensions/agent-browser/lib/browser-legacy-projection.js +282 -0
- package/dist/extensions/agent-browser/lib/browser-legacy-types.js +1 -0
- package/dist/extensions/agent-browser/lib/browser-session-conversion-stream.js +217 -0
- package/dist/extensions/agent-browser/lib/browser-session-conversion.js +80 -335
- package/dist/extensions/agent-browser/lib/browser-transcript-contracts.js +35 -0
- package/dist/extensions/agent-browser/lib/browser-transcript-validation.js +166 -0
- package/dist/extensions/agent-browser/lib/browser-transcript.js +137 -81
- package/dist/extensions/agent-browser/lib/browser-value-parsing.js +15 -0
- package/dist/extensions/agent-browser/lib/command-capabilities.js +340 -0
- package/dist/extensions/agent-browser/lib/command-policy.js +107 -88
- package/dist/extensions/agent-browser/lib/command-taxonomy.js +49 -322
- package/dist/extensions/agent-browser/lib/config-policy.js +138 -343
- package/dist/extensions/agent-browser/lib/config-providers.js +71 -0
- package/dist/extensions/agent-browser/lib/config-validation.js +218 -0
- package/dist/extensions/agent-browser/lib/config.js +19 -7
- package/dist/extensions/agent-browser/lib/electron/cdp.js +15 -7
- package/dist/extensions/agent-browser/lib/electron/cleanup.js +134 -55
- package/dist/extensions/agent-browser/lib/electron/discovery-darwin.js +109 -0
- package/dist/extensions/agent-browser/lib/electron/discovery-desktop.js +136 -0
- package/dist/extensions/agent-browser/lib/electron/discovery-evidence.js +89 -0
- package/dist/extensions/agent-browser/lib/electron/discovery-linux.js +93 -0
- package/dist/extensions/agent-browser/lib/electron/discovery-packages.js +162 -0
- package/dist/extensions/agent-browser/lib/electron/discovery-types.js +2 -0
- package/dist/extensions/agent-browser/lib/electron/discovery.js +140 -549
- package/dist/extensions/agent-browser/lib/electron/launch-monitor.js +102 -0
- package/dist/extensions/agent-browser/lib/electron/launch-process.js +209 -0
- package/dist/extensions/agent-browser/lib/electron/launch-types.js +2 -0
- package/dist/extensions/agent-browser/lib/electron/launch.js +249 -354
- package/dist/extensions/agent-browser/lib/executable-path.js +21 -12
- package/dist/extensions/agent-browser/lib/execution-cwd.js +35 -18
- package/dist/extensions/agent-browser/lib/input-modes/electron.js +162 -121
- package/dist/extensions/agent-browser/lib/input-modes/job.js +116 -313
- package/dist/extensions/agent-browser/lib/input-modes/lookup-network-evidence.js +104 -0
- package/dist/extensions/agent-browser/lib/input-modes/lookup-plan.js +132 -0
- package/dist/extensions/agent-browser/lib/input-modes/lookup-redaction.js +57 -0
- package/dist/extensions/agent-browser/lib/input-modes/lookup-source-evidence.js +151 -0
- package/dist/extensions/agent-browser/lib/input-modes/lookup-workspace.js +142 -0
- package/dist/extensions/agent-browser/lib/input-modes/lookups.js +57 -412
- package/dist/extensions/agent-browser/lib/input-modes/params.js +63 -17
- package/dist/extensions/agent-browser/lib/input-modes/qa-analysis.js +268 -0
- package/dist/extensions/agent-browser/lib/input-modes/qa-presentation.js +117 -0
- package/dist/extensions/agent-browser/lib/input-modes/script-child.js +396 -0
- package/dist/extensions/agent-browser/lib/input-modes/script-protocol.js +86 -0
- package/dist/extensions/agent-browser/lib/input-modes/script-types.js +1 -0
- package/dist/extensions/agent-browser/lib/input-modes/script-validation.js +60 -0
- package/dist/extensions/agent-browser/lib/input-modes/script.js +60 -409
- package/dist/extensions/agent-browser/lib/input-modes/semantic-action.js +218 -128
- package/dist/extensions/agent-browser/lib/input-modes/shared.js +15 -4
- package/dist/extensions/agent-browser/lib/input-modes/types.js +56 -7
- package/dist/extensions/agent-browser/lib/json-schema.js +22 -10
- package/dist/extensions/agent-browser/lib/launch-scoped-flags.js +17 -5
- package/dist/extensions/agent-browser/lib/managed-session-policy-lock.js +92 -425
- package/dist/extensions/agent-browser/lib/managed-session-posix-storage.js +58 -0
- package/dist/extensions/agent-browser/lib/managed-session-project-identity.js +244 -0
- package/dist/extensions/agent-browser/lib/managed-session-restore-context.js +84 -0
- package/dist/extensions/agent-browser/lib/managed-session-restore-policy.js +119 -0
- package/dist/extensions/agent-browser/lib/managed-session-restore-state.js +83 -0
- package/dist/extensions/agent-browser/lib/managed-session-restore.js +168 -300
- package/dist/extensions/agent-browser/lib/managed-session-snapshot-records.js +277 -0
- package/dist/extensions/agent-browser/lib/managed-session-snapshots.js +128 -305
- package/dist/extensions/agent-browser/lib/managed-session-storage.js +56 -253
- package/dist/extensions/agent-browser/lib/native-confirmation.js +140 -0
- package/dist/extensions/agent-browser/lib/native-output.js +44 -9
- package/dist/extensions/agent-browser/lib/orchestration/batch-stdin.js +107 -66
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/artifact-merge.js +14 -6
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/artifact-paths.js +109 -57
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/browser-observation-result.js +82 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/click-dispatch.js +171 -57
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/diagnostic-values.js +31 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/diagnostics.js +152 -781
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/electron-observation.js +202 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/electron-text-diagnostics.js +109 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/fill-diagnostics.js +119 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-action-recovery.js +147 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-actions.js +144 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-content.js +123 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-contracts.js +1 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-details.js +156 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-electron.js +179 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-evidence.js +39 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-missing-binary.js +89 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-recovery.js +97 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-redaction.js +106 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result-timeout.js +110 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/final-result.js +41 -538
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/index.js +204 -108
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/interaction-diagnostics.js +290 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/managed-session-close.js +167 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/managed-session-daemon-inspection.js +108 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/managed-session-daemon-policy.js +127 -199
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/native-helper-observation.js +65 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/observation-types.js +1 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/overlay-diagnostics.js +120 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare/network-page-filter.js +113 -30
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare/scroll-shims.js +109 -28
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare/snapshot-filter-data.js +150 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare/snapshot-filter.js +138 -253
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare/snapshot-rendered-text.js +147 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare/wait-timeouts.js +59 -24
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-artifacts.js +159 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-command.js +131 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-contracts.js +1 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-daemon.js +93 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-failure.js +42 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-guards.js +242 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-input.js +75 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-observations.js +92 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-page-selection.js +254 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-page-state.js +121 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-refs.js +130 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-resources.js +114 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-semantic.js +121 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-session-plan.js +222 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare-timeouts.js +68 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prepare.js +176 -1114
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-analysis.js +191 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-confirmation.js +152 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-diagnostics.js +182 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-electron.js +150 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-lifecycle-contracts.js +1 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-lifecycle-phase-contracts.js +1 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-lifecycle-phase.js +115 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-lifecycle.js +256 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-managed-contracts.js +1 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-managed.js +256 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-native-phase-contracts.js +1 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-native-phase.js +93 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-native.js +113 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-navigation-contracts.js +1 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-navigation.js +316 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-ownership.js +28 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-page-phase-contracts.js +1 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-page-phase.js +142 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-presentation-contracts.js +1 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-presentation.js +333 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-publication-phase-contracts.js +1 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-publication-phase.js +71 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-publication.js +201 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-receipts.js +183 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-refs.js +200 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output-tabs.js +142 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/process-output.js +18 -910
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/prompt-guards.js +23 -13
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/recording-receipt-reconciliation.js +198 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/recording-recovery-contracts.js +1 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/recording-recovery-presentation.js +154 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/recording-recovery.js +68 -151
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/screenshot-capture.js +14 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/screenshot-observation.js +169 -46
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/session-state-commands.js +130 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/session-state-electron.js +210 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/session-state-observations.js +61 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/session-state-outcomes.js +187 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/session-state-refs.js +171 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/session-state-tabs.js +228 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/session-state.js +77 -753
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/text-visibility-diagnostics.js +182 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/timeout-diagnostics.js +256 -0
- package/dist/extensions/agent-browser/lib/orchestration/browser-run/timeout-progress.js +108 -0
- package/dist/extensions/agent-browser/lib/orchestration/code-artifact-observation.js +39 -0
- package/dist/extensions/agent-browser/lib/orchestration/code-image-observation.js +119 -0
- package/dist/extensions/agent-browser/lib/orchestration/electron-host/branch.js +92 -0
- package/dist/extensions/agent-browser/lib/orchestration/electron-host/cleanup-result.js +58 -0
- package/dist/extensions/agent-browser/lib/orchestration/electron-host/cleanup.js +78 -0
- package/dist/extensions/agent-browser/lib/orchestration/electron-host/contracts.js +1 -0
- package/dist/extensions/agent-browser/lib/orchestration/electron-host/discovery.js +106 -0
- package/dist/extensions/agent-browser/lib/orchestration/electron-host/index.js +48 -816
- package/dist/extensions/agent-browser/lib/orchestration/electron-host/policy.js +86 -0
- package/dist/extensions/agent-browser/lib/orchestration/electron-host/probe-collection.js +69 -0
- package/dist/extensions/agent-browser/lib/orchestration/electron-host/probe-data.js +167 -0
- package/dist/extensions/agent-browser/lib/orchestration/electron-host/probe-presentation.js +164 -0
- package/dist/extensions/agent-browser/lib/orchestration/electron-host/probe.js +161 -0
- package/dist/extensions/agent-browser/lib/orchestration/electron-host/status.js +165 -0
- package/dist/extensions/agent-browser/lib/orchestration/execution-queue.js +21 -9
- package/dist/extensions/agent-browser/lib/orchestration/extension-artifact-preflight.js +211 -0
- package/dist/extensions/agent-browser/lib/orchestration/extension-artifacts.js +23 -0
- package/dist/extensions/agent-browser/lib/orchestration/extension-attachment-replay.js +99 -0
- package/dist/extensions/agent-browser/lib/orchestration/extension-branch-restore.js +275 -0
- package/dist/extensions/agent-browser/lib/orchestration/extension-code.js +280 -0
- package/dist/extensions/agent-browser/lib/orchestration/extension-command-admission.js +303 -0
- package/dist/extensions/agent-browser/lib/orchestration/extension-command-output.js +36 -0
- package/dist/extensions/agent-browser/lib/orchestration/extension-command-result.js +335 -0
- package/dist/extensions/agent-browser/lib/orchestration/extension-command-run.js +227 -0
- package/dist/extensions/agent-browser/lib/orchestration/extension-command-state.js +1 -0
- package/dist/extensions/agent-browser/lib/orchestration/extension-electron-ownership.js +204 -0
- package/dist/extensions/agent-browser/lib/orchestration/extension-execution-locks.js +139 -0
- package/dist/extensions/agent-browser/lib/orchestration/extension-execution-queue.js +24 -0
- package/dist/extensions/agent-browser/lib/orchestration/extension-host-coordination.js +98 -0
- package/dist/extensions/agent-browser/lib/orchestration/extension-host-run.js +295 -0
- package/dist/extensions/agent-browser/lib/orchestration/extension-intent-replay.js +41 -0
- package/dist/extensions/agent-browser/lib/orchestration/extension-invocation.js +7 -0
- package/dist/extensions/agent-browser/lib/orchestration/extension-lifecycle.js +102 -0
- package/dist/extensions/agent-browser/lib/orchestration/extension-managed-ownership.js +133 -0
- package/dist/extensions/agent-browser/lib/orchestration/extension-observation.js +120 -0
- package/dist/extensions/agent-browser/lib/orchestration/extension-prompt.js +180 -0
- package/dist/extensions/agent-browser/lib/orchestration/extension-recording.js +290 -0
- package/dist/extensions/agent-browser/lib/orchestration/extension-resource-contracts.js +1 -0
- package/dist/extensions/agent-browser/lib/orchestration/extension-resource-replay.js +269 -0
- package/dist/extensions/agent-browser/lib/orchestration/extension-result-state.js +113 -0
- package/dist/extensions/agent-browser/lib/orchestration/extension-runtime.js +146 -0
- package/dist/extensions/agent-browser/lib/orchestration/extension-script-leases.js +58 -0
- package/dist/extensions/agent-browser/lib/orchestration/extension-tool-boundary.js +62 -0
- package/dist/extensions/agent-browser/lib/orchestration/extension-version-check.js +54 -0
- package/dist/extensions/agent-browser/lib/orchestration/input-plan-types.js +1 -0
- package/dist/extensions/agent-browser/lib/orchestration/input-plan.js +261 -185
- package/dist/extensions/agent-browser/lib/orchestration/input-redaction.js +62 -0
- package/dist/extensions/agent-browser/lib/orchestration/native-config.js +144 -0
- package/dist/extensions/agent-browser/lib/orchestration/native-root-launch.js +77 -0
- package/dist/extensions/agent-browser/lib/orchestration/native-session-defaults.js +210 -139
- package/dist/extensions/agent-browser/lib/orchestration/operation-paths.js +124 -58
- package/dist/extensions/agent-browser/lib/orchestration/output-file.js +198 -98
- package/dist/extensions/agent-browser/lib/orchestration/script-mode.js +199 -96
- package/dist/extensions/agent-browser/lib/owned-managed-session-context.js +55 -0
- package/dist/extensions/agent-browser/lib/page-target-batch.js +118 -0
- package/dist/extensions/agent-browser/lib/page-target-guards.js +50 -0
- package/dist/extensions/agent-browser/lib/page-target-navigation.js +104 -0
- package/dist/extensions/agent-browser/lib/page-target-validation.js +59 -243
- package/dist/extensions/agent-browser/lib/parsing.js +13 -4
- package/dist/extensions/agent-browser/lib/pi-tool-rendering.js +134 -68
- package/dist/extensions/agent-browser/lib/playbook.js +18 -14
- package/dist/extensions/agent-browser/lib/process-child.js +284 -0
- package/dist/extensions/agent-browser/lib/process-environment.js +22 -6
- package/dist/extensions/agent-browser/lib/process-errors.js +23 -0
- package/dist/extensions/agent-browser/lib/process-identity.js +47 -15
- package/dist/extensions/agent-browser/lib/process-socket-storage.js +256 -0
- package/dist/extensions/agent-browser/lib/process-stdout.js +74 -0
- package/dist/extensions/agent-browser/lib/process.js +146 -537
- package/dist/extensions/agent-browser/lib/prompt-artifacts.js +287 -0
- package/dist/extensions/agent-browser/lib/prompt-policy.js +15 -194
- package/dist/extensions/agent-browser/lib/read-command.js +41 -0
- package/dist/extensions/agent-browser/lib/read-confirmation.js +138 -35
- package/dist/extensions/agent-browser/lib/recording-reservations.js +118 -45
- package/dist/extensions/agent-browser/lib/redaction-fields.js +75 -0
- package/dist/extensions/agent-browser/lib/redaction-json.js +149 -0
- package/dist/extensions/agent-browser/lib/redaction-url.js +88 -0
- package/dist/extensions/agent-browser/lib/results/action-contracts.js +1 -0
- package/dist/extensions/agent-browser/lib/results/action-recommendations.js +28 -271
- package/dist/extensions/agent-browser/lib/results/artifact-contracts.js +1 -0
- package/dist/extensions/agent-browser/lib/results/artifact-manifest-validation.js +133 -0
- package/dist/extensions/agent-browser/lib/results/artifact-manifest.js +96 -94
- package/dist/extensions/agent-browser/lib/results/artifact-recommendations.js +73 -0
- package/dist/extensions/agent-browser/lib/results/categories.js +111 -54
- package/dist/extensions/agent-browser/lib/results/confirmation.js +29 -10
- package/dist/extensions/agent-browser/lib/results/editable-ref-evidence.js +62 -27
- package/dist/extensions/agent-browser/lib/results/electron-recommendations.js +83 -0
- package/dist/extensions/agent-browser/lib/results/envelope-decoding.js +48 -0
- package/dist/extensions/agent-browser/lib/results/envelope.js +93 -66
- package/dist/extensions/agent-browser/lib/results/evidence-contracts.js +1 -0
- package/dist/extensions/agent-browser/lib/results/failure-recommendations.js +180 -0
- package/dist/extensions/agent-browser/lib/results/network-routes.js +86 -45
- package/dist/extensions/agent-browser/lib/results/network.js +35 -12
- package/dist/extensions/agent-browser/lib/results/next-actions.js +49 -19
- package/dist/extensions/agent-browser/lib/results/presentation/artifact-files.js +320 -0
- package/dist/extensions/agent-browser/lib/results/presentation/artifact-format.js +138 -0
- package/dist/extensions/agent-browser/lib/results/presentation/artifact-images.js +113 -0
- package/dist/extensions/agent-browser/lib/results/presentation/artifact-verification.js +145 -0
- package/dist/extensions/agent-browser/lib/results/presentation/artifacts.js +99 -552
- package/dist/extensions/agent-browser/lib/results/presentation/batch-contracts.js +1 -0
- package/dist/extensions/agent-browser/lib/results/presentation/batch-recording.js +118 -0
- package/dist/extensions/agent-browser/lib/results/presentation/batch-redaction.js +68 -0
- package/dist/extensions/agent-browser/lib/results/presentation/batch-rendering.js +135 -0
- package/dist/extensions/agent-browser/lib/results/presentation/batch-step.js +227 -0
- package/dist/extensions/agent-browser/lib/results/presentation/batch-summary.js +91 -0
- package/dist/extensions/agent-browser/lib/results/presentation/batch.js +91 -460
- package/dist/extensions/agent-browser/lib/results/presentation/browser-profile-recovery.js +9 -5
- package/dist/extensions/agent-browser/lib/results/presentation/command-presenters.js +216 -0
- package/dist/extensions/agent-browser/lib/results/presentation/common.js +26 -9
- package/dist/extensions/agent-browser/lib/results/presentation/content.js +86 -29
- package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-a11y.js +67 -0
- package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-health.js +79 -0
- package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-identity.js +199 -0
- package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-logs.js +75 -0
- package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-network-actions.js +216 -0
- package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-network.js +124 -0
- package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-redaction.js +64 -0
- package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-storage.js +209 -0
- package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-stream.js +69 -0
- package/dist/extensions/agent-browser/lib/results/presentation/diagnostic-summary.js +222 -0
- package/dist/extensions/agent-browser/lib/results/presentation/diagnostics.js +103 -1019
- package/dist/extensions/agent-browser/lib/results/presentation/early-result.js +70 -0
- package/dist/extensions/agent-browser/lib/results/presentation/errors.js +130 -60
- package/dist/extensions/agent-browser/lib/results/presentation/input-contracts.js +1 -0
- package/dist/extensions/agent-browser/lib/results/presentation/large-output.js +60 -145
- package/dist/extensions/agent-browser/lib/results/presentation/navigation.js +147 -88
- package/dist/extensions/agent-browser/lib/results/presentation/notices.js +75 -0
- package/dist/extensions/agent-browser/lib/results/presentation/observation-contracts.js +1 -0
- package/dist/extensions/agent-browser/lib/results/presentation/observation-rendering.js +127 -0
- package/dist/extensions/agent-browser/lib/results/presentation/outcomes.js +120 -0
- package/dist/extensions/agent-browser/lib/results/presentation/output-completion.js +77 -0
- package/dist/extensions/agent-browser/lib/results/presentation/output-spill.js +51 -0
- package/dist/extensions/agent-browser/lib/results/presentation/registry.js +117 -237
- package/dist/extensions/agent-browser/lib/results/presentation/semantic-action.js +35 -21
- package/dist/extensions/agent-browser/lib/results/presentation/skills.js +104 -73
- package/dist/extensions/agent-browser/lib/results/presentation/source.js +109 -0
- package/dist/extensions/agent-browser/lib/results/presentation.js +17 -248
- package/dist/extensions/agent-browser/lib/results/recommendation-contracts.js +1 -0
- package/dist/extensions/agent-browser/lib/results/recording.js +52 -14
- package/dist/extensions/agent-browser/lib/results/recovery-actions.js +14 -5
- package/dist/extensions/agent-browser/lib/results/recovery-next-actions.js +30 -22
- package/dist/extensions/agent-browser/lib/results/selector-recovery-target.js +83 -0
- package/dist/extensions/agent-browser/lib/results/selector-recovery.js +123 -123
- package/dist/extensions/agent-browser/lib/results/snapshot-compact.js +266 -0
- package/dist/extensions/agent-browser/lib/results/snapshot-content.js +32 -0
- package/dist/extensions/agent-browser/lib/results/snapshot-high-value-controls.js +104 -71
- package/dist/extensions/agent-browser/lib/results/snapshot-refs.js +31 -11
- package/dist/extensions/agent-browser/lib/results/snapshot-segments.js +125 -66
- package/dist/extensions/agent-browser/lib/results/snapshot-spill.js +26 -7
- package/dist/extensions/agent-browser/lib/results/snapshot.js +28 -248
- package/dist/extensions/agent-browser/lib/results/text.js +16 -5
- package/dist/extensions/agent-browser/lib/runtime-args-validation.js +133 -0
- package/dist/extensions/agent-browser/lib/runtime-compatibility.js +81 -0
- package/dist/extensions/agent-browser/lib/runtime-contracts.js +1 -0
- package/dist/extensions/agent-browser/lib/runtime-redaction.js +118 -0
- package/dist/extensions/agent-browser/lib/runtime-replay-events.js +144 -0
- package/dist/extensions/agent-browser/lib/runtime-session-identity.js +76 -0
- package/dist/extensions/agent-browser/lib/runtime-session-plan.js +114 -0
- package/dist/extensions/agent-browser/lib/runtime-session-replay.js +123 -0
- package/dist/extensions/agent-browser/lib/runtime-tab-correction.js +65 -0
- package/dist/extensions/agent-browser/lib/runtime-timeouts.js +28 -0
- package/dist/extensions/agent-browser/lib/runtime.js +137 -1037
- package/dist/extensions/agent-browser/lib/session-identity.js +51 -0
- package/dist/extensions/agent-browser/lib/session-page-observation.js +357 -0
- package/dist/extensions/agent-browser/lib/session-page-state.js +188 -324
- package/dist/extensions/agent-browser/lib/session-page-types.js +1 -0
- package/dist/extensions/agent-browser/lib/temp-artifact-budget.js +78 -0
- package/dist/extensions/agent-browser/lib/temp-mutation-queue.js +7 -0
- package/dist/extensions/agent-browser/lib/temp-root-ownership.js +234 -0
- package/dist/extensions/agent-browser/lib/temp-root.js +207 -0
- package/dist/extensions/agent-browser/lib/temp.js +33 -446
- package/dist/extensions/agent-browser/lib/tool-surface.js +94 -24
- package/dist/extensions/agent-browser/lib/upstream-version.js +3 -2
- package/dist/extensions/agent-browser/lib/web-search-providers.js +229 -0
- package/dist/extensions/agent-browser/lib/web-search-request.js +108 -0
- package/dist/extensions/agent-browser/lib/web-search-results.js +281 -0
- package/dist/extensions/agent-browser/lib/web-search-schema.js +82 -0
- package/dist/extensions/agent-browser/lib/web-search.js +109 -617
- package/dist/extensions/agent-browser/lib/webmcp-observation.js +13 -6
- package/dist/extensions/agent-browser/lib/windows-stock-launcher.js +63 -37
- package/dist/extensions/agent-browser/script-worker.js +80 -43
- package/dist/scripts/agent-browser-target.mjs +4 -2
- package/docs/ARCHITECTURE.md +22 -10
- package/docs/CODE_QUALITY.md +242 -0
- package/docs/COMMAND_REFERENCE.md +264 -229
- package/docs/ELECTRON.md +53 -44
- package/docs/RELEASE.md +21 -17
- package/docs/REQUIREMENTS.md +2 -0
- package/docs/SESSION_STORAGE.md +1 -1
- package/docs/SUPPORT_MATRIX.md +84 -77
- package/docs/TOOL_CONTRACT.md +165 -130
- package/docs/platform-smoke.md +5 -5
- package/package.json +143 -120
- package/scripts/agent-browser-capability-baseline.mjs +361 -957
- package/scripts/agent-browser-target.mjs +6 -2
- package/scripts/build.mjs +37 -8
- package/scripts/capability-core-commands.mjs +193 -0
- package/scripts/capability-options.mjs +283 -0
- package/scripts/capability-samples.mjs +133 -0
- package/scripts/capability-section.mjs +11 -0
- package/scripts/config.mjs +213 -114
- package/scripts/convert-browser-session.mjs +30 -9
- package/scripts/doctor-sources.mjs +195 -0
- package/scripts/doctor.mjs +92 -247
- package/scripts/platform-smoke/artifacts.mjs +38 -11
- package/scripts/platform-smoke/commands.mjs +104 -0
- package/scripts/platform-smoke/crabbox-runner.mjs +167 -80
- package/scripts/platform-smoke/doctor-support.mjs +157 -0
- package/scripts/platform-smoke/doctor-windows.mjs +230 -0
- package/scripts/platform-smoke/doctor.mjs +212 -320
- package/scripts/platform-smoke/lease-evidence.mjs +134 -0
- package/scripts/platform-smoke/suite-checks.mjs +98 -0
- package/scripts/platform-smoke/suite-evidence.mjs +281 -0
- package/scripts/platform-smoke/targets.mjs +158 -472
- package/scripts/platform-smoke.mjs +55 -40
- package/scripts/prepare.mjs +16 -7
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import { format } from "node:util";
|
|
2
|
+
import { SessionPageState } from "../session-page-state.js";
|
|
3
|
+
import { getBrowserRecord } from "../browser-transcript.js";
|
|
4
|
+
import { readBrowserEntries } from "../browser-journal.js";
|
|
5
|
+
import { createFreshSessionName, isRestorableManagedSessionName, restoreManagedSessionStateFromBranch, } from "../runtime.js";
|
|
6
|
+
import { getAgentBrowserSessionIdentityKey } from "../argv-grammar.js";
|
|
7
|
+
import { getActiveElectronRecords, getSessionContextKey } from "./browser-run/session-state.js";
|
|
8
|
+
import { restoreElectronLaunchRecordsFromBranch, } from "./electron-host/index.js";
|
|
9
|
+
import { restoreArtifactManifestFromBranch } from "./extension-result-state.js";
|
|
10
|
+
import { trackOwnedManagedSession, untrackOwnedManagedSessionFromBranchClose, } from "./extension-managed-ownership.js";
|
|
11
|
+
import { collectBranchManagedResourceEvents } from "./extension-resource-replay.js";
|
|
12
|
+
import { collectPendingOwnedBrowserIntents } from "./extension-intent-replay.js";
|
|
13
|
+
import { restoreAttachedSessionKeysFromBranch } from "./extension-attachment-replay.js";
|
|
14
|
+
async function readBranchForRestore(runtime, ctx, resetRuntimeOwnership) {
|
|
15
|
+
runtime.branch.beginRestore(ctx.sessionManager.getSessionId());
|
|
16
|
+
runtime.prompt.restore(ctx);
|
|
17
|
+
const previous = {
|
|
18
|
+
active: runtime.managed.active,
|
|
19
|
+
sessionName: runtime.managed.name,
|
|
20
|
+
freshOrdinal: runtime.managed.freshOrdinal,
|
|
21
|
+
attachedKeys: runtime.sessions.attached,
|
|
22
|
+
pageState: runtime.sessions.pages,
|
|
23
|
+
};
|
|
24
|
+
runtime.managed.initializeBase(ctx.sessionManager.getSessionId(), ctx.cwd, runtime.ephemeralSessionSeed);
|
|
25
|
+
try {
|
|
26
|
+
const branch = await readBrowserEntries(ctx.sessionManager);
|
|
27
|
+
runtime.branch.setReplayError(undefined);
|
|
28
|
+
return { previous, branch, resetRuntimeOwnership };
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
runtime.branch.setReplayError(error instanceof Error ? error.message : format("%s", error));
|
|
32
|
+
runtime.sessions.pages.reset();
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function headedLaunchTracking(launch) {
|
|
37
|
+
return {
|
|
38
|
+
headedManagedAutosaveDisabled: launch?.headedManagedAutosaveDisabled ?? false,
|
|
39
|
+
headedManagedAutosaveInterval: launch?.headedManagedAutosaveInterval,
|
|
40
|
+
socketDir: launch?.socketDir,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
class BrowserBranchRestoration {
|
|
44
|
+
runtime;
|
|
45
|
+
ctx;
|
|
46
|
+
input;
|
|
47
|
+
branchResourceEvents;
|
|
48
|
+
restoredState;
|
|
49
|
+
constructor(runtime, ctx, input) {
|
|
50
|
+
this.runtime = runtime;
|
|
51
|
+
this.ctx = ctx;
|
|
52
|
+
this.input = input;
|
|
53
|
+
this.branchResourceEvents = collectBranchManagedResourceEvents(input.branch);
|
|
54
|
+
this.restoredState = restoreManagedSessionStateFromBranch([...input.branch], runtime.managed.baseName);
|
|
55
|
+
}
|
|
56
|
+
currentLaunch() {
|
|
57
|
+
return this.branchResourceEvents.managedSessionLaunchState.get(getSessionContextKey(this.runtime.managed.name, this.runtime.managed.namespace) ??
|
|
58
|
+
this.runtime.managed.name);
|
|
59
|
+
}
|
|
60
|
+
restoreManagedState() {
|
|
61
|
+
this.runtime.managed.restore.replace([...this.restoredState.managedSessionRestoreDisabledIdentities], {
|
|
62
|
+
preserveDaemonRestoreKeys: !this.input.resetRuntimeOwnership,
|
|
63
|
+
});
|
|
64
|
+
this.runtime.managed.active = this.restoredState.active;
|
|
65
|
+
}
|
|
66
|
+
alreadyReservedPostClose(ordinal, shouldReserve) {
|
|
67
|
+
return (shouldReserve &&
|
|
68
|
+
!this.input.resetRuntimeOwnership &&
|
|
69
|
+
!this.input.previous.active &&
|
|
70
|
+
this.input.previous.freshOrdinal > this.restoredState.freshSessionOrdinal &&
|
|
71
|
+
this.input.previous.freshOrdinal === ordinal &&
|
|
72
|
+
this.input.previous.sessionName ===
|
|
73
|
+
createFreshSessionName(this.runtime.managed.baseName, this.runtime.ephemeralSessionSeed, ordinal));
|
|
74
|
+
}
|
|
75
|
+
reserveSession() {
|
|
76
|
+
const restoredFreshSessionOrdinal = this.input.resetRuntimeOwnership
|
|
77
|
+
? this.restoredState.freshSessionOrdinal
|
|
78
|
+
: Math.max(this.input.previous.freshOrdinal, this.restoredState.freshSessionOrdinal);
|
|
79
|
+
const shouldReservePostCloseSession = !this.restoredState.active &&
|
|
80
|
+
this.restoredState.closedSessionName === this.restoredState.sessionName;
|
|
81
|
+
const alreadyReservedPostCloseSession = this.alreadyReservedPostClose(restoredFreshSessionOrdinal, shouldReservePostCloseSession);
|
|
82
|
+
const nextFreshSessionOrdinal = shouldReservePostCloseSession && !alreadyReservedPostCloseSession
|
|
83
|
+
? restoredFreshSessionOrdinal + 1
|
|
84
|
+
: restoredFreshSessionOrdinal;
|
|
85
|
+
if (!shouldReservePostCloseSession) {
|
|
86
|
+
this.runtime.managed.name = this.restoredState.sessionName;
|
|
87
|
+
}
|
|
88
|
+
else if (alreadyReservedPostCloseSession) {
|
|
89
|
+
this.runtime.managed.name = this.input.previous.sessionName;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
this.runtime.managed.name = createFreshSessionName(this.runtime.managed.baseName, this.runtime.ephemeralSessionSeed, nextFreshSessionOrdinal);
|
|
93
|
+
}
|
|
94
|
+
this.runtime.managed.freshOrdinal = nextFreshSessionOrdinal;
|
|
95
|
+
this.runtime.managed.namespace = shouldReservePostCloseSession
|
|
96
|
+
? undefined
|
|
97
|
+
: this.restoredState.namespace;
|
|
98
|
+
}
|
|
99
|
+
restoreLaunchState() {
|
|
100
|
+
const currentLaunch = this.currentLaunch();
|
|
101
|
+
this.runtime.managed.compatibilityWorkaround = this.runtime.managed.active
|
|
102
|
+
? currentLaunch?.compatibilityWorkaround
|
|
103
|
+
: undefined;
|
|
104
|
+
this.runtime.managed.headedAutosaveDisabled =
|
|
105
|
+
this.runtime.managed.active && currentLaunch?.headedManagedAutosaveDisabled === true;
|
|
106
|
+
this.runtime.managed.headedAutosaveInterval = this.runtime.managed.active
|
|
107
|
+
? currentLaunch?.headedManagedAutosaveInterval
|
|
108
|
+
: undefined;
|
|
109
|
+
this.runtime.managed.cwd = currentLaunch?.cwd ?? this.ctx.cwd;
|
|
110
|
+
}
|
|
111
|
+
restoreRecordingState() {
|
|
112
|
+
this.runtime.sessions.pages = SessionPageState.fromBranch([...this.input.branch]);
|
|
113
|
+
this.runtime.sessions.traces = new Map();
|
|
114
|
+
this.runtime.artifacts.manifest = restoreArtifactManifestFromBranch(this.input.branch);
|
|
115
|
+
this.runtime.recordings.restore(this.input.branch);
|
|
116
|
+
}
|
|
117
|
+
restoreAttachments() {
|
|
118
|
+
this.runtime.sessions.attached = restoreAttachedSessionKeysFromBranch(this.input.branch);
|
|
119
|
+
this.runtime.sessions.routes = new Map();
|
|
120
|
+
this.runtime.electron.records = restoreElectronLaunchRecordsFromBranch([...this.input.branch]);
|
|
121
|
+
for (const record of getActiveElectronRecords(this.runtime.electron.records)) {
|
|
122
|
+
if (record.sessionName !== undefined && record.sessionName !== "") {
|
|
123
|
+
this.runtime.sessions.attached.add(getSessionContextKey(record.sessionName, record.namespace) ?? record.sessionName);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
restoreOwnershipRanks() {
|
|
128
|
+
if (this.input.resetRuntimeOwnership) {
|
|
129
|
+
this.runtime.managed.owned.clear();
|
|
130
|
+
this.runtime.electron.resetOwnership();
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
for (const [sessionName, closeRank] of this.branchResourceEvents.managedSessionCloseRanks) {
|
|
134
|
+
untrackOwnedManagedSessionFromBranchClose(this.runtime.managed.owned, sessionName, this.branchResourceEvents.managedSessionActiveRanks.get(sessionName), closeRank);
|
|
135
|
+
}
|
|
136
|
+
this.runtime.electron.removeInactive(this.runtime.electron.records, this.branchResourceEvents.electronLaunchActiveRanks, this.branchResourceEvents.electronLaunchCleanupRanks);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
restoreManagedOwners() {
|
|
140
|
+
for (const [sessionKey, identity] of this.branchResourceEvents.managedSessionActiveIdentities) {
|
|
141
|
+
this.restoreBranchManagedOwner(sessionKey, identity);
|
|
142
|
+
}
|
|
143
|
+
if (this.restoredState.active) {
|
|
144
|
+
trackOwnedManagedSession(this.runtime.managed.owned, this.restoredState.sessionName, this.runtime.managed.cwd, {
|
|
145
|
+
branchOwned: true,
|
|
146
|
+
compatibilityWorkaround: this.runtime.managed.compatibilityWorkaround,
|
|
147
|
+
headedManagedAutosaveDisabled: this.runtime.managed.headedAutosaveDisabled,
|
|
148
|
+
headedManagedAutosaveInterval: this.runtime.managed.headedAutosaveInterval,
|
|
149
|
+
namespace: this.restoredState.namespace,
|
|
150
|
+
socketDir: this.currentLaunch()?.socketDir,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
sessionActiveOnBranch(key) {
|
|
155
|
+
const active = this.branchResourceEvents.managedSessionActiveRanks.get(key);
|
|
156
|
+
const closed = this.branchResourceEvents.managedSessionCloseRanks.get(key);
|
|
157
|
+
return active !== undefined && (closed === undefined || closed < active);
|
|
158
|
+
}
|
|
159
|
+
restoreBranchManagedOwner(key, identity) {
|
|
160
|
+
if (!this.sessionActiveOnBranch(key) ||
|
|
161
|
+
!isRestorableManagedSessionName(identity.sessionName, this.runtime.managed.baseName)) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const launch = this.branchResourceEvents.managedSessionLaunchState.get(key);
|
|
165
|
+
trackOwnedManagedSession(this.runtime.managed.owned, identity.sessionName, launch?.cwd ?? this.ctx.cwd, {
|
|
166
|
+
branchOwned: true,
|
|
167
|
+
compatibilityWorkaround: launch?.compatibilityWorkaround,
|
|
168
|
+
headedManagedAutosaveDisabled: launch?.headedManagedAutosaveDisabled ?? false,
|
|
169
|
+
headedManagedAutosaveInterval: launch?.headedManagedAutosaveInterval,
|
|
170
|
+
namespace: identity.namespace,
|
|
171
|
+
socketDir: launch?.socketDir,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
restoreInterruptedIntents() {
|
|
175
|
+
for (const begin of collectPendingOwnedBrowserIntents(this.input.branch, this.runtime.branch.ownerSessionId)) {
|
|
176
|
+
if (typeof begin.state.sessionName !== "string") {
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
// The persisted wrapper-selected intent proves cleanup scope, not launch success.
|
|
180
|
+
trackOwnedManagedSession(this.runtime.managed.owned, begin.state.sessionName, typeof begin.state.managedSessionCwd === "string"
|
|
181
|
+
? begin.state.managedSessionCwd
|
|
182
|
+
: this.ctx.cwd, {
|
|
183
|
+
branchOwned: true,
|
|
184
|
+
namespace: typeof begin.state.namespace === "string" ? begin.state.namespace : undefined,
|
|
185
|
+
socketDir: typeof begin.state.managedSessionSocketDir === "string"
|
|
186
|
+
? begin.state.managedSessionSocketDir
|
|
187
|
+
: undefined,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
restoreElectronOwners() {
|
|
192
|
+
for (const record of getActiveElectronRecords(this.runtime.electron.records)) {
|
|
193
|
+
this.restoreElectronOwner(record);
|
|
194
|
+
}
|
|
195
|
+
this.runtime.electron.mergeActive(new Map([...this.runtime.electron.records].filter(([, record]) => record.ownerSessionId === this.runtime.branch.ownerSessionId)), { markBranchOwned: true });
|
|
196
|
+
}
|
|
197
|
+
restoreElectronOwner(record) {
|
|
198
|
+
const session = record.sessionName;
|
|
199
|
+
if (session === undefined ||
|
|
200
|
+
session === "" ||
|
|
201
|
+
!isRestorableManagedSessionName(session, this.runtime.managed.baseName)) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const key = getSessionContextKey(session) ?? session;
|
|
205
|
+
if (!this.sessionActiveOnBranch(key)) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
const launch = this.branchResourceEvents.managedSessionLaunchState.get(key);
|
|
209
|
+
trackOwnedManagedSession(this.runtime.managed.owned, session, launch?.cwd ?? this.ctx.cwd, {
|
|
210
|
+
branchOwned: true,
|
|
211
|
+
...headedLaunchTracking(launch),
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
restoreDaemonReceipts() {
|
|
215
|
+
for (const entry of this.input.branch) {
|
|
216
|
+
const event = getBrowserRecord(entry)?.event;
|
|
217
|
+
if (event && event.phase !== "begin") {
|
|
218
|
+
this.restoreDaemonReceipt(event.state);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
restoreDaemonReceipt(state) {
|
|
223
|
+
if (state.ownerSessionId !== this.runtime.branch.ownerSessionId ||
|
|
224
|
+
typeof state.sessionName !== "string") {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
const namespace = typeof state.namespace === "string" ? state.namespace : undefined;
|
|
228
|
+
const key = getAgentBrowserSessionIdentityKey(state.sessionName, namespace);
|
|
229
|
+
if (this.runtime.managed.owned.has(key) &&
|
|
230
|
+
!this.runtime.managed.restore.hasDaemonRestoreKey(state.sessionName, namespace)) {
|
|
231
|
+
this.runtime.managed.restore.restoreDaemonReceipt(state.sessionName, namespace, state.managedSessionDaemon);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
preserveLiveOwners() {
|
|
235
|
+
if (!this.input.resetRuntimeOwnership) {
|
|
236
|
+
// Off-branch live owners still need their established setting for cleanup.
|
|
237
|
+
for (const key of this.runtime.managed.owned.keys()) {
|
|
238
|
+
if (!this.branchResourceEvents.managedSessionActiveIdentities.has(key)) {
|
|
239
|
+
this.runtime.sessions.pages.setConfirmActions(key, this.input.previous.pageState.get(key).confirmActions);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
for (const sessionKey of this.input.previous.attachedKeys) {
|
|
243
|
+
if (this.runtime.managed.owned.has(sessionKey)) {
|
|
244
|
+
this.runtime.sessions.attached.add(sessionKey);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
for (const record of this.runtime.electron.ownedRecords.values()) {
|
|
248
|
+
const sessionKey = getSessionContextKey(record.sessionName);
|
|
249
|
+
if (sessionKey !== undefined &&
|
|
250
|
+
sessionKey !== "" &&
|
|
251
|
+
this.input.previous.attachedKeys.has(sessionKey)) {
|
|
252
|
+
this.runtime.sessions.attached.add(sessionKey);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
run() {
|
|
258
|
+
this.restoreManagedState();
|
|
259
|
+
this.reserveSession();
|
|
260
|
+
this.restoreLaunchState();
|
|
261
|
+
this.restoreRecordingState();
|
|
262
|
+
this.restoreAttachments();
|
|
263
|
+
this.restoreOwnershipRanks();
|
|
264
|
+
this.restoreManagedOwners();
|
|
265
|
+
this.restoreInterruptedIntents();
|
|
266
|
+
this.restoreElectronOwners();
|
|
267
|
+
this.restoreDaemonReceipts();
|
|
268
|
+
this.preserveLiveOwners();
|
|
269
|
+
return [...this.input.branch];
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
export async function restoreBranchBackedState(runtime, ctx, options) {
|
|
273
|
+
const input = await readBranchForRestore(runtime, ctx, options.resetRuntimeOwnership);
|
|
274
|
+
return new BrowserBranchRestoration(runtime, ctx, input).run();
|
|
275
|
+
}
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import { requirePublishedBrowserJournal } from "../browser-journal.js";
|
|
2
|
+
import { buildExecutionPlan } from "../runtime.js";
|
|
3
|
+
import { extractExplicitSessionName, getAgentBrowserSessionIdentityKey } from "../argv-grammar.js";
|
|
4
|
+
import { isRecord } from "../parsing.js";
|
|
5
|
+
import { getAgentBrowserProcessEnvironment, withAgentBrowserProcessEnvironment, } from "../process-environment.js";
|
|
6
|
+
import { withNativeSessionDefaults } from "./native-session-defaults.js";
|
|
7
|
+
import { getBrowserCwdError, resolveExecutionCwd } from "../execution-cwd.js";
|
|
8
|
+
import { AGENT_BROWSER_SCRIPT_DEFAULT_TIMEOUT_MS, bindBrowserCodeCall, runAgentBrowserScript, } from "../input-modes/script.js";
|
|
9
|
+
import { buildValidationFailureResult, resolveAgentBrowserInput, } from "./input-plan.js";
|
|
10
|
+
import { applyAgentBrowserOutputPath } from "./output-file.js";
|
|
11
|
+
import { createBrowserCodeOutput } from "./script-mode.js";
|
|
12
|
+
import { resolveBrowserExecutionIdentity, withBrowserExecutionLock, } from "../managed-session-policy-lock.js";
|
|
13
|
+
import { loadAgentBrowserConfigSync } from "../config.js";
|
|
14
|
+
import { getArtifactPreflightValidationError } from "./extension-artifact-preflight.js";
|
|
15
|
+
import { browserExecutionFailure } from "./extension-result-state.js";
|
|
16
|
+
import { shouldSerializeBrowserCommand } from "./extension-managed-ownership.js";
|
|
17
|
+
import { shouldIncludeProjectConfig } from "./extension-prompt.js";
|
|
18
|
+
import { executeBrowserInvocation } from "./extension-command-admission.js";
|
|
19
|
+
import { createBrowserInvocation } from "./extension-invocation.js";
|
|
20
|
+
function codePreflight(pi, replayError, invocation) {
|
|
21
|
+
if (replayError !== undefined && replayError !== "") {
|
|
22
|
+
return {
|
|
23
|
+
failure: browserExecutionFailure(new Error(replayError), invocation.signal, "validation-error"),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
requirePublishedBrowserJournal(invocation.ctx.sessionManager);
|
|
28
|
+
return { cwd: resolveExecutionCwd(pi, invocation.ctx) };
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
return { failure: browserExecutionFailure(error, invocation.signal, "validation-error") };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
class BrowserCodeExecution {
|
|
35
|
+
runtime;
|
|
36
|
+
invocation;
|
|
37
|
+
operationCwd;
|
|
38
|
+
deadline;
|
|
39
|
+
output = createBrowserCodeOutput();
|
|
40
|
+
nativeEnvironment = getAgentBrowserProcessEnvironment();
|
|
41
|
+
controller = new AbortController();
|
|
42
|
+
abort = () => {
|
|
43
|
+
this.controller.abort(this.invocation.signal?.reason);
|
|
44
|
+
};
|
|
45
|
+
commandIndex = 0;
|
|
46
|
+
journalFailed = false;
|
|
47
|
+
constructor(runtime, invocation, operationCwd) {
|
|
48
|
+
this.runtime = runtime;
|
|
49
|
+
this.invocation = invocation;
|
|
50
|
+
this.operationCwd = operationCwd;
|
|
51
|
+
this.deadline =
|
|
52
|
+
Date.now() + (invocation.params.timeoutMs ?? AGENT_BROWSER_SCRIPT_DEFAULT_TIMEOUT_MS);
|
|
53
|
+
}
|
|
54
|
+
start() {
|
|
55
|
+
const { runtime, invocation } = this;
|
|
56
|
+
invocation.signal?.addEventListener("abort", this.abort, { once: true });
|
|
57
|
+
if (invocation.signal?.aborted === true) {
|
|
58
|
+
this.abort();
|
|
59
|
+
}
|
|
60
|
+
runtime.code.controllers.add(this.controller);
|
|
61
|
+
}
|
|
62
|
+
prepare() {
|
|
63
|
+
const { params } = this.invocation;
|
|
64
|
+
const args = [
|
|
65
|
+
...(params.namespace !== undefined ? ["--namespace", params.namespace] : []),
|
|
66
|
+
...(params.session !== undefined ? ["--session", params.session] : []),
|
|
67
|
+
"get",
|
|
68
|
+
"url",
|
|
69
|
+
];
|
|
70
|
+
const input = resolveAgentBrowserInput({
|
|
71
|
+
params: { args },
|
|
72
|
+
getBatchPreflightValidationError: () => {
|
|
73
|
+
// The identity-selection get-url probe has no batch rows to preflight.
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
return input;
|
|
77
|
+
}
|
|
78
|
+
browserCwd() {
|
|
79
|
+
const { runtime, invocation } = this;
|
|
80
|
+
if (this.nativeEnvironment.AGENT_BROWSER_CONFIG !== undefined) {
|
|
81
|
+
return this.operationCwd;
|
|
82
|
+
}
|
|
83
|
+
const session = invocation.params.session;
|
|
84
|
+
if (session !== undefined && session !== "") {
|
|
85
|
+
const key = getAgentBrowserSessionIdentityKey(session, invocation.params.namespace ?? this.nativeEnvironment.AGENT_BROWSER_NAMESPACE);
|
|
86
|
+
return runtime.managed.owned.get(key)?.cwd ?? invocation.ctx.cwd;
|
|
87
|
+
}
|
|
88
|
+
return runtime.managed.active ? runtime.managed.cwd : invocation.ctx.cwd;
|
|
89
|
+
}
|
|
90
|
+
nativeRoot() {
|
|
91
|
+
const { invocation } = this;
|
|
92
|
+
const config = loadAgentBrowserConfigSync({
|
|
93
|
+
cwd: invocation.ctx.cwd,
|
|
94
|
+
includeProjectConfig: shouldIncludeProjectConfig(invocation.ctx),
|
|
95
|
+
});
|
|
96
|
+
const profile = config.trustedBrowserDefaultProfile;
|
|
97
|
+
const root = process.env.PI_SUBAGENT_ROOT_SESSION_ID;
|
|
98
|
+
const id = process.env.PI_SUBAGENT_CHILD === "1" && root !== undefined && root !== ""
|
|
99
|
+
? root
|
|
100
|
+
: invocation.ctx.sessionManager.getSessionId();
|
|
101
|
+
return {
|
|
102
|
+
id,
|
|
103
|
+
profile: profile?.policy === "always" && !/[\\/~]/.test(profile.name) ? profile.name : undefined,
|
|
104
|
+
executablePath: config.trustedBrowserExecutablePath,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
async runAdmitted(root, input) {
|
|
108
|
+
const cwd = this.browserCwd();
|
|
109
|
+
const error = getBrowserCwdError(cwd);
|
|
110
|
+
if (error !== undefined && error !== "") {
|
|
111
|
+
return browserExecutionFailure(new Error(error), this.controller.signal, "validation-error");
|
|
112
|
+
}
|
|
113
|
+
const selectedRoot = this.runtime.managed.active || this.runtime.managed.freshOrdinal > 0 ? undefined : root;
|
|
114
|
+
return withNativeSessionDefaults(input, { cwd, signal: this.controller.signal, root: selectedRoot }, (nativeInput) => this.runNative(nativeInput));
|
|
115
|
+
}
|
|
116
|
+
async runNative(input) {
|
|
117
|
+
const { runtime } = this;
|
|
118
|
+
const plan = buildExecutionPlan(input.toolArgs, {
|
|
119
|
+
freshSessionName: runtime.managed.name,
|
|
120
|
+
managedSessionActive: runtime.managed.active,
|
|
121
|
+
managedSessionName: runtime.managed.name,
|
|
122
|
+
managedSessionNamespace: runtime.managed.namespace,
|
|
123
|
+
sessionMode: "auto",
|
|
124
|
+
});
|
|
125
|
+
const sessionName = plan.sessionName ?? "default";
|
|
126
|
+
const namespace = plan.namespace === "" ? undefined : plan.namespace;
|
|
127
|
+
const key = getAgentBrowserSessionIdentityKey(sessionName, namespace);
|
|
128
|
+
const identity = {
|
|
129
|
+
usedImplicitSession: plan.usedImplicitSession,
|
|
130
|
+
sessionName,
|
|
131
|
+
namespace,
|
|
132
|
+
key,
|
|
133
|
+
owned: plan.managedSessionName !== undefined || runtime.managed.owned.has(key),
|
|
134
|
+
};
|
|
135
|
+
const run = () => this.runLocked(identity);
|
|
136
|
+
return shouldSerializeBrowserCommand(runtime.managed.owned, runtime.electron.ownedRecords, {
|
|
137
|
+
namespace,
|
|
138
|
+
explicitSessionName: sessionName,
|
|
139
|
+
managedSessionName: runtime.managed.name,
|
|
140
|
+
})
|
|
141
|
+
? runtime.managedSessionExecutionQueue.run(run, this.controller.signal)
|
|
142
|
+
: runtime.callerOwnedSessionExecutionQueues.run(key, namespace, run, this.controller.signal);
|
|
143
|
+
}
|
|
144
|
+
async runLocked(identity) {
|
|
145
|
+
const socketDir = this.runtime.managed.owned.get(identity.key)?.socketDir;
|
|
146
|
+
const env = socketDir !== undefined && socketDir !== "" ? { PI_AGENT_BROWSER_SOCKET_DIR: socketDir } : {};
|
|
147
|
+
return withAgentBrowserProcessEnvironment(env, async () => {
|
|
148
|
+
const lease = await resolveBrowserExecutionIdentity({
|
|
149
|
+
sessionName: identity.sessionName,
|
|
150
|
+
namespace: identity.namespace,
|
|
151
|
+
ownedManagedSession: identity.owned,
|
|
152
|
+
});
|
|
153
|
+
return withBrowserExecutionLock({ identity: lease, deadline: this.deadline, signal: this.controller.signal }, (signal) => this.runCell(signal, identity));
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
async dispatch(inner, innerSignal, identity) {
|
|
157
|
+
if (this.journalFailed) {
|
|
158
|
+
throw new Error("Browser-state persistence failed. Inspect the current page before continuing in another tool call.");
|
|
159
|
+
}
|
|
160
|
+
const bound = bindBrowserCodeCall(inner, {
|
|
161
|
+
sessionName: identity.sessionName,
|
|
162
|
+
namespace: identity.namespace,
|
|
163
|
+
});
|
|
164
|
+
const args = [...bound.args];
|
|
165
|
+
if (identity.usedImplicitSession &&
|
|
166
|
+
!this.runtime.managed.active &&
|
|
167
|
+
this.runtime.managed.name === identity.sessionName &&
|
|
168
|
+
extractExplicitSessionName(inner.args) === undefined) {
|
|
169
|
+
args.splice(args.indexOf("--session"), 2);
|
|
170
|
+
}
|
|
171
|
+
const { toolCallId, ctx, branch } = this.invocation;
|
|
172
|
+
const result = await withAgentBrowserProcessEnvironment({ AGENT_BROWSER_SESSION: this.nativeEnvironment.AGENT_BROWSER_SESSION }, () => executeBrowserInvocation(this.runtime, createBrowserInvocation({
|
|
173
|
+
toolCallId,
|
|
174
|
+
params: {
|
|
175
|
+
args,
|
|
176
|
+
stdin: inner.stdin,
|
|
177
|
+
timeoutMs: Math.min(inner.timeoutMs ?? this.deadline - Date.now(), Math.max(1, this.deadline - Date.now())),
|
|
178
|
+
},
|
|
179
|
+
signal: innerSignal,
|
|
180
|
+
ctx,
|
|
181
|
+
nativeToolCallId: toolCallId,
|
|
182
|
+
capturedCwd: this.operationCwd,
|
|
183
|
+
modelVisible: false,
|
|
184
|
+
commandIndex: this.commandIndex++,
|
|
185
|
+
selectedBranch: branch,
|
|
186
|
+
})));
|
|
187
|
+
if (isRecord(result.details) && result.details.browserStatePersistence !== undefined) {
|
|
188
|
+
this.journalFailed = true;
|
|
189
|
+
throw new Error("The browser effect may already have happened and its finish could not be persisted. Inspect before continuing; dependent commands were stopped.");
|
|
190
|
+
}
|
|
191
|
+
return this.output.observe(result);
|
|
192
|
+
}
|
|
193
|
+
async runCell(signal, identity) {
|
|
194
|
+
const run = await runAgentBrowserScript({
|
|
195
|
+
code: this.invocation.params.code,
|
|
196
|
+
signal,
|
|
197
|
+
timeoutMs: Math.max(1, this.deadline - Date.now()),
|
|
198
|
+
emitImage: (image) => this.output.emitImage(image),
|
|
199
|
+
dispatch: (inner, innerSignal) => this.dispatch(inner, innerSignal, identity),
|
|
200
|
+
});
|
|
201
|
+
const result = await this.finish(run, identity);
|
|
202
|
+
const path = this.invocation.params.outputPath;
|
|
203
|
+
if (path === undefined || path === "") {
|
|
204
|
+
return result;
|
|
205
|
+
}
|
|
206
|
+
return this.runtime.artifacts.queue.run(() => this.writeOutput(result, path));
|
|
207
|
+
}
|
|
208
|
+
async finish(run, identity) {
|
|
209
|
+
const result = await this.output.finish(run, identity.sessionName, identity.namespace);
|
|
210
|
+
if (this.journalFailed && isRecord(result.details)) {
|
|
211
|
+
result.isError = true;
|
|
212
|
+
result.details.resultCategory = "failure";
|
|
213
|
+
result.details.failureCategory = "upstream-error";
|
|
214
|
+
result.details.error =
|
|
215
|
+
"Browser-state persistence failed. Dependent calls were stopped; inspect before continuing because already-dispatched effects may have happened.";
|
|
216
|
+
}
|
|
217
|
+
if (isRecord(result.details)) {
|
|
218
|
+
result.details.browserEventVersion = 1;
|
|
219
|
+
}
|
|
220
|
+
return result;
|
|
221
|
+
}
|
|
222
|
+
async writeOutput(result, outputPath) {
|
|
223
|
+
const error = getArtifactPreflightValidationError({
|
|
224
|
+
args: [],
|
|
225
|
+
cwd: this.operationCwd,
|
|
226
|
+
outputPath,
|
|
227
|
+
activeRecordingReservations: [...this.runtime.recordings.active.values()],
|
|
228
|
+
});
|
|
229
|
+
if (error !== undefined && error !== "") {
|
|
230
|
+
const failure = browserExecutionFailure(new Error(error), undefined, "validation-error");
|
|
231
|
+
return {
|
|
232
|
+
...result,
|
|
233
|
+
isError: true,
|
|
234
|
+
content: [...failure.content, ...result.content],
|
|
235
|
+
details: {
|
|
236
|
+
...(isRecord(result.details) ? result.details : {}),
|
|
237
|
+
...(isRecord(failure.details) ? failure.details : {}),
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
return applyAgentBrowserOutputPath({
|
|
242
|
+
cwd: this.operationCwd,
|
|
243
|
+
outputPath,
|
|
244
|
+
preserveTextContent: true,
|
|
245
|
+
result,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
async run() {
|
|
249
|
+
this.start();
|
|
250
|
+
const timer = setTimeout(() => this.controller.abort(new DOMException("Browser code deadline exceeded.", "TimeoutError")), Math.max(0, this.deadline - Date.now()));
|
|
251
|
+
try {
|
|
252
|
+
const input = this.prepare();
|
|
253
|
+
if (input.status === "invalid") {
|
|
254
|
+
return buildValidationFailureResult(input);
|
|
255
|
+
}
|
|
256
|
+
const root = this.nativeRoot();
|
|
257
|
+
const session = this.invocation.params.session;
|
|
258
|
+
const implicit = (session === undefined || session === "") &&
|
|
259
|
+
this.nativeEnvironment.AGENT_BROWSER_CONFIG === undefined;
|
|
260
|
+
return await (implicit
|
|
261
|
+
? this.runtime.managedSessionExecutionQueue.run(() => this.runAdmitted(root, input), this.controller.signal)
|
|
262
|
+
: this.runAdmitted(root, input));
|
|
263
|
+
}
|
|
264
|
+
catch (error) {
|
|
265
|
+
return browserExecutionFailure(error, this.controller.signal);
|
|
266
|
+
}
|
|
267
|
+
finally {
|
|
268
|
+
clearTimeout(timer);
|
|
269
|
+
this.runtime.code.controllers.delete(this.controller);
|
|
270
|
+
this.invocation.signal?.removeEventListener("abort", this.abort);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
export function executeCode(runtime, invocation) {
|
|
275
|
+
const prepared = codePreflight(runtime.pi, runtime.branch.replayError, invocation);
|
|
276
|
+
if ("failure" in prepared) {
|
|
277
|
+
return Promise.resolve(prepared.failure);
|
|
278
|
+
}
|
|
279
|
+
return new BrowserCodeExecution(runtime, invocation, prepared.cwd).run();
|
|
280
|
+
}
|