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,232 @@
|
|
|
1
|
+
import { randomInt, randomUUID } from "node:crypto";
|
|
2
|
+
import { lstat, readFile, readdir, rename, rm } from "node:fs/promises";
|
|
3
|
+
import { basename, dirname, join } from "node:path";
|
|
4
|
+
import { processStartIdentitiesMatch, readProcessStartIdentity } from "./process-identity.js";
|
|
5
|
+
import { getErrorCode } from "./process-errors.js";
|
|
6
|
+
import { parseOwner, parseTicket, POLICY_LOCK_MAX_BYTES, } from "./browser-execution-claim-codec.js";
|
|
7
|
+
export const POLICY_LOCK_WAIT_MS = 1_000;
|
|
8
|
+
export const LOCK_OWNER_FILE = "owner.json";
|
|
9
|
+
export const LOCK_TICKET_FILE = "ticket.json";
|
|
10
|
+
const STALE_CLAIM_MIN_AGE_MS = 30 * 60 * 1_000;
|
|
11
|
+
const POLICY_GC_BATCH_SIZE = 8;
|
|
12
|
+
let lastPolicyGcName;
|
|
13
|
+
function secureEntry(entry, directory) {
|
|
14
|
+
if (entry.isSymbolicLink() || (directory ? !entry.isDirectory() : !entry.isFile())) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
if (!directory && entry.size > POLICY_LOCK_MAX_BYTES) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return secureEntryOwnership(entry, directory ? 0o077 : 0o177);
|
|
21
|
+
}
|
|
22
|
+
function secureEntryOwnership(entry, mask) {
|
|
23
|
+
if (process.platform === "win32") {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
const uid = typeof process.getuid === "function" ? process.getuid() : undefined;
|
|
27
|
+
return uid !== undefined && entry.uid === uid && (entry.mode & mask) === 0;
|
|
28
|
+
}
|
|
29
|
+
async function readClaimTicket(path, owner) {
|
|
30
|
+
const ticketPath = join(path, LOCK_TICKET_FILE);
|
|
31
|
+
try {
|
|
32
|
+
if (!secureEntry(await lstat(ticketPath), false)) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
const ticket = parseTicket(await readFile(ticketPath, "utf8"), owner.token);
|
|
36
|
+
return ticket === undefined ? undefined : { owner, path, ticket };
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
return getErrorCode(error) === "ENOENT" ? { owner, path, ticket: null } : undefined;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export async function readClaim(path) {
|
|
43
|
+
try {
|
|
44
|
+
const directory = await lstat(path);
|
|
45
|
+
const ownerPath = join(path, LOCK_OWNER_FILE);
|
|
46
|
+
const ownerEntry = await lstat(ownerPath);
|
|
47
|
+
if (!secureEntry(directory, true) || !secureEntry(ownerEntry, false)) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
const owner = parseOwner(await readFile(ownerPath, "utf8"));
|
|
51
|
+
return owner ? await readClaimTicket(path, owner) : undefined;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async function claimDisappeared(path) {
|
|
58
|
+
try {
|
|
59
|
+
await lstat(path);
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
return getErrorCode(error) === "ENOENT";
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export async function readClaims(basePath) {
|
|
67
|
+
const directory = dirname(basePath);
|
|
68
|
+
const prefix = `${basename(basePath)}.claim-`;
|
|
69
|
+
let names;
|
|
70
|
+
try {
|
|
71
|
+
names = await readdir(directory);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
const claims = [];
|
|
77
|
+
for (const name of names.filter((candidate) => candidate.startsWith(prefix))) {
|
|
78
|
+
const path = join(directory, name);
|
|
79
|
+
// Claim absence must be resolved before accepting the next contender.
|
|
80
|
+
// oxlint-disable-next-line no-await-in-loop
|
|
81
|
+
const claim = await readClaim(path);
|
|
82
|
+
if (!claim) {
|
|
83
|
+
// A disappearing immutable claim is not a corrupt contender.
|
|
84
|
+
// oxlint-disable-next-line no-await-in-loop
|
|
85
|
+
if (await claimDisappeared(path)) {
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
if (name !== `${prefix}${claim.owner.token}`) {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
claims.push(claim);
|
|
94
|
+
}
|
|
95
|
+
return claims;
|
|
96
|
+
}
|
|
97
|
+
export async function ownerAlive(owner, budget) {
|
|
98
|
+
try {
|
|
99
|
+
process.kill(owner.pid, 0);
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
const code = getErrorCode(error);
|
|
103
|
+
if (code === "ESRCH") {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
if (code !== "EPERM") {
|
|
107
|
+
return undefined;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const current = await readProcessStartIdentity(owner.pid, process.platform, budget);
|
|
111
|
+
return current === undefined
|
|
112
|
+
? undefined
|
|
113
|
+
: processStartIdentitiesMatch(owner.startIdentity, current);
|
|
114
|
+
}
|
|
115
|
+
export function waitForRetry(signal) {
|
|
116
|
+
return new Promise((resolve) => {
|
|
117
|
+
if (signal?.aborted === true) {
|
|
118
|
+
resolve();
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const timer = setTimeout(done, 10);
|
|
122
|
+
function done() {
|
|
123
|
+
clearTimeout(timer);
|
|
124
|
+
signal?.removeEventListener("abort", done);
|
|
125
|
+
resolve();
|
|
126
|
+
}
|
|
127
|
+
signal?.addEventListener("abort", done, { once: true });
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
async function moveOwnedClaim(path, movedPath, token, deadline) {
|
|
131
|
+
while (true) {
|
|
132
|
+
// Each retry must revalidate ownership before another move attempt.
|
|
133
|
+
// oxlint-disable-next-line no-await-in-loop
|
|
134
|
+
if ((await readClaim(path))?.owner.token !== token) {
|
|
135
|
+
return undefined;
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
// Windows readers may temporarily hold the directory; moves stay serialized.
|
|
139
|
+
// oxlint-disable-next-line no-await-in-loop
|
|
140
|
+
await rename(path, movedPath);
|
|
141
|
+
return "moved";
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
const code = getErrorCode(error);
|
|
145
|
+
if (code === "ENOENT") {
|
|
146
|
+
return "absent";
|
|
147
|
+
}
|
|
148
|
+
if (process.platform !== "win32" || code !== "EPERM" || Date.now() >= deadline) {
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
// Retry only after a bounded pause, then revalidate the same immutable owner.
|
|
152
|
+
// oxlint-disable-next-line no-await-in-loop
|
|
153
|
+
await waitForRetry();
|
|
154
|
+
if (Date.now() >= deadline) {
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
export async function removeClaimOwnedBy(path, token, deadline = 0) {
|
|
161
|
+
const movedPath = join(dirname(path), `.pi-agent-browser-policy-remove-${token}-${randomUUID()}`);
|
|
162
|
+
const movement = await moveOwnedClaim(path, movedPath, token, deadline);
|
|
163
|
+
if (movement === "absent") {
|
|
164
|
+
return true;
|
|
165
|
+
}
|
|
166
|
+
if (movement !== "moved") {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
const moved = await readClaim(movedPath);
|
|
170
|
+
if (moved?.owner.token !== token) {
|
|
171
|
+
try {
|
|
172
|
+
await rename(movedPath, path);
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
/* An unverified moved claim remains unavailable to contenders. */
|
|
176
|
+
}
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
await rm(movedPath, { force: true, recursive: true });
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
function gcBatch(names) {
|
|
183
|
+
// ponytail: list/sort all names; stream directories if enumeration becomes the bottleneck.
|
|
184
|
+
const candidates = names
|
|
185
|
+
.filter((name) => name.startsWith(".pi-agent-browser-policy-remove-") ||
|
|
186
|
+
/^\.pi-agent-browser-policy-[a-f0-9]{64}\.lock-v4\.(?:candidate|claim)-/.test(name))
|
|
187
|
+
.sort();
|
|
188
|
+
if (candidates.length === 0) {
|
|
189
|
+
return [];
|
|
190
|
+
}
|
|
191
|
+
const previous = lastPolicyGcName;
|
|
192
|
+
const start = previous === undefined
|
|
193
|
+
? randomInt(candidates.length)
|
|
194
|
+
: Math.max(0, candidates.findIndex((name) => name > previous));
|
|
195
|
+
const batch = Array.from({ length: Math.min(POLICY_GC_BATCH_SIZE, candidates.length) }, (_, offset) => candidates[(start + offset) % candidates.length]);
|
|
196
|
+
lastPolicyGcName = batch.at(-1);
|
|
197
|
+
return batch;
|
|
198
|
+
}
|
|
199
|
+
async function cleanDeadClaim(directory, name, budget) {
|
|
200
|
+
const path = join(directory, name);
|
|
201
|
+
const published = name.includes(".lock-v4.claim-");
|
|
202
|
+
if (published) {
|
|
203
|
+
const entry = await lstat(path).catch(() => undefined);
|
|
204
|
+
if (!entry || entry.mtimeMs >= Date.now() - STALE_CLAIM_MIN_AGE_MS) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const claim = await readClaim(path);
|
|
209
|
+
if (!claim || (published && !name.endsWith(`.claim-${claim.owner.token}`))) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
if ((await ownerAlive(claim.owner, budget)) === false) {
|
|
213
|
+
await removeClaimOwnedBy(path, claim.owner.token).catch(() => false);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
export async function cleanDeadPolicyArtifacts(directory, budget) {
|
|
217
|
+
let names;
|
|
218
|
+
try {
|
|
219
|
+
names = await readdir(directory);
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
for (const name of gcBatch(names)) {
|
|
225
|
+
if (budget.signal?.aborted === true || Date.now() >= (budget.deadline ?? Infinity)) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
// Bounded GC respects the acquisition budget between native liveness probes.
|
|
229
|
+
// oxlint-disable-next-line no-await-in-loop
|
|
230
|
+
await cleanDeadClaim(directory, name, budget);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { lstat, mkdir, rename, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { getErrorCode } from "./process-errors.js";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { readProcessStartIdentity } from "./process-identity.js";
|
|
6
|
+
import { POLICY_LOCK_MAX_BYTES, } from "./browser-execution-claim-codec.js";
|
|
7
|
+
import { ensureCoordinationDirectory, getCoordinationDirectory, getBrowserExecutionLockPath, } from "./browser-execution-identity.js";
|
|
8
|
+
import { cleanDeadPolicyArtifacts, readClaim, readClaims, removeClaimOwnedBy, ownerAlive, waitForRetry, LOCK_OWNER_FILE, LOCK_TICKET_FILE, POLICY_LOCK_WAIT_MS, } from "./browser-execution-claim-storage.js";
|
|
9
|
+
function claimPrecedes(left, right) {
|
|
10
|
+
if (left.ticket === null) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
if (right.ticket === null) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return (left.ticket < right.ticket ||
|
|
17
|
+
(left.ticket === right.ticket && left.owner.token < right.owner.token));
|
|
18
|
+
}
|
|
19
|
+
async function hasPublishedLaterTicket(claim, ownClaim) {
|
|
20
|
+
if (claim.ticket !== null) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
const current = await readClaim(claim.path);
|
|
24
|
+
return current?.owner.token === claim.owner.token && !claimPrecedes(current, ownClaim);
|
|
25
|
+
}
|
|
26
|
+
function relevantPredecessor(claim, ownClaim) {
|
|
27
|
+
if (claim.owner.token === ownClaim.owner.token || !claimPrecedes(claim, ownClaim)) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const ownSessions = ownClaim.owner.sessionNames;
|
|
31
|
+
const sessions = claim.owner.sessionNames;
|
|
32
|
+
return (ownSessions === null ||
|
|
33
|
+
sessions === null ||
|
|
34
|
+
ownSessions.some((session) => sessions.includes(session)));
|
|
35
|
+
}
|
|
36
|
+
async function claimBlocks(claim, ownClaim, budget) {
|
|
37
|
+
if (!relevantPredecessor(claim, ownClaim) || (await hasPublishedLaterTicket(claim, ownClaim))) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
const alive = await ownerAlive(claim.owner, budget);
|
|
41
|
+
if (alive === false) {
|
|
42
|
+
await removeClaimOwnedBy(claim.path, claim.owner.token);
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
// Native identity queries can outlive the whole critical section. Re-read the immutable
|
|
46
|
+
// claim so an already released owner, or a newly published later ticket, cannot block us.
|
|
47
|
+
if (!(await claimStillExists(claim.path))) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
return !(await hasPublishedLaterTicket(claim, ownClaim));
|
|
51
|
+
}
|
|
52
|
+
async function claimStillExists(path) {
|
|
53
|
+
try {
|
|
54
|
+
await lstat(path);
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
return getErrorCode(error) !== "ENOENT";
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async function anyPredecessorBlocks(claims, own, budget) {
|
|
62
|
+
for (const claim of claims) {
|
|
63
|
+
// Contender inspection/removal is ordered before the next ticket decision.
|
|
64
|
+
// oxlint-disable-next-line no-await-in-loop
|
|
65
|
+
if (await claimBlocks(claim, own, budget)) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
async function prepareClaim(identity, budget) {
|
|
72
|
+
const directory = getCoordinationDirectory(process.platform);
|
|
73
|
+
if (!(await ensureCoordinationDirectory(directory, process.platform))) {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
const basePath = getBrowserExecutionLockPath(identity);
|
|
77
|
+
const token = randomUUID();
|
|
78
|
+
const startIdentity = await readProcessStartIdentity(process.pid, process.platform, budget);
|
|
79
|
+
if (startIdentity === undefined || startIdentity.length === 0) {
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
const owner = {
|
|
83
|
+
pid: process.pid,
|
|
84
|
+
startIdentity,
|
|
85
|
+
token,
|
|
86
|
+
sessionNames: identity.sessionNames,
|
|
87
|
+
version: 4,
|
|
88
|
+
};
|
|
89
|
+
const content = JSON.stringify(owner);
|
|
90
|
+
if (Buffer.byteLength(content) > POLICY_LOCK_MAX_BYTES) {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
owner,
|
|
95
|
+
content,
|
|
96
|
+
basePath,
|
|
97
|
+
directory,
|
|
98
|
+
candidatePath: `${basePath}.candidate-${token}`,
|
|
99
|
+
path: `${basePath}.claim-${token}`,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
async function publishClaim(claim) {
|
|
103
|
+
await mkdir(claim.candidatePath, { mode: 0o700 });
|
|
104
|
+
await writeFile(join(claim.candidatePath, LOCK_OWNER_FILE), claim.content, {
|
|
105
|
+
encoding: "utf8",
|
|
106
|
+
flag: "wx",
|
|
107
|
+
mode: 0o600,
|
|
108
|
+
});
|
|
109
|
+
await rename(claim.candidatePath, claim.path);
|
|
110
|
+
}
|
|
111
|
+
async function publishTicket(claim) {
|
|
112
|
+
const claims = await readClaims(claim.basePath);
|
|
113
|
+
if (!claims) {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
const maxTicket = claims.reduce((max, entry) => (entry.ticket === null ? max : Math.max(max, entry.ticket)), 0);
|
|
117
|
+
if (!Number.isSafeInteger(maxTicket + 1)) {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
const ticket = { ticket: maxTicket + 1, token: claim.owner.token, version: 4 };
|
|
121
|
+
const candidate = join(claim.path, `.ticket-${claim.owner.token}.tmp`);
|
|
122
|
+
await writeFile(candidate, JSON.stringify(ticket), { encoding: "utf8", flag: "wx", mode: 0o600 });
|
|
123
|
+
await rename(candidate, join(claim.path, LOCK_TICKET_FILE));
|
|
124
|
+
return ticket.ticket;
|
|
125
|
+
}
|
|
126
|
+
function acquisitionExpired(budget) {
|
|
127
|
+
return (budget.signal?.aborted === true ||
|
|
128
|
+
(budget.deadline !== undefined && Date.now() >= budget.deadline));
|
|
129
|
+
}
|
|
130
|
+
async function waitForTurn(claim, ticket, budget, deadline) {
|
|
131
|
+
while (budget.signal?.aborted !== true) {
|
|
132
|
+
// Each poll observes a fresh published ticket set after the previous delay.
|
|
133
|
+
// oxlint-disable-next-line no-await-in-loop
|
|
134
|
+
const claims = await readClaims(claim.basePath);
|
|
135
|
+
if (!claims) {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
const own = claims.find((entry) => entry.owner.token === claim.owner.token);
|
|
139
|
+
if (!own || own.ticket !== ticket) {
|
|
140
|
+
return false;
|
|
141
|
+
}
|
|
142
|
+
// Liveness checks and stale-claim removal must finish before acquisition.
|
|
143
|
+
// oxlint-disable-next-line no-await-in-loop
|
|
144
|
+
if (!(await anyPredecessorBlocks(claims, own, budget))) {
|
|
145
|
+
// Opportunistic GC must finish before the final cancellation check.
|
|
146
|
+
// oxlint-disable-next-line no-await-in-loop
|
|
147
|
+
await cleanDeadPolicyArtifacts(claim.directory, budget);
|
|
148
|
+
// Re-read cancellation/deadline after the awaited filesystem/native probes.
|
|
149
|
+
return !acquisitionExpired(budget);
|
|
150
|
+
}
|
|
151
|
+
if (Date.now() >= deadline) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
// Polling respects ordering and cancellation; contenders cannot run concurrently here.
|
|
155
|
+
// oxlint-disable-next-line no-await-in-loop
|
|
156
|
+
await waitForRetry(budget.signal);
|
|
157
|
+
}
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
function acquisitionDeadline(options) {
|
|
161
|
+
return options.deadline ?? Date.now() + (options.timeoutMs ?? POLICY_LOCK_WAIT_MS);
|
|
162
|
+
}
|
|
163
|
+
export async function acquireExecutionClaim(options) {
|
|
164
|
+
if (options.signal?.aborted === true) {
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
const deadline = acquisitionDeadline(options);
|
|
168
|
+
// timeoutMs: 0 retains the existing single-attempt policy probe contract.
|
|
169
|
+
const budget = {
|
|
170
|
+
signal: options.signal,
|
|
171
|
+
deadline: options.timeoutMs === 0 ? undefined : deadline,
|
|
172
|
+
};
|
|
173
|
+
const claim = await prepareClaim(options.identity, budget);
|
|
174
|
+
if (!claim) {
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
let published = false;
|
|
178
|
+
let acquired = false;
|
|
179
|
+
try {
|
|
180
|
+
await publishClaim(claim);
|
|
181
|
+
published = true;
|
|
182
|
+
const ticket = await publishTicket(claim);
|
|
183
|
+
if (ticket === undefined || !(await waitForTurn(claim, ticket, budget, deadline))) {
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
acquired = true;
|
|
187
|
+
return {
|
|
188
|
+
release: async () => {
|
|
189
|
+
await removeClaimOwnedBy(claim.path, claim.owner.token, Date.now() + POLICY_LOCK_WAIT_MS);
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
catch {
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
finally {
|
|
197
|
+
await rm(claim.candidatePath, { force: true, recursive: true }).catch(() => undefined);
|
|
198
|
+
if (published && !acquired) {
|
|
199
|
+
await removeClaimOwnedBy(claim.path, claim.owner.token, Date.now() + POLICY_LOCK_WAIT_MS);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { lstat, mkdir, realpath } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { canonicalizeAgentBrowserNamespace, foldAgentBrowserFilesystemIdentity, } from "./argv-grammar.js";
|
|
6
|
+
import { getAgentBrowserSocketDirValidationError, resolveAgentBrowserSocketDir, } from "./process-socket-storage.js";
|
|
7
|
+
import { getCurrentProcessUid } from "./process-identity.js";
|
|
8
|
+
import { getErrorCode } from "./process-errors.js";
|
|
9
|
+
export function getCoordinationDirectory(platform = process.platform) {
|
|
10
|
+
if (platform !== "win32") {
|
|
11
|
+
const uid = getCurrentProcessUid();
|
|
12
|
+
const suffix = uid === undefined ? "" : `-${uid}`;
|
|
13
|
+
return platform === "android"
|
|
14
|
+
? join(tmpdir(), `pi-agent-browser-policy${suffix}`)
|
|
15
|
+
: `/tmp/pi-agent-browser-policy${suffix}`;
|
|
16
|
+
}
|
|
17
|
+
const user = process.env.USERNAME ?? process.env.USER ?? "unknown";
|
|
18
|
+
const suffix = createHash("sha256").update(user).digest("hex").slice(0, 12);
|
|
19
|
+
return join(tmpdir(), `pi-agent-browser-policy-${suffix}`);
|
|
20
|
+
}
|
|
21
|
+
function directoryOwnerTrusted(entry, platform) {
|
|
22
|
+
if (platform === "win32") {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
const uid = getCurrentProcessUid();
|
|
26
|
+
return uid !== undefined && entry.uid === uid && (entry.mode & 0o077) === 0;
|
|
27
|
+
}
|
|
28
|
+
export async function ensureCoordinationDirectory(path, platform) {
|
|
29
|
+
try {
|
|
30
|
+
try {
|
|
31
|
+
await mkdir(path, { mode: 0o700 });
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (getErrorCode(error) !== "EEXIST") {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const entry = await lstat(path);
|
|
39
|
+
return !entry.isSymbolicLink() && entry.isDirectory() && directoryOwnerTrusted(entry, platform);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** Resolve only after native routing; omit sessionName for a namespace-wide operation. */
|
|
46
|
+
export async function resolveBrowserExecutionIdentity(options) {
|
|
47
|
+
const socketDir = resolveAgentBrowserSocketDir(options);
|
|
48
|
+
const namespace = canonicalizeAgentBrowserNamespace(options.namespace);
|
|
49
|
+
let socketContext;
|
|
50
|
+
if (process.platform === "win32") {
|
|
51
|
+
// Windows native TCP daemons are shared across storage roots; don't split their coordination.
|
|
52
|
+
socketContext = `win32-native:${namespace ?? ""}`;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
if (socketDir === undefined) {
|
|
56
|
+
throw new Error("Browser execution coordination requires the native socket directory.");
|
|
57
|
+
}
|
|
58
|
+
const error = await getAgentBrowserSocketDirValidationError(socketDir);
|
|
59
|
+
if (error !== undefined && error.length > 0) {
|
|
60
|
+
throw new Error(`Browser execution coordination cannot use socket storage: ${error}.`);
|
|
61
|
+
}
|
|
62
|
+
const root = await realpath(socketDir);
|
|
63
|
+
socketContext =
|
|
64
|
+
namespace !== undefined && namespace.length > 0
|
|
65
|
+
? join(root, "namespaces", namespace, "run")
|
|
66
|
+
: root;
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
socketContext: foldAgentBrowserFilesystemIdentity(socketContext, process.platform),
|
|
70
|
+
...(options.sessionName !== undefined
|
|
71
|
+
? { sessionName: foldAgentBrowserFilesystemIdentity(options.sessionName, process.platform) }
|
|
72
|
+
: {}),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
export function getBrowserExecutionLockPath(identity) {
|
|
76
|
+
return join(getCoordinationDirectory(), `.pi-agent-browser-policy-${createHash("sha256").update(identity.socketContext).digest("hex")}.lock-v4`);
|
|
77
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { isRecord } from "./parsing.js";
|
|
2
|
+
/** An admitted branch follows native append-only identity/ancestry, never entry body snapshots. */
|
|
3
|
+
class CapturedBrowserBranch {
|
|
4
|
+
manager;
|
|
5
|
+
isGenerationCurrent;
|
|
6
|
+
sessionId;
|
|
7
|
+
anchorId;
|
|
8
|
+
trackedAnchor;
|
|
9
|
+
validatedAnchor;
|
|
10
|
+
validatedLeaf;
|
|
11
|
+
constructor(manager, isGenerationCurrent) {
|
|
12
|
+
this.manager = manager;
|
|
13
|
+
this.isGenerationCurrent = isGenerationCurrent;
|
|
14
|
+
this.sessionId = manager.getSessionId();
|
|
15
|
+
this.anchorId = manager.getLeafId();
|
|
16
|
+
this.trackedAnchor = this.anchorId;
|
|
17
|
+
}
|
|
18
|
+
isCurrent() {
|
|
19
|
+
if (!this.isGenerationCurrent() || this.manager.getSessionId() !== this.sessionId) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
if (this.anchorId !== this.trackedAnchor) {
|
|
23
|
+
this.clearCache();
|
|
24
|
+
this.trackedAnchor = this.anchorId;
|
|
25
|
+
}
|
|
26
|
+
const result = this.walk();
|
|
27
|
+
// Native entries/parents are append-only. Cache only after validation to a root or cached endpoint.
|
|
28
|
+
// ponytail: behind-host ancestor mutation without native reseed/generation is outside this contract; upgrade if Pi exposes ancestry revisions.
|
|
29
|
+
if (result.current && result.selected) {
|
|
30
|
+
this.validatedAnchor = result.anchor ?? this.validatedAnchor;
|
|
31
|
+
this.validatedLeaf = result.selected;
|
|
32
|
+
}
|
|
33
|
+
return result.current;
|
|
34
|
+
}
|
|
35
|
+
clearCache() {
|
|
36
|
+
this.validatedAnchor = undefined;
|
|
37
|
+
this.validatedLeaf = undefined;
|
|
38
|
+
}
|
|
39
|
+
entry(leaf) {
|
|
40
|
+
const entry = this.manager.getEntry(leaf);
|
|
41
|
+
if (!isRecord(entry) ||
|
|
42
|
+
entry.id !== leaf ||
|
|
43
|
+
(entry.parentId !== null && typeof entry.parentId !== "string")) {
|
|
44
|
+
throw new Error("Selected Pi journal ancestry is incomplete.");
|
|
45
|
+
}
|
|
46
|
+
return { value: entry, parentId: entry.parentId };
|
|
47
|
+
}
|
|
48
|
+
cached(leaf) {
|
|
49
|
+
if (leaf === this.anchorId) {
|
|
50
|
+
return this.validatedAnchor;
|
|
51
|
+
}
|
|
52
|
+
return leaf === (isRecord(this.validatedLeaf?.entry) ? this.validatedLeaf.entry.id : undefined)
|
|
53
|
+
? this.validatedLeaf
|
|
54
|
+
: undefined;
|
|
55
|
+
}
|
|
56
|
+
validCache(leaf, entry) {
|
|
57
|
+
const cached = this.cached(leaf);
|
|
58
|
+
if (!cached) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
// Keep indexed lookup: the native API also refreshes fork journal identity.
|
|
62
|
+
if (cached.entry === entry.value && cached.parentId === entry.parentId) {
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
this.clearCache();
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
walk() {
|
|
69
|
+
let leaf = this.manager.getLeafId();
|
|
70
|
+
// Empty selection is not a universal ancestor of independent roots.
|
|
71
|
+
let current = this.anchorId === null && leaf === null;
|
|
72
|
+
const seen = new Set();
|
|
73
|
+
let selected;
|
|
74
|
+
let anchor;
|
|
75
|
+
while (leaf !== null) {
|
|
76
|
+
if (typeof leaf !== "string" || seen.has(leaf)) {
|
|
77
|
+
throw new Error("Selected Pi journal ancestry is invalid or cyclic.");
|
|
78
|
+
}
|
|
79
|
+
seen.add(leaf);
|
|
80
|
+
const entry = this.entry(leaf);
|
|
81
|
+
selected ??= { entry: entry.value, parentId: entry.parentId };
|
|
82
|
+
if (this.validCache(leaf, entry)) {
|
|
83
|
+
current = true;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
if (leaf === this.anchorId) {
|
|
87
|
+
current = true;
|
|
88
|
+
anchor = { entry: entry.value, parentId: entry.parentId };
|
|
89
|
+
}
|
|
90
|
+
leaf = entry.parentId;
|
|
91
|
+
}
|
|
92
|
+
return { current, selected, anchor };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/** Capture before waiting: native branch selection precedes awaited session_tree handlers. */
|
|
96
|
+
export function captureBrowserBranch(manager, isGenerationCurrent) {
|
|
97
|
+
return new CapturedBrowserBranch(manager, isGenerationCurrent);
|
|
98
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|