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,120 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { appendBrowserTransition, artifactChanges, } from "../browser-transcript.js";
|
|
3
|
+
import { appendBrowserRecord, hasPublishedBrowserJournal, } from "../browser-journal.js";
|
|
4
|
+
import { isPlainTextInspectionArgs } from "../runtime.js";
|
|
5
|
+
import { isBooleanFlagEnabled } from "../argv-grammar.js";
|
|
6
|
+
import { isRecord } from "../parsing.js";
|
|
7
|
+
import { mergeBrowserRunArtifactManifest } from "./browser-run/artifact-merge.js";
|
|
8
|
+
import { getPersistentSessionArtifactStore } from "./browser-run/session-state.js";
|
|
9
|
+
import { isSessionArtifactManifest } from "../results/artifact-manifest.js";
|
|
10
|
+
import { renderAgentBrowserObservation } from "../results/presentation/large-output.js";
|
|
11
|
+
import { invocationArtifactManifest } from "./extension-result-state.js";
|
|
12
|
+
function observationDetails(result) {
|
|
13
|
+
const details = isRecord(result.details) ? result.details : {};
|
|
14
|
+
if (result.isError === true && details.error === undefined) {
|
|
15
|
+
details.error =
|
|
16
|
+
details.validationError ??
|
|
17
|
+
details.summary ??
|
|
18
|
+
result.content
|
|
19
|
+
.filter((item) => item.type === "text")
|
|
20
|
+
.map((item) => item.text)
|
|
21
|
+
.join("\n");
|
|
22
|
+
}
|
|
23
|
+
return details;
|
|
24
|
+
}
|
|
25
|
+
function observedResult(observation, manifest) {
|
|
26
|
+
return {
|
|
27
|
+
...observation.result,
|
|
28
|
+
details: {
|
|
29
|
+
...observation.details,
|
|
30
|
+
browserEventVersion: 1,
|
|
31
|
+
...(manifest ? { artifactManifest: manifest.value } : {}),
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
class ObservationPublication {
|
|
36
|
+
resources;
|
|
37
|
+
context;
|
|
38
|
+
constructor(resources, context) {
|
|
39
|
+
this.resources = resources;
|
|
40
|
+
this.context = context;
|
|
41
|
+
}
|
|
42
|
+
async render(result, params) {
|
|
43
|
+
const details = observationDetails(result);
|
|
44
|
+
const priorManifest = isSessionArtifactManifest(details.artifactManifest)
|
|
45
|
+
? details.artifactManifest
|
|
46
|
+
: undefined;
|
|
47
|
+
const renderOptions = {
|
|
48
|
+
content: result.content,
|
|
49
|
+
details,
|
|
50
|
+
json: "code" in params || isBooleanFlagEnabled([...(params.args ?? [])], "--json"),
|
|
51
|
+
succeeded: result.isError !== true,
|
|
52
|
+
persistentArtifactStore: this.context.branch.isCurrent()
|
|
53
|
+
? getPersistentSessionArtifactStore(this.context.ctx)
|
|
54
|
+
: undefined,
|
|
55
|
+
withArtifactWrite: (write) => this.resources.queue.run(() => {
|
|
56
|
+
if (!this.context.branch.isCurrent()) {
|
|
57
|
+
renderOptions.persistentArtifactStore = undefined;
|
|
58
|
+
}
|
|
59
|
+
return write();
|
|
60
|
+
}),
|
|
61
|
+
};
|
|
62
|
+
const rendered = await renderAgentBrowserObservation(renderOptions);
|
|
63
|
+
return {
|
|
64
|
+
result: {
|
|
65
|
+
...result,
|
|
66
|
+
content: rendered.content,
|
|
67
|
+
structuredContent: rendered.structuredContent,
|
|
68
|
+
},
|
|
69
|
+
details,
|
|
70
|
+
priorManifest,
|
|
71
|
+
renderedManifest: rendered.artifactManifest,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
async persistChanges(observation, changes) {
|
|
75
|
+
const { ctx, branch } = this.context;
|
|
76
|
+
if (!changes || !hasPublishedBrowserJournal(ctx.sessionManager)) {
|
|
77
|
+
return true;
|
|
78
|
+
}
|
|
79
|
+
const record = {
|
|
80
|
+
event: {
|
|
81
|
+
version: 1,
|
|
82
|
+
phase: "state",
|
|
83
|
+
operationId: randomUUID(),
|
|
84
|
+
toolCallId: "observation",
|
|
85
|
+
commandIndex: 0,
|
|
86
|
+
isError: observation.result.isError === true,
|
|
87
|
+
state: {},
|
|
88
|
+
artifacts: changes,
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
return ((await appendBrowserRecord(ctx.sessionManager, () => appendBrowserTransition(this.resources.pi, record), record, branch)) && branch.isCurrent());
|
|
92
|
+
}
|
|
93
|
+
async publish(observation) {
|
|
94
|
+
if (!this.context.branch.isCurrent()) {
|
|
95
|
+
return observedResult(observation, { value: observation.renderedManifest });
|
|
96
|
+
}
|
|
97
|
+
const before = this.resources.manifest;
|
|
98
|
+
const merged = mergeBrowserRunArtifactManifest(before, observation.priorManifest, observation.renderedManifest);
|
|
99
|
+
if (!(await this.persistChanges(observation, artifactChanges(before, merged)))) {
|
|
100
|
+
return observedResult(observation, { value: observation.renderedManifest });
|
|
101
|
+
}
|
|
102
|
+
this.resources.commit(observation.priorManifest, observation.renderedManifest);
|
|
103
|
+
return observedResult(observation, {
|
|
104
|
+
value: invocationArtifactManifest(this.resources.manifest, before, observation.details, observation.priorManifest),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
async run(result, params) {
|
|
108
|
+
if ("args" in params && params.args && isPlainTextInspectionArgs([...params.args])) {
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
const observation = await this.render(result, params);
|
|
112
|
+
if (!observation.priorManifest && !observation.renderedManifest) {
|
|
113
|
+
return observedResult(observation);
|
|
114
|
+
}
|
|
115
|
+
return this.resources.queue.run(() => this.publish(observation));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
export function finalizeObservation(resources, result, params, context) {
|
|
119
|
+
return new ObservationPublication(resources, context).run(result, params);
|
|
120
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { PROJECT_RULE_PROMPT, ADVANCED_TOOL_PROMPT_GUIDELINES, QUICK_START_GUIDELINES, SHARED_BROWSER_PLAYBOOK_GUIDELINES, WEB_SEARCH_TOOL_PROMPT_GUIDELINES, WRAPPER_TAB_RECOVERY_BEHAVIOR, buildBrowserDefaultProfileGuideline, buildBrowserExecutablePathGuideline, buildToolPromptGuidelines, } from "../playbook.js";
|
|
5
|
+
import { isRecord } from "../parsing.js";
|
|
6
|
+
import { buildPromptPolicy, getLatestUserMessage, getMessageText } from "../prompt-policy.js";
|
|
7
|
+
import { AGENT_BROWSER_INSTRUCTION_GROUP, AGENT_BROWSER_TOOL_INVENTORY } from "../tool-surface.js";
|
|
8
|
+
import { canRegisterWebSearchTool, loadAgentBrowserConfigSync } from "../config.js";
|
|
9
|
+
import { createAgentBrowserWebSearchTool } from "../web-search.js";
|
|
10
|
+
import { isDirectAgentBrowserBashAllowed, isHarmlessAgentBrowserInspectionCommand, looksLikeDirectAgentBrowserBash, } from "../bash-guard.js";
|
|
11
|
+
export function isBashToolCallEvent(event) {
|
|
12
|
+
return (isRecord(event) &&
|
|
13
|
+
event.toolName === "bash" &&
|
|
14
|
+
isRecord(event.input) &&
|
|
15
|
+
typeof event.input.command === "string");
|
|
16
|
+
}
|
|
17
|
+
export function findPackageRoot(startDir) {
|
|
18
|
+
let currentDir = startDir;
|
|
19
|
+
while (true) {
|
|
20
|
+
const packageJsonPath = join(currentDir, "package.json");
|
|
21
|
+
if (existsSync(packageJsonPath)) {
|
|
22
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
|
|
23
|
+
if (isRecord(packageJson) && packageJson.name === "pi-agent-browser-native") {
|
|
24
|
+
return currentDir;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const parentDir = dirname(currentDir);
|
|
28
|
+
if (parentDir === currentDir) {
|
|
29
|
+
return startDir;
|
|
30
|
+
}
|
|
31
|
+
currentDir = parentDir;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function getInstalledDocsPaths() {
|
|
35
|
+
const root = findPackageRoot(dirname(fileURLToPath(import.meta.url)));
|
|
36
|
+
return {
|
|
37
|
+
readmePath: join(root, "README.md"),
|
|
38
|
+
commandReferencePath: join(root, "docs", "COMMAND_REFERENCE.md"),
|
|
39
|
+
toolContractPath: join(root, "docs", "TOOL_CONTRACT.md"),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export function hasArgvFlag(argv, longFlag, shortFlag) {
|
|
43
|
+
return argv.includes(longFlag) || argv.includes(shortFlag);
|
|
44
|
+
}
|
|
45
|
+
export function shouldIncludeProjectConfig(ctx, argv = process.argv) {
|
|
46
|
+
return !hasArgvFlag(argv, "--no-approve", "-na") && ctx.isProjectTrusted();
|
|
47
|
+
}
|
|
48
|
+
/** Owns prompt caching and companion registration, never browser or artifact state. */
|
|
49
|
+
export class BrowserPrompt {
|
|
50
|
+
pi;
|
|
51
|
+
state;
|
|
52
|
+
webSearchToolRegistered = false;
|
|
53
|
+
constructor(pi) {
|
|
54
|
+
this.pi = pi;
|
|
55
|
+
}
|
|
56
|
+
restore(ctx) {
|
|
57
|
+
this.state = {
|
|
58
|
+
sessionId: ctx.sessionManager.getSessionId(),
|
|
59
|
+
message: getLatestUserMessage(ctx.sessionManager),
|
|
60
|
+
};
|
|
61
|
+
return this.state;
|
|
62
|
+
}
|
|
63
|
+
policy(ctx) {
|
|
64
|
+
const state = this.state?.sessionId === ctx.sessionManager.getSessionId() ? this.state : this.restore(ctx);
|
|
65
|
+
// Keep the native message reference: later transforms must be reflected in policy.
|
|
66
|
+
const text = getMessageText(state.message?.content);
|
|
67
|
+
if (!state.policy || state.text !== text) {
|
|
68
|
+
state.text = text;
|
|
69
|
+
state.policy = buildPromptPolicy(text);
|
|
70
|
+
}
|
|
71
|
+
return state.policy;
|
|
72
|
+
}
|
|
73
|
+
registerWebSearch(config) {
|
|
74
|
+
if (this.webSearchToolRegistered || !canRegisterWebSearchTool(config)) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
this.pi.registerTool({
|
|
78
|
+
...createAgentBrowserWebSearchTool(config, {
|
|
79
|
+
loadConfigState(ctx) {
|
|
80
|
+
return loadAgentBrowserConfigSync({
|
|
81
|
+
cwd: ctx.cwd,
|
|
82
|
+
includeProjectConfig: shouldIncludeProjectConfig(ctx),
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
}),
|
|
86
|
+
});
|
|
87
|
+
this.webSearchToolRegistered = true;
|
|
88
|
+
}
|
|
89
|
+
instructions(ctx) {
|
|
90
|
+
const config = loadAgentBrowserConfigSync({
|
|
91
|
+
cwd: ctx.cwd,
|
|
92
|
+
includeProjectConfig: shouldIncludeProjectConfig(ctx),
|
|
93
|
+
});
|
|
94
|
+
const guidance = [
|
|
95
|
+
config.browserExecutablePathScope === "project"
|
|
96
|
+
? buildBrowserExecutablePathGuideline(config.browserExecutablePath)
|
|
97
|
+
: undefined,
|
|
98
|
+
config.browserDefaultProfileScope === "project"
|
|
99
|
+
? buildBrowserDefaultProfileGuideline(config.browserDefaultProfile)
|
|
100
|
+
: undefined,
|
|
101
|
+
].filter((line) => typeof line === "string" && line.length > 0);
|
|
102
|
+
const configPrompt = guidance.length > 0
|
|
103
|
+
? `\n\nProject agent_browser config guidance:\n${guidance.map((line) => `- ${line}`).join("\n")}`
|
|
104
|
+
: "";
|
|
105
|
+
const guidelines = [
|
|
106
|
+
...buildToolPromptGuidelines({
|
|
107
|
+
browserDefaultProfile: config.trustedBrowserDefaultProfile,
|
|
108
|
+
browserExecutablePath: config.trustedBrowserExecutablePath,
|
|
109
|
+
includeWebSearch: this.webSearchToolRegistered,
|
|
110
|
+
docs: getInstalledDocsPaths(),
|
|
111
|
+
}),
|
|
112
|
+
...QUICK_START_GUIDELINES,
|
|
113
|
+
...SHARED_BROWSER_PLAYBOOK_GUIDELINES,
|
|
114
|
+
...WRAPPER_TAB_RECOVERY_BEHAVIOR,
|
|
115
|
+
...Object.values(ADVANCED_TOOL_PROMPT_GUIDELINES).flat(),
|
|
116
|
+
...(this.webSearchToolRegistered ? WEB_SEARCH_TOOL_PROMPT_GUIDELINES : []),
|
|
117
|
+
];
|
|
118
|
+
return `${PROJECT_RULE_PROMPT}\n\n${[...new Set(guidelines)].map((line) => `- ${line}`).join("\n")}${configPrompt}`;
|
|
119
|
+
}
|
|
120
|
+
registerCollector(data, setManaged) {
|
|
121
|
+
if (!isRecord(data) ||
|
|
122
|
+
typeof data.register !== "function" ||
|
|
123
|
+
typeof data.isManaged !== "function") {
|
|
124
|
+
throw new Error("Invalid Pi instruction-group collector.");
|
|
125
|
+
}
|
|
126
|
+
const register = data.register;
|
|
127
|
+
const isManaged = data.isManaged;
|
|
128
|
+
Reflect.apply(register, data, [
|
|
129
|
+
{
|
|
130
|
+
...AGENT_BROWSER_INSTRUCTION_GROUP,
|
|
131
|
+
tools: [
|
|
132
|
+
"agent_browser",
|
|
133
|
+
"agent_browser_code",
|
|
134
|
+
"agent_browser_tools",
|
|
135
|
+
"agent_browser_web_search",
|
|
136
|
+
...Object.values(AGENT_BROWSER_TOOL_INVENTORY).map(({ name }) => name),
|
|
137
|
+
],
|
|
138
|
+
instructions: (ctx) => this.instructions(ctx),
|
|
139
|
+
},
|
|
140
|
+
]);
|
|
141
|
+
setManaged(() => {
|
|
142
|
+
const managed = Reflect.apply(isManaged, undefined, []);
|
|
143
|
+
if (typeof managed !== "boolean") {
|
|
144
|
+
throw new Error("Pi instruction-group ownership must be boolean.");
|
|
145
|
+
}
|
|
146
|
+
return managed;
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
register() {
|
|
150
|
+
let isInstructionsManaged = () => false;
|
|
151
|
+
this.pi.on("message_end", (event, ctx) => {
|
|
152
|
+
if (event.message.role === "user") {
|
|
153
|
+
this.state = { sessionId: ctx.sessionManager.getSessionId(), message: event.message };
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
this.pi.events.on("pi:instruction-groups", (data) => this.registerCollector(data, (managed) => {
|
|
157
|
+
isInstructionsManaged = managed;
|
|
158
|
+
}));
|
|
159
|
+
this.pi.on("before_agent_start", async (event, ctx) => {
|
|
160
|
+
if (!isInstructionsManaged()) {
|
|
161
|
+
event.systemPromptOptions.sections.agent_browser = this.instructions(ctx);
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
this.pi.on("tool_call", async (event, ctx) => {
|
|
165
|
+
if (!isBashToolCallEvent(event) ||
|
|
166
|
+
!looksLikeDirectAgentBrowserBash(event.input.command) ||
|
|
167
|
+
isHarmlessAgentBrowserInspectionCommand(event.input.command)) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (!this.policy(ctx).allowLegacyAgentBrowserBash &&
|
|
171
|
+
!(await isDirectAgentBrowserBashAllowed(ctx.cwd))) {
|
|
172
|
+
return {
|
|
173
|
+
block: true,
|
|
174
|
+
reason: "Use the native agent_browser tool instead of bash for agent-browser in this environment.",
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
return;
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { extractUpstreamCommandTokens } from "../runtime.js";
|
|
2
|
+
import { getAgentBrowserSessionIdentityKey } from "../argv-grammar.js";
|
|
3
|
+
import { isRecord } from "../parsing.js";
|
|
4
|
+
import { isCloseCommand } from "../command-taxonomy.js";
|
|
5
|
+
import { applyNamespaceToNextActions, applySessionToNextActions, buildNextToolAction, } from "../results/next-actions.js";
|
|
6
|
+
import { appendRecordingReservationTransition, applyRecordingArtifactsToReservations, retireRecordingReservation, restoreRecordingReservationStateFromBranch, } from "../recording-reservations.js";
|
|
7
|
+
import { isResultFileArtifact, getResultFileArtifacts } from "./extension-result-state.js";
|
|
8
|
+
const recordingPersistenceWarning = "Recording persistence warning: recording protection could not be saved to the Pi journal. Restart protection is not yet durable; keep recording destinations untouched until exact stop or close. The next browser operation retries journal persistence; cleanup remains available.";
|
|
9
|
+
/** Owns the durable unbounded recording index separately from the bounded artifact manifest. */
|
|
10
|
+
export class BrowserRecordingRegistry {
|
|
11
|
+
pi;
|
|
12
|
+
artifacts;
|
|
13
|
+
getCwd;
|
|
14
|
+
active = new Map();
|
|
15
|
+
terminal = new Map();
|
|
16
|
+
persistenceDirty = false;
|
|
17
|
+
constructor(pi, artifacts, getCwd) {
|
|
18
|
+
this.pi = pi;
|
|
19
|
+
this.artifacts = artifacts;
|
|
20
|
+
this.getCwd = getCwd;
|
|
21
|
+
}
|
|
22
|
+
get dirty() {
|
|
23
|
+
return this.persistenceDirty;
|
|
24
|
+
}
|
|
25
|
+
flush() {
|
|
26
|
+
if (!this.persistenceDirty) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
// A failed append may mask earlier reservations; republish the full current index.
|
|
31
|
+
for (const reservation of this.terminal.values()) {
|
|
32
|
+
appendRecordingReservationTransition(this.pi, { reservation, state: "closed" });
|
|
33
|
+
}
|
|
34
|
+
for (const reservation of this.active.values()) {
|
|
35
|
+
appendRecordingReservationTransition(this.pi, { reservation, state: "active" });
|
|
36
|
+
}
|
|
37
|
+
this.persistenceDirty = false;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
// Keep the dirty index for the next operation's persistence retry.
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
append(transitions) {
|
|
44
|
+
for (const transition of transitions) {
|
|
45
|
+
const key = getAgentBrowserSessionIdentityKey(transition.reservation.sessionName, transition.reservation.namespace);
|
|
46
|
+
if (transition.state === "active") {
|
|
47
|
+
this.terminal.delete(key);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
this.terminal.set(key, transition.reservation);
|
|
51
|
+
}
|
|
52
|
+
if (this.persistenceDirty) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
appendRecordingReservationTransition(this.pi, transition);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
this.persistenceDirty = true;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
applyArtifacts(artifacts) {
|
|
64
|
+
this.append(applyRecordingArtifactsToReservations(this.active, artifacts));
|
|
65
|
+
}
|
|
66
|
+
retire(sessionName, namespace, retireManifest = true) {
|
|
67
|
+
const reservation = retireRecordingReservation(this.active, sessionName, namespace);
|
|
68
|
+
const changed = retireManifest && this.artifacts.retireRecording(sessionName, namespace);
|
|
69
|
+
if (!reservation && !changed) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const terminal = reservation ?? {
|
|
73
|
+
absolutePath: "",
|
|
74
|
+
cwd: this.getCwd(),
|
|
75
|
+
namespace,
|
|
76
|
+
path: "",
|
|
77
|
+
sessionName,
|
|
78
|
+
};
|
|
79
|
+
this.append([{ reservation: terminal, state: "closed" }]);
|
|
80
|
+
}
|
|
81
|
+
restore(branch) {
|
|
82
|
+
const restored = restoreRecordingReservationStateFromBranch([...branch]);
|
|
83
|
+
for (const key of this.terminal.keys()) {
|
|
84
|
+
if (!restored.terminal.has(key)) {
|
|
85
|
+
this.persistenceDirty = true;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
for (const [key, reservation] of restored.terminal) {
|
|
89
|
+
if (!this.active.has(key)) {
|
|
90
|
+
this.terminal.set(key, reservation);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
for (const [key, reservation] of this.terminal) {
|
|
94
|
+
restored.active.delete(key);
|
|
95
|
+
this.artifacts.retireRecording(reservation.sessionName, reservation.namespace);
|
|
96
|
+
}
|
|
97
|
+
for (const [key, reservation] of this.active) {
|
|
98
|
+
if (recordingReservationChanged(restored.active.get(key), reservation)) {
|
|
99
|
+
this.persistenceDirty = true;
|
|
100
|
+
}
|
|
101
|
+
restored.active.set(key, reservation);
|
|
102
|
+
}
|
|
103
|
+
this.active = restored.active;
|
|
104
|
+
}
|
|
105
|
+
resetIfClean() {
|
|
106
|
+
if (!this.persistenceDirty) {
|
|
107
|
+
this.active = new Map();
|
|
108
|
+
this.terminal.clear();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
syncResult(result) {
|
|
112
|
+
const details = isRecord(result.details) ? result.details : undefined;
|
|
113
|
+
const steps = Array.isArray(details?.batchSteps)
|
|
114
|
+
? details.batchSteps
|
|
115
|
+
: undefined;
|
|
116
|
+
if (!steps) {
|
|
117
|
+
this.applyArtifacts(getResultFileArtifacts(result));
|
|
118
|
+
return new Set();
|
|
119
|
+
}
|
|
120
|
+
const fold = new RecordingBatchFold(this, typeof details?.sessionName === "string" ? details.sessionName : undefined, typeof details?.namespace === "string" ? details.namespace : undefined);
|
|
121
|
+
for (const step of steps) {
|
|
122
|
+
fold.apply(step);
|
|
123
|
+
}
|
|
124
|
+
return fold.finish();
|
|
125
|
+
}
|
|
126
|
+
retireManifest(sessionName, namespace) {
|
|
127
|
+
this.artifacts.retireRecording(sessionName, namespace);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function recordingReservationChanged(prior, current) {
|
|
131
|
+
return (prior?.absolutePath !== current.absolutePath ||
|
|
132
|
+
prior.cwd !== current.cwd ||
|
|
133
|
+
prior.recordingId !== current.recordingId ||
|
|
134
|
+
prior.startedAtMs !== current.startedAtMs ||
|
|
135
|
+
prior.contactSheetPath !== current.contactSheetPath);
|
|
136
|
+
}
|
|
137
|
+
function warningJson(text) {
|
|
138
|
+
let json;
|
|
139
|
+
try {
|
|
140
|
+
json = JSON.parse(text);
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
return isRecord(json) && typeof json.success === "boolean" ? json : undefined;
|
|
146
|
+
}
|
|
147
|
+
export function warnRecordingPersistence(dirty, result) {
|
|
148
|
+
if (!dirty) {
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
const content = [...result.content];
|
|
152
|
+
const first = content.at(0);
|
|
153
|
+
const json = first?.type === "text" ? warningJson(first.text) : undefined;
|
|
154
|
+
if (json) {
|
|
155
|
+
const warnings = Array.isArray(json.warnings) ? json.warnings : [];
|
|
156
|
+
content[0] = {
|
|
157
|
+
type: "text",
|
|
158
|
+
text: JSON.stringify({ ...json, warnings: [...warnings, recordingPersistenceWarning] }, null, 2),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
else if (first?.type === "text") {
|
|
162
|
+
content[0] = { ...first, text: `${first.text}\n\n${recordingPersistenceWarning}` };
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
content.push({ type: "text", text: recordingPersistenceWarning });
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
...result,
|
|
169
|
+
content,
|
|
170
|
+
details: { ...(isRecord(result.details) ? result.details : {}), recordingPersistenceWarning },
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
export function notifyRecordingPersistence(dirty, ctx) {
|
|
174
|
+
if (!dirty) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
if (ctx?.hasUI === true) {
|
|
178
|
+
ctx.ui.notify(recordingPersistenceWarning, "warning");
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
console.warn(recordingPersistenceWarning);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function recordingCleanupActions(reservation, cleanupOnly) {
|
|
185
|
+
const action = buildNextToolAction({
|
|
186
|
+
args: cleanupOnly ? ["close"] : ["record", "stop"],
|
|
187
|
+
id: cleanupOnly ? "close-pending-recording" : "stop-pending-recording",
|
|
188
|
+
reason: cleanupOnly
|
|
189
|
+
? "Close this exact session to abandon the recording; its live daemon lacks current-instance provenance."
|
|
190
|
+
: "Stop the active recording so the requested video can be finalized and verified on disk.",
|
|
191
|
+
safety: cleanupOnly
|
|
192
|
+
? "Close does not verify the WebM. The recording is abandoned/unverified, even if close leaves a file on disk."
|
|
193
|
+
: "The file remains pending until record stop succeeds; verify details.artifactVerification afterward.",
|
|
194
|
+
});
|
|
195
|
+
return applyNamespaceToNextActions(applySessionToNextActions([action], reservation.sessionName), cleanupOnly ? (reservation.namespace ?? "") : reservation.namespace);
|
|
196
|
+
}
|
|
197
|
+
export function appendActiveRecordingCleanupAction(result, reservation) {
|
|
198
|
+
if (result.isError !== true) {
|
|
199
|
+
return result;
|
|
200
|
+
}
|
|
201
|
+
const details = isRecord(result.details) ? result.details : {};
|
|
202
|
+
const recordingRecovered = Boolean(details.recordingRecovery);
|
|
203
|
+
if (recordingRecovered) {
|
|
204
|
+
return result;
|
|
205
|
+
}
|
|
206
|
+
const cleanupOnly = details.managedSessionCleanupOnlyReason === "restore-disabled-daemon-without-provenance";
|
|
207
|
+
const existing = Array.isArray(details.nextActions)
|
|
208
|
+
? details.nextActions
|
|
209
|
+
: [];
|
|
210
|
+
const nextActions = existing.filter((action) => !cleanupOnly || !isRecord(action) || action.id !== "stop-pending-recording");
|
|
211
|
+
const actionId = cleanupOnly ? "close-pending-recording" : "stop-pending-recording";
|
|
212
|
+
if (nextActions.some((action) => isRecord(action) && action.id === actionId)) {
|
|
213
|
+
return result;
|
|
214
|
+
}
|
|
215
|
+
nextActions.push(...(recordingCleanupActions(reservation, cleanupOnly) ?? []));
|
|
216
|
+
const notice = cleanupOnly
|
|
217
|
+
? "This recording cannot be stopped through the unproven daemon. Use the exact close-pending-recording payload in details.nextActions; any WebM left by close is abandoned/unverified."
|
|
218
|
+
: "An active recording remains open. Use the exact stop-pending-recording payload in details.nextActions before leaving this session.";
|
|
219
|
+
const firstText = result.content.findIndex((item) => item.type === "text");
|
|
220
|
+
const content = result.content.map((item, index) => index === firstText && item.type === "text"
|
|
221
|
+
? { ...item, text: `${item.text}\n\n${notice}` }
|
|
222
|
+
: item);
|
|
223
|
+
if (firstText < 0) {
|
|
224
|
+
content.push({ type: "text", text: notice });
|
|
225
|
+
}
|
|
226
|
+
return { ...result, content, details: { ...details, nextActions } };
|
|
227
|
+
}
|
|
228
|
+
function recordingStepCommand(value) {
|
|
229
|
+
if (!Array.isArray(value)) {
|
|
230
|
+
return undefined;
|
|
231
|
+
}
|
|
232
|
+
const tokens = value;
|
|
233
|
+
return tokens.every((token) => typeof token === "string") ? tokens : undefined;
|
|
234
|
+
}
|
|
235
|
+
class RecordingBatchFold {
|
|
236
|
+
registry;
|
|
237
|
+
sessionName;
|
|
238
|
+
namespace;
|
|
239
|
+
handled = new Set();
|
|
240
|
+
sessionClosed = false;
|
|
241
|
+
constructor(registry, sessionName, namespace) {
|
|
242
|
+
this.registry = registry;
|
|
243
|
+
this.sessionName = sessionName;
|
|
244
|
+
this.namespace = namespace;
|
|
245
|
+
}
|
|
246
|
+
closeRow(step, command) {
|
|
247
|
+
if (step.success !== true ||
|
|
248
|
+
command === undefined ||
|
|
249
|
+
command === "" ||
|
|
250
|
+
!isCloseCommand(command) ||
|
|
251
|
+
this.sessionName === undefined ||
|
|
252
|
+
this.sessionName === "") {
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
this.registry.retire(this.sessionName, this.namespace, false);
|
|
256
|
+
this.handled.add(getAgentBrowserSessionIdentityKey(this.sessionName, this.namespace));
|
|
257
|
+
this.sessionClosed = true;
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
apply(step) {
|
|
261
|
+
if (!isRecord(step)) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const command = recordingStepCommand(step.command);
|
|
265
|
+
const name = command ? extractUpstreamCommandTokens(command)[0] : undefined;
|
|
266
|
+
if (this.closeRow(step, name)) {
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
if (this.sessionClosed && name === "record") {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
if (step.success === true && this.sessionClosed) {
|
|
273
|
+
this.sessionClosed = false;
|
|
274
|
+
}
|
|
275
|
+
const artifacts = Array.isArray(step.artifacts)
|
|
276
|
+
? step.artifacts.filter(isResultFileArtifact)
|
|
277
|
+
: [];
|
|
278
|
+
this.registry.applyArtifacts(artifacts);
|
|
279
|
+
}
|
|
280
|
+
finish() {
|
|
281
|
+
for (const key of this.handled) {
|
|
282
|
+
if (!this.registry.active.has(key) &&
|
|
283
|
+
this.sessionName !== undefined &&
|
|
284
|
+
this.sessionName !== "") {
|
|
285
|
+
this.registry.retireManifest(this.sessionName, this.namespace);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return this.handled;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|