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,98 @@
|
|
|
1
|
+
import { getActiveElectronRecords } from "./browser-run/session-state.js";
|
|
2
|
+
import { buildValidationFailureResult } from "./input-plan.js";
|
|
3
|
+
import { applyAgentBrowserOutputPath } from "./output-file.js";
|
|
4
|
+
import { resolveBrowserExecutionIdentity, withBrowserExecutionLocks, } from "../managed-session-policy-lock.js";
|
|
5
|
+
import { getArtifactPreflightValidationError } from "./extension-artifact-preflight.js";
|
|
6
|
+
import { browserExecutionFailure } from "./extension-result-state.js";
|
|
7
|
+
import { shouldSerializeElectronHostInput } from "./extension-electron-ownership.js";
|
|
8
|
+
import { warnRecordingPersistence } from "./extension-recording.js";
|
|
9
|
+
import { runElectronHostInput } from "./extension-host-run.js";
|
|
10
|
+
class ElectronHostCoordinator {
|
|
11
|
+
runtime;
|
|
12
|
+
call;
|
|
13
|
+
constructor(runtime, call) {
|
|
14
|
+
this.runtime = runtime;
|
|
15
|
+
this.call = call;
|
|
16
|
+
}
|
|
17
|
+
async cleanup(signal) {
|
|
18
|
+
this.runtime.recordings.flush();
|
|
19
|
+
const path = this.call.outputPath;
|
|
20
|
+
const error = path !== undefined && path !== ""
|
|
21
|
+
? getArtifactPreflightValidationError({
|
|
22
|
+
activeRecordingReservations: [...this.runtime.recordings.active.values()],
|
|
23
|
+
args: [],
|
|
24
|
+
cwd: this.call.operationCwd,
|
|
25
|
+
outputPath: path,
|
|
26
|
+
})
|
|
27
|
+
: undefined;
|
|
28
|
+
if (error !== undefined && error !== "") {
|
|
29
|
+
return warnRecordingPersistence(this.runtime.recordings.dirty, buildValidationFailureResult({
|
|
30
|
+
...this.call.resolvedInput,
|
|
31
|
+
attemptedKind: this.call.resolvedInput.kind,
|
|
32
|
+
kind: "invalid",
|
|
33
|
+
status: "invalid",
|
|
34
|
+
validationError: error,
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
const result = await runElectronHostInput(this.runtime, this.call, signal);
|
|
38
|
+
return result
|
|
39
|
+
? applyAgentBrowserOutputPath({
|
|
40
|
+
cwd: this.call.operationCwd,
|
|
41
|
+
outputPath: path,
|
|
42
|
+
result: warnRecordingPersistence(this.runtime.recordings.dirty, result),
|
|
43
|
+
})
|
|
44
|
+
: result;
|
|
45
|
+
}
|
|
46
|
+
execute(signal = this.call.signal) {
|
|
47
|
+
return this.call.compiledElectron?.action === "cleanup"
|
|
48
|
+
? this.runtime.artifacts.queue.run(() => this.cleanup(signal))
|
|
49
|
+
: runElectronHostInput(this.runtime, this.call, signal);
|
|
50
|
+
}
|
|
51
|
+
selectedSessions() {
|
|
52
|
+
const compiled = this.call.compiledElectron;
|
|
53
|
+
const records = this.runtime.electron.forHostInput({
|
|
54
|
+
compiledElectron: compiled,
|
|
55
|
+
ownerSessionId: this.call.ctx.sessionManager.getSessionId(),
|
|
56
|
+
});
|
|
57
|
+
const launchId = compiled && "launchId" in compiled ? compiled.launchId : undefined;
|
|
58
|
+
const selected = launchId !== undefined && launchId !== ""
|
|
59
|
+
? [records.get(launchId)].filter((record) => record !== undefined)
|
|
60
|
+
: getActiveElectronRecords(records);
|
|
61
|
+
const sessions = selected.flatMap((record) => record.sessionName !== undefined && record.sessionName !== ""
|
|
62
|
+
? [{ sessionName: record.sessionName, namespace: record.namespace }]
|
|
63
|
+
: []);
|
|
64
|
+
if (compiled?.action === "probe" &&
|
|
65
|
+
(launchId === undefined || launchId === "") &&
|
|
66
|
+
this.runtime.managed.active) {
|
|
67
|
+
sessions.push({
|
|
68
|
+
sessionName: this.runtime.managed.name,
|
|
69
|
+
namespace: this.runtime.managed.namespace,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return sessions;
|
|
73
|
+
}
|
|
74
|
+
async run() {
|
|
75
|
+
if (!shouldSerializeElectronHostInput(this.call.compiledElectron)) {
|
|
76
|
+
return this.execute();
|
|
77
|
+
}
|
|
78
|
+
const sessions = this.selectedSessions();
|
|
79
|
+
if (sessions.length === 0) {
|
|
80
|
+
return this.execute();
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
const identities = await Promise.all(sessions.map((session) => resolveBrowserExecutionIdentity({ ...session, ownedManagedSession: true })));
|
|
84
|
+
return await withBrowserExecutionLocks({
|
|
85
|
+
identities,
|
|
86
|
+
signal: this.call.signal,
|
|
87
|
+
deadline: Date.now() + this.call.executionTimeoutMs,
|
|
88
|
+
waitOnly: true,
|
|
89
|
+
}, (signal) => this.execute(signal));
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
return browserExecutionFailure(error, this.call.signal);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
export function runCoordinatedElectronHostInput(runtime, call) {
|
|
97
|
+
return new ElectronHostCoordinator(runtime, call).run();
|
|
98
|
+
}
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { appendBrowserTransition, applyArtifactChanges, artifactChanges, browserStateEffects, } from "../browser-transcript.js";
|
|
3
|
+
import { appendBrowserRecord } from "../browser-journal.js";
|
|
4
|
+
import { createFreshSessionName } from "../runtime.js";
|
|
5
|
+
import { getAgentBrowserSessionIdentityKey } from "../argv-grammar.js";
|
|
6
|
+
import { isRecord } from "../parsing.js";
|
|
7
|
+
import { inspectManagedSessionDaemon } from "./browser-run/managed-session-daemon-policy.js";
|
|
8
|
+
import { getActiveElectronRecords, getSessionContextKey } from "./browser-run/session-state.js";
|
|
9
|
+
import { handleElectronHostInput } from "./electron-host/index.js";
|
|
10
|
+
import { formatSessionArtifactRetentionSummary } from "../results/artifact-manifest.js";
|
|
11
|
+
import { browserExecutionFailure, invocationArtifactManifest, browserPageChanges, } from "./extension-result-state.js";
|
|
12
|
+
import { getCleanupResultsClosedManagedSessionIdentities, isElectronLaunchRecord, syncElectronCleanupManagedSessions, } from "./extension-electron-ownership.js";
|
|
13
|
+
class ElectronHostTransaction {
|
|
14
|
+
runtime;
|
|
15
|
+
call;
|
|
16
|
+
executionSignal;
|
|
17
|
+
electronHostLaunchRecords;
|
|
18
|
+
hostAffecting;
|
|
19
|
+
workingPageState;
|
|
20
|
+
priorPages;
|
|
21
|
+
priorManifest;
|
|
22
|
+
operationId;
|
|
23
|
+
launchId;
|
|
24
|
+
selected;
|
|
25
|
+
keys;
|
|
26
|
+
begin;
|
|
27
|
+
electronHostResult;
|
|
28
|
+
constructor(runtime, call, executionSignal = call.signal) {
|
|
29
|
+
this.runtime = runtime;
|
|
30
|
+
this.call = call;
|
|
31
|
+
this.executionSignal = executionSignal;
|
|
32
|
+
this.electronHostLaunchRecords = this.runtime.electron.forHostInput({
|
|
33
|
+
compiledElectron: this.call.compiledElectron,
|
|
34
|
+
ownerSessionId: this.call.ctx.sessionManager.getSessionId(),
|
|
35
|
+
});
|
|
36
|
+
this.hostAffecting =
|
|
37
|
+
this.call.compiledElectron !== undefined &&
|
|
38
|
+
["cleanup", "probe"].includes(this.call.compiledElectron.action);
|
|
39
|
+
this.workingPageState = this.runtime.sessions.pages.fork();
|
|
40
|
+
this.priorPages = this.workingPageState.views();
|
|
41
|
+
this.priorManifest = this.runtime.artifacts.manifest;
|
|
42
|
+
this.operationId = randomUUID();
|
|
43
|
+
this.launchId =
|
|
44
|
+
this.call.compiledElectron && "launchId" in this.call.compiledElectron
|
|
45
|
+
? this.call.compiledElectron.launchId
|
|
46
|
+
: undefined;
|
|
47
|
+
this.selected =
|
|
48
|
+
this.launchId !== undefined && this.launchId !== ""
|
|
49
|
+
? [this.electronHostLaunchRecords.get(this.launchId)].filter((record) => record !== undefined)
|
|
50
|
+
: getActiveElectronRecords(this.electronHostLaunchRecords);
|
|
51
|
+
this.keys = this.selectedKeys();
|
|
52
|
+
this.begin = this.beginRecord();
|
|
53
|
+
}
|
|
54
|
+
selectedKeys() {
|
|
55
|
+
const keys = new Set(this.selected.flatMap((record) => record.sessionName !== undefined && record.sessionName !== ""
|
|
56
|
+
? [getAgentBrowserSessionIdentityKey(record.sessionName, record.namespace)]
|
|
57
|
+
: []));
|
|
58
|
+
if (this.call.compiledElectron?.action === "probe" &&
|
|
59
|
+
!(this.launchId !== undefined && this.launchId !== "") &&
|
|
60
|
+
this.runtime.managed.active) {
|
|
61
|
+
keys.add(getAgentBrowserSessionIdentityKey(this.runtime.managed.name, this.runtime.managed.namespace));
|
|
62
|
+
}
|
|
63
|
+
return keys;
|
|
64
|
+
}
|
|
65
|
+
beginRecord() {
|
|
66
|
+
return {
|
|
67
|
+
event: {
|
|
68
|
+
version: 1,
|
|
69
|
+
phase: "begin",
|
|
70
|
+
operationId: this.operationId,
|
|
71
|
+
toolCallId: this.call.toolCallId,
|
|
72
|
+
commandIndex: this.call.commandIndex ?? 0,
|
|
73
|
+
isError: true,
|
|
74
|
+
state: {},
|
|
75
|
+
pages: [...this.keys].map((key) => ({
|
|
76
|
+
key,
|
|
77
|
+
refs: { kind: "unknown" },
|
|
78
|
+
unknown: true,
|
|
79
|
+
})),
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
async admit() {
|
|
84
|
+
if (this.hostAffecting) {
|
|
85
|
+
try {
|
|
86
|
+
if (!(await appendBrowserRecord(this.call.ctx.sessionManager, () => appendBrowserTransition(this.runtime.pi, this.begin), this.begin, this.call.branch)) ||
|
|
87
|
+
!this.call.branch.isCurrent()) {
|
|
88
|
+
throw new Error("The selected Pi branch changed before host-operation admission.");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
catch (error) {
|
|
92
|
+
return browserExecutionFailure(new Error("Could not persist Electron/browser-state begin; the host operation was not run.", { cause: error }), this.executionSignal);
|
|
93
|
+
}
|
|
94
|
+
this.runtime.sessions.pages.applyBrowserRecord(this.begin);
|
|
95
|
+
}
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
async dispatch() {
|
|
99
|
+
this.electronHostResult = await handleElectronHostInput({
|
|
100
|
+
attachedSessionKeys: this.runtime.sessions.attached,
|
|
101
|
+
compiledElectron: this.call.compiledElectron,
|
|
102
|
+
cwd: this.call.ctx.cwd,
|
|
103
|
+
electronChildProcesses: this.runtime.electron.childProcesses,
|
|
104
|
+
electronLaunchRecords: this.electronHostLaunchRecords,
|
|
105
|
+
implicitSessionCloseTimeoutMs: this.runtime.implicitSessionCloseTimeoutMs,
|
|
106
|
+
managedSessionActive: this.runtime.managed.active,
|
|
107
|
+
managedSessionName: this.runtime.managed.name,
|
|
108
|
+
managedSessionNamespace: this.runtime.managed.namespace,
|
|
109
|
+
managedSessionRestoreState: this.runtime.managed.restore,
|
|
110
|
+
ownedManagedSessions: this.runtime.managed.owned,
|
|
111
|
+
redactedCompiledElectron: this.call.redactedCompiledElectron,
|
|
112
|
+
sessionPageState: this.workingPageState,
|
|
113
|
+
signal: this.executionSignal,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
cleanupRecords() {
|
|
117
|
+
const details = this.electronHostResult?.details;
|
|
118
|
+
if (!isRecord(details) || !isRecord(details.electron) || !isRecord(details.electron.cleanup)) {
|
|
119
|
+
return [];
|
|
120
|
+
}
|
|
121
|
+
const rows = details.electron.cleanup.results;
|
|
122
|
+
return Array.isArray(rows) ? rows : [];
|
|
123
|
+
}
|
|
124
|
+
resetManagedSession() {
|
|
125
|
+
this.runtime.managed.active = false;
|
|
126
|
+
this.runtime.managed.compatibilityWorkaround = undefined;
|
|
127
|
+
this.runtime.managed.headedAutosaveDisabled = false;
|
|
128
|
+
this.runtime.managed.headedAutosaveInterval = undefined;
|
|
129
|
+
this.runtime.managed.namespace = undefined;
|
|
130
|
+
this.runtime.managed.freshOrdinal += 1;
|
|
131
|
+
this.runtime.managed.name = createFreshSessionName(this.runtime.managed.baseName, this.runtime.ephemeralSessionSeed, this.runtime.managed.freshOrdinal);
|
|
132
|
+
}
|
|
133
|
+
retireClosedIdentity(identity) {
|
|
134
|
+
this.runtime.recordings.retire(identity.sessionName, identity.namespace);
|
|
135
|
+
const key = getSessionContextKey(identity.sessionName, identity.namespace) ?? identity.sessionName;
|
|
136
|
+
this.runtime.sessions.clear(key);
|
|
137
|
+
this.workingPageState.clearSession(key);
|
|
138
|
+
if (key ===
|
|
139
|
+
(getSessionContextKey(this.runtime.managed.name, this.runtime.managed.namespace) ??
|
|
140
|
+
this.runtime.managed.name)) {
|
|
141
|
+
this.resetManagedSession();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
cleanedLaunchIds(records) {
|
|
145
|
+
const ids = new Set();
|
|
146
|
+
for (const row of records) {
|
|
147
|
+
if (isRecord(row) && isElectronLaunchRecord(row.record)) {
|
|
148
|
+
ids.add(row.record.launchId);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return ids;
|
|
152
|
+
}
|
|
153
|
+
applyCleanup() {
|
|
154
|
+
const result = this.electronHostResult;
|
|
155
|
+
if (!result || this.call.compiledElectron?.action !== "cleanup") {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
this.runtime.branch.advanceState();
|
|
159
|
+
const records = this.cleanupRecords();
|
|
160
|
+
const cleanedLaunchIds = this.cleanedLaunchIds(records);
|
|
161
|
+
this.runtime.electron.replaceActive(this.electronHostLaunchRecords, cleanedLaunchIds);
|
|
162
|
+
this.runtime.electron.mergeCleanup(records);
|
|
163
|
+
const namespace = isRecord(result.details) && typeof result.details.namespace === "string"
|
|
164
|
+
? result.details.namespace
|
|
165
|
+
: undefined;
|
|
166
|
+
const identities = getCleanupResultsClosedManagedSessionIdentities(records, namespace);
|
|
167
|
+
syncElectronCleanupManagedSessions(this.runtime.managed.owned, records, namespace);
|
|
168
|
+
for (const identity of identities) {
|
|
169
|
+
this.retireClosedIdentity(identity);
|
|
170
|
+
}
|
|
171
|
+
if (this.runtime.artifacts.manifest && isRecord(result.details)) {
|
|
172
|
+
result.details.artifactRetentionSummary = formatSessionArtifactRetentionSummary(this.runtime.artifacts.manifest);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
selectedRecordForKey(key) {
|
|
176
|
+
return this.selected.find((candidate) => candidate.sessionName !== undefined &&
|
|
177
|
+
candidate.sessionName !== "" &&
|
|
178
|
+
getAgentBrowserSessionIdentityKey(candidate.sessionName, candidate.namespace) === key);
|
|
179
|
+
}
|
|
180
|
+
snapshotChanged(key) {
|
|
181
|
+
const snapshot = this.workingPageState.get(key).refSnapshot;
|
|
182
|
+
return (snapshot !== undefined &&
|
|
183
|
+
snapshot.snapshotId !== this.priorPages.get(key)?.refSnapshot?.snapshotId);
|
|
184
|
+
}
|
|
185
|
+
headedAutosaveInterval(key) {
|
|
186
|
+
const owner = this.runtime.managed.owned.get(key);
|
|
187
|
+
return (owner?.headedManagedAutosaveInterval ??
|
|
188
|
+
(owner?.headedManagedAutosaveDisabled === true ? "0" : undefined));
|
|
189
|
+
}
|
|
190
|
+
async bindSnapshotGeneration(key) {
|
|
191
|
+
if (!this.snapshotChanged(key)) {
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
const record = this.selectedRecordForKey(key);
|
|
195
|
+
const daemon = await inspectManagedSessionDaemon({
|
|
196
|
+
cwd: this.call.ctx.cwd,
|
|
197
|
+
sessionName: record?.sessionName ?? this.runtime.managed.name,
|
|
198
|
+
namespace: record?.namespace ?? this.runtime.managed.namespace,
|
|
199
|
+
signal: this.executionSignal,
|
|
200
|
+
includeGeneration: true,
|
|
201
|
+
headedManagedAutosaveInterval: this.headedAutosaveInterval(key),
|
|
202
|
+
});
|
|
203
|
+
this.workingPageState.bindSnapshotGeneration(key, daemon.status === "active" ? daemon.generation : undefined);
|
|
204
|
+
}
|
|
205
|
+
buildFinish(result) {
|
|
206
|
+
const changes = browserPageChanges(this.workingPageState, this.priorPages, [...this.keys]);
|
|
207
|
+
return {
|
|
208
|
+
event: {
|
|
209
|
+
version: 1,
|
|
210
|
+
phase: this.hostAffecting ? "finish" : "state",
|
|
211
|
+
operationId: this.operationId,
|
|
212
|
+
toolCallId: this.call.toolCallId,
|
|
213
|
+
commandIndex: this.call.commandIndex ?? 0,
|
|
214
|
+
isError: result.isError === true,
|
|
215
|
+
state: browserStateEffects(isRecord(result.details) ? result.details : {}),
|
|
216
|
+
pages: changes.pages,
|
|
217
|
+
artifacts: artifactChanges(this.priorManifest, this.runtime.artifacts.manifest),
|
|
218
|
+
},
|
|
219
|
+
...(changes.snapshot ? { snapshot: changes.snapshot } : {}),
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
persistenceFailure(result, error) {
|
|
223
|
+
if (this.call.branch.isCurrent()) {
|
|
224
|
+
this.runtime.sessions.pages.applyBrowserRecord(this.begin);
|
|
225
|
+
}
|
|
226
|
+
return {
|
|
227
|
+
...browserExecutionFailure(new Error("The host operation finished, but its state could not be persisted. Inspect before retrying; changes may already have happened.", { cause: error }), this.executionSignal),
|
|
228
|
+
details: {
|
|
229
|
+
...(isRecord(result.details) ? result.details : {}),
|
|
230
|
+
browserStatePersistence: "finish-unconfirmed",
|
|
231
|
+
resultCategory: "failure",
|
|
232
|
+
failureCategory: "upstream-error",
|
|
233
|
+
nextActions: undefined,
|
|
234
|
+
},
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
async persistFinish() {
|
|
238
|
+
const result = this.electronHostResult;
|
|
239
|
+
if (!result || !this.hostAffecting || !this.call.branch.isCurrent()) {
|
|
240
|
+
return undefined;
|
|
241
|
+
}
|
|
242
|
+
for (const key of this.keys) {
|
|
243
|
+
// Bind each ordered host snapshot to its live daemon before persisting one canonical finish.
|
|
244
|
+
// oxlint-disable-next-line no-await-in-loop
|
|
245
|
+
await this.bindSnapshotGeneration(key);
|
|
246
|
+
}
|
|
247
|
+
const finish = this.buildFinish(result);
|
|
248
|
+
try {
|
|
249
|
+
if (!(await appendBrowserRecord(this.call.ctx.sessionManager, () => appendBrowserTransition(this.runtime.pi, finish), finish, this.call.branch)) ||
|
|
250
|
+
!this.call.branch.isCurrent()) {
|
|
251
|
+
throw new Error("The selected Pi branch changed before host-state confirmation.");
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
return this.persistenceFailure(result, error);
|
|
256
|
+
}
|
|
257
|
+
this.runtime.sessions.pages.applyBrowserRecord(finish);
|
|
258
|
+
this.runtime.artifacts.manifest = applyArtifactChanges(this.runtime.artifacts.manifest, finish.event.artifacts);
|
|
259
|
+
if (isRecord(result.details)) {
|
|
260
|
+
result.details.browserEventVersion = 1;
|
|
261
|
+
result.details.artifactManifest = invocationArtifactManifest(this.runtime.artifacts.manifest, this.priorManifest, result.details);
|
|
262
|
+
}
|
|
263
|
+
return undefined;
|
|
264
|
+
}
|
|
265
|
+
complete() {
|
|
266
|
+
if (this.electronHostResult && this.executionSignal?.aborted === true) {
|
|
267
|
+
const failure = browserExecutionFailure(this.executionSignal.reason, this.executionSignal);
|
|
268
|
+
return {
|
|
269
|
+
...this.electronHostResult,
|
|
270
|
+
...failure,
|
|
271
|
+
details: {
|
|
272
|
+
...(isRecord(this.electronHostResult.details) ? this.electronHostResult.details : {}),
|
|
273
|
+
...(isRecord(failure.details) ? failure.details : {}),
|
|
274
|
+
},
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
return this.electronHostResult;
|
|
278
|
+
}
|
|
279
|
+
async run() {
|
|
280
|
+
const admissionFailure = await this.admit();
|
|
281
|
+
if (admissionFailure) {
|
|
282
|
+
return admissionFailure;
|
|
283
|
+
}
|
|
284
|
+
await this.dispatch();
|
|
285
|
+
this.applyCleanup();
|
|
286
|
+
const failure = await this.persistFinish();
|
|
287
|
+
if (failure) {
|
|
288
|
+
return failure;
|
|
289
|
+
}
|
|
290
|
+
return this.complete();
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
export function runElectronHostInput(runtime, call, executionSignal = call.signal) {
|
|
294
|
+
return new ElectronHostTransaction(runtime, call, executionSignal).run();
|
|
295
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { getBrowserRecord } from "../browser-transcript.js";
|
|
2
|
+
class PendingOwnedBrowserIntents {
|
|
3
|
+
ownerSessionId;
|
|
4
|
+
begins = new Map();
|
|
5
|
+
constructor(ownerSessionId) {
|
|
6
|
+
this.ownerSessionId = ownerSessionId;
|
|
7
|
+
}
|
|
8
|
+
clearPage(key) {
|
|
9
|
+
for (const [id, begin] of this.begins) {
|
|
10
|
+
if (begin.pages?.some((page) => page.key === key) === true) {
|
|
11
|
+
this.begins.delete(id);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
apply(event) {
|
|
16
|
+
if (event.phase === "begin" &&
|
|
17
|
+
event.state.ownerSessionId === this.ownerSessionId &&
|
|
18
|
+
event.state.wrapperManaged === true) {
|
|
19
|
+
this.begins.set(event.operationId, event);
|
|
20
|
+
}
|
|
21
|
+
else if (event.phase === "finish") {
|
|
22
|
+
this.begins.delete(event.operationId);
|
|
23
|
+
}
|
|
24
|
+
for (const page of event.pages ?? []) {
|
|
25
|
+
if (page.clear) {
|
|
26
|
+
this.clearPage(page.key);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** Interrupted owned intents retain cleanup scope, never proof of a successful launch. */
|
|
32
|
+
export function collectPendingOwnedBrowserIntents(branch, ownerSessionId) {
|
|
33
|
+
const pending = new PendingOwnedBrowserIntents(ownerSessionId);
|
|
34
|
+
for (const entry of branch) {
|
|
35
|
+
const event = getBrowserRecord(entry)?.event;
|
|
36
|
+
if (event) {
|
|
37
|
+
pending.apply(event);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return [...pending.begins.values()];
|
|
41
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { cleanupSecureTempArtifacts } from "../temp.js";
|
|
2
|
+
import { getActiveElectronRecords } from "./browser-run/session-state.js";
|
|
3
|
+
import { cleanupActiveElectronHostLaunches } from "./electron-host/index.js";
|
|
4
|
+
import { loadAgentBrowserConfigSync } from "../config.js";
|
|
5
|
+
import { closeOwnedManagedSessionsExcept } from "./extension-managed-ownership.js";
|
|
6
|
+
import { getCleanupResultsClosedManagedSessionIdentities, getCleanupResultsPreservedUserDataDirs, getOffBranchOwnedElectronLaunchRecords, syncElectronCleanupManagedSessions, } from "./extension-electron-ownership.js";
|
|
7
|
+
import { shouldIncludeProjectConfig } from "./extension-prompt.js";
|
|
8
|
+
import { notifyRecordingPersistence } from "./extension-recording.js";
|
|
9
|
+
import { recoverScriptSessionLeasesWithinQueue } from "./extension-script-leases.js";
|
|
10
|
+
import { restoreBranchBackedState } from "./extension-branch-restore.js";
|
|
11
|
+
class BrowserLifecycle {
|
|
12
|
+
runtime;
|
|
13
|
+
constructor(runtime) {
|
|
14
|
+
this.runtime = runtime;
|
|
15
|
+
}
|
|
16
|
+
async restore(ctx, resetRuntimeOwnership) {
|
|
17
|
+
const { runtime } = this;
|
|
18
|
+
const branch = await restoreBranchBackedState(runtime, ctx, { resetRuntimeOwnership });
|
|
19
|
+
if (resetRuntimeOwnership) {
|
|
20
|
+
runtime.electron.childProcesses = new Map();
|
|
21
|
+
runtime.prompt.registerWebSearch(loadAgentBrowserConfigSync({
|
|
22
|
+
cwd: ctx.cwd,
|
|
23
|
+
includeProjectConfig: shouldIncludeProjectConfig(ctx),
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
await recoverScriptSessionLeasesWithinQueue(runtime, ctx, branch);
|
|
27
|
+
runtime.recordings.flush();
|
|
28
|
+
notifyRecordingPersistence(runtime.recordings.dirty, ctx);
|
|
29
|
+
}
|
|
30
|
+
start(ctx) {
|
|
31
|
+
return this.runtime.managedSessionExecutionQueue.run(() => this.runtime.artifacts.queue.run(() => this.restore(ctx, true)));
|
|
32
|
+
}
|
|
33
|
+
async tree(ctx) {
|
|
34
|
+
this.runtime.branch.invalidateRestore();
|
|
35
|
+
await this.runtime.code.settle();
|
|
36
|
+
await this.runtime.managedSessionExecutionQueue.run(() => this.runtime.artifacts.queue.run(() => this.restore(ctx, false)));
|
|
37
|
+
}
|
|
38
|
+
async cleanup(ctx, quitting) {
|
|
39
|
+
const { runtime } = this;
|
|
40
|
+
const active = getActiveElectronRecords(runtime.electron.records);
|
|
41
|
+
const preserved = quitting
|
|
42
|
+
? active
|
|
43
|
+
.filter((record) => !runtime.electron.ownedRecords.has(record.launchId))
|
|
44
|
+
.map((record) => record.userDataDir)
|
|
45
|
+
: active.map((record) => record.userDataDir);
|
|
46
|
+
const records = quitting
|
|
47
|
+
? runtime.electron.ownedRecords
|
|
48
|
+
: getOffBranchOwnedElectronLaunchRecords(runtime.electron.ownedRecords, runtime.electron.records);
|
|
49
|
+
const results = await cleanupActiveElectronHostLaunches({
|
|
50
|
+
attachedSessionKeys: runtime.sessions.attached,
|
|
51
|
+
cwd: ctx?.cwd ?? runtime.managed.cwd,
|
|
52
|
+
electronChildProcesses: runtime.electron.childProcesses,
|
|
53
|
+
electronLaunchRecords: records,
|
|
54
|
+
managedSessionRestoreState: runtime.managed.restore,
|
|
55
|
+
ownedManagedSessions: runtime.managed.owned,
|
|
56
|
+
sessionPageState: runtime.sessions.pages,
|
|
57
|
+
timeoutMs: runtime.implicitSessionCloseTimeoutMs,
|
|
58
|
+
});
|
|
59
|
+
const preservePaths = [
|
|
60
|
+
...new Set([...preserved, ...getCleanupResultsPreservedUserDataDirs(results)]),
|
|
61
|
+
];
|
|
62
|
+
syncElectronCleanupManagedSessions(runtime.managed.owned, results);
|
|
63
|
+
for (const identity of getCleanupResultsClosedManagedSessionIdentities(results)) {
|
|
64
|
+
runtime.recordings.retire(identity.sessionName, identity.namespace);
|
|
65
|
+
}
|
|
66
|
+
await closeOwnedManagedSessionsExcept(runtime.managed.owned, runtime.sessions, {
|
|
67
|
+
restore: runtime.managed.restore,
|
|
68
|
+
timeoutMs: runtime.implicitSessionCloseTimeoutMs,
|
|
69
|
+
}, {
|
|
70
|
+
keepSessionName: !quitting && runtime.managed.active ? runtime.managed.name : undefined,
|
|
71
|
+
keepNamespace: !quitting && runtime.managed.active ? runtime.managed.namespace : undefined,
|
|
72
|
+
onClosed: (owner) => runtime.recordings.retire(owner.sessionName, owner.namespace),
|
|
73
|
+
});
|
|
74
|
+
runtime.recordings.flush();
|
|
75
|
+
notifyRecordingPersistence(runtime.recordings.dirty, ctx);
|
|
76
|
+
return preservePaths;
|
|
77
|
+
}
|
|
78
|
+
reset() {
|
|
79
|
+
const { runtime } = this;
|
|
80
|
+
runtime.managed.reset();
|
|
81
|
+
runtime.sessions.reset();
|
|
82
|
+
runtime.artifacts.manifest = undefined;
|
|
83
|
+
runtime.recordings.resetIfClean();
|
|
84
|
+
runtime.electron.reset();
|
|
85
|
+
}
|
|
86
|
+
async shutdown(ctx, quitting) {
|
|
87
|
+
await this.runtime.code.settle();
|
|
88
|
+
this.runtime.branch.invalidate();
|
|
89
|
+
const preservePaths = await this.runtime.managedSessionExecutionQueue.run(() => this.runtime.artifacts.queue.run(() => this.cleanup(ctx, quitting)));
|
|
90
|
+
this.reset();
|
|
91
|
+
await cleanupSecureTempArtifacts({ preservePaths });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function isQuitting(event) {
|
|
95
|
+
return event?.reason === "quit";
|
|
96
|
+
}
|
|
97
|
+
export function registerBrowserLifecycle(runtime) {
|
|
98
|
+
const lifecycle = new BrowserLifecycle(runtime);
|
|
99
|
+
runtime.pi.on("session_start", (_event, ctx) => lifecycle.start(ctx));
|
|
100
|
+
runtime.pi.on("session_tree", (_event, ctx) => lifecycle.tree(ctx));
|
|
101
|
+
runtime.pi.on("session_shutdown", (event, ctx) => lifecycle.shutdown(ctx, isQuitting(event)));
|
|
102
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { isRecord } from "../parsing.js";
|
|
2
|
+
import { closeManagedSession } from "./browser-run/managed-session-daemon-policy.js";
|
|
3
|
+
import { getActiveElectronRecords, getSessionContextKey } from "./browser-run/session-state.js";
|
|
4
|
+
function inheritedLaunchSettings(existing, options) {
|
|
5
|
+
return {
|
|
6
|
+
compatibilityWorkaround: Object.hasOwn(options, "compatibilityWorkaround")
|
|
7
|
+
? options.compatibilityWorkaround
|
|
8
|
+
: existing?.compatibilityWorkaround,
|
|
9
|
+
headedManagedAutosaveDisabled: options.headedManagedAutosaveDisabled ?? existing?.headedManagedAutosaveDisabled,
|
|
10
|
+
headedManagedAutosaveInterval: options.headedManagedAutosaveInterval ?? existing?.headedManagedAutosaveInterval,
|
|
11
|
+
socketDir: options.socketDir ?? existing?.socketDir,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function trackOwnedManagedSession(sessions, sessionName, cwd, options = {}) {
|
|
15
|
+
if (sessionName === undefined || sessionName === "") {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const key = getSessionContextKey(sessionName, options.namespace) ?? sessionName;
|
|
19
|
+
const existing = sessions.get(key);
|
|
20
|
+
const branchOwned = existing && !existing.branchOwned ? false : options.branchOwned === true;
|
|
21
|
+
sessions.set(key, {
|
|
22
|
+
branchOwned,
|
|
23
|
+
...inheritedLaunchSettings(existing, options),
|
|
24
|
+
cwd,
|
|
25
|
+
namespace: options.namespace,
|
|
26
|
+
sessionName,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
export function untrackOwnedManagedSession(sessions, sessionName, namespace) {
|
|
30
|
+
if (sessionName === undefined || sessionName === "") {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
sessions.delete(sessionName.includes("\u0000")
|
|
34
|
+
? sessionName
|
|
35
|
+
: (getSessionContextKey(sessionName, namespace) ?? sessionName));
|
|
36
|
+
}
|
|
37
|
+
export function untrackOwnedManagedSessionFromBranchClose(sessions, sessionName, activeBranchRank, closeBranchRank) {
|
|
38
|
+
if (sessionName === undefined || sessionName === "" || closeBranchRank === undefined) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const owner = sessions.get(sessionName);
|
|
42
|
+
if (owner?.branchOwned !== true) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (activeBranchRank !== undefined && closeBranchRank <= activeBranchRank) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
sessions.delete(sessionName);
|
|
49
|
+
}
|
|
50
|
+
function getOutcomeLaunchSettings(details) {
|
|
51
|
+
return {
|
|
52
|
+
compatibilityWorkaround: getRecognizedCompatibilityWorkaround(details.compatibilityWorkaround),
|
|
53
|
+
headedManagedAutosaveDisabled: details.managedSessionHeadedAutosaveDisabled === true,
|
|
54
|
+
headedManagedAutosaveInterval: typeof details.managedSessionHeadedAutosaveInterval === "string"
|
|
55
|
+
? details.managedSessionHeadedAutosaveInterval
|
|
56
|
+
: undefined,
|
|
57
|
+
namespace: typeof details.namespace === "string" ? details.namespace : undefined,
|
|
58
|
+
socketDir: typeof details.managedSessionSocketDir === "string"
|
|
59
|
+
? details.managedSessionSocketDir
|
|
60
|
+
: undefined,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function outcomeCreatesOwner(outcome) {
|
|
64
|
+
return (outcome.activeAfter === true &&
|
|
65
|
+
(outcome.status === "created" ||
|
|
66
|
+
outcome.status === "replaced" ||
|
|
67
|
+
outcome.status === "unchanged"));
|
|
68
|
+
}
|
|
69
|
+
function retireOutcomeOwner(sessions, outcome, details, current) {
|
|
70
|
+
if (outcome.succeeded !== true || outcome.status !== "closed") {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const attempted = typeof outcome.attemptedSessionName === "string" ? outcome.attemptedSessionName : undefined;
|
|
74
|
+
const namespace = typeof details.namespace === "string" ? details.namespace : undefined;
|
|
75
|
+
untrackOwnedManagedSession(sessions, attempted ?? current, namespace);
|
|
76
|
+
}
|
|
77
|
+
export function syncOwnedManagedSessionsFromResult(sessions, result, cwd) {
|
|
78
|
+
const details = isRecord(result.details) ? result.details : undefined;
|
|
79
|
+
if (!details || !isRecord(details.managedSessionOutcome)) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const outcome = details.managedSessionOutcome;
|
|
83
|
+
const current = typeof outcome.currentSessionName === "string" ? outcome.currentSessionName : undefined;
|
|
84
|
+
if (outcomeCreatesOwner(outcome)) {
|
|
85
|
+
trackOwnedManagedSession(sessions, current, cwd, getOutcomeLaunchSettings(details));
|
|
86
|
+
}
|
|
87
|
+
retireOutcomeOwner(sessions, outcome, details, current);
|
|
88
|
+
}
|
|
89
|
+
export async function closeOwnedManagedSessionsExcept(sessions, pages, settings, options) {
|
|
90
|
+
const keepKey = getSessionContextKey(options.keepSessionName, options.keepNamespace);
|
|
91
|
+
// Snapshot ownership before awaiting: callbacks may add owners during shutdown cleanup.
|
|
92
|
+
const owners = Array.from(sessions);
|
|
93
|
+
for (const [key, owner] of owners) {
|
|
94
|
+
if (key === keepKey) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
// Session close and its durable cleanup callback must finish before the next owner is retired.
|
|
98
|
+
// oxlint-disable-next-line no-await-in-loop
|
|
99
|
+
const error = await closeManagedSession({
|
|
100
|
+
confirmActions: pages.getConfirmActions(key) ?? process.env.AGENT_BROWSER_CONFIRM_ACTIONS,
|
|
101
|
+
cwd: owner.cwd,
|
|
102
|
+
headedManagedAutosaveInterval: owner.headedManagedAutosaveInterval,
|
|
103
|
+
namespace: owner.namespace,
|
|
104
|
+
preserveAttachedBrowserSession: pages.hasAttachment(key),
|
|
105
|
+
restoreState: settings.restore,
|
|
106
|
+
sessionName: owner.sessionName,
|
|
107
|
+
socketDir: owner.socketDir,
|
|
108
|
+
timeoutMs: settings.timeoutMs,
|
|
109
|
+
});
|
|
110
|
+
if (error === undefined || error === "") {
|
|
111
|
+
sessions.delete(key);
|
|
112
|
+
options.onClosed?.(owner);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
export function shouldSerializeBrowserCommand(sessions, electronRecords, options) {
|
|
117
|
+
const session = options.explicitSessionName;
|
|
118
|
+
if (session === undefined || session === "" || session === options.managedSessionName) {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
if (sessions.has(getSessionContextKey(session, options.namespace) ?? session)) {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
return getActiveElectronRecords(electronRecords).some((record) => record.sessionName === session);
|
|
125
|
+
}
|
|
126
|
+
export function getRecognizedCompatibilityWorkaround(value) {
|
|
127
|
+
const workaround = isRecord(value) ? value : undefined;
|
|
128
|
+
return (workaround?.id === "chatgpt-headless-user-agent" ||
|
|
129
|
+
workaround?.id === "cloudflare-headless-user-agent") &&
|
|
130
|
+
typeof workaround.reason === "string"
|
|
131
|
+
? { id: workaround.id, reason: workaround.reason }
|
|
132
|
+
: undefined;
|
|
133
|
+
}
|