refactor(cli): migrate Browse runtime and commands to Stagehand V4 - #2834
Conversation
|
7e9c944 to
34c5c7d
Compare
df91115 to
389e2da
Compare
There was a problem hiding this comment.
All reported issues were addressed across 22 files
Architecture diagram
sequenceDiagram
participant CLI as Browse CLI Client
participant Daemon as Driver Daemon
participant Manager as Driver Session Manager
participant Factory as Stagehand V4 Browser Factories
participant BB as Browserbase
participant Browser as Browser or CDP Target
participant Stagehand as Stagehand V4 Session
participant Context as Browser Context and Pages
participant Page as Active Page and Locators
Note over CLI,Page: Browse runtime uses a daemon-owned session and Stagehand V4 browser lifecycle
CLI->>Daemon: Open or execute driver command
Daemon->>Daemon: Resolve session, target, and forwarded environment
Daemon->>Manager: Dispatch request
alt Managed local target
Manager->>Factory: localBrowser.launch(headless, Chrome args)
Factory->>Browser: Launch local browser
Browser-->>Factory: Browser handle
else Browserbase remote target
Manager->>Factory: browserbase.launch(apiKey, userMetadata, flags)
Factory->>BB: Create managed remote session
BB-->>Factory: Browser handle and session identity
Factory->>BB: Lookup debug URL
BB-->>Factory: Optional live-view URL
Factory-->>Manager: Browser and Browserbase identity
else Attached CDP target
Manager->>Factory: localBrowser.connect(cdpUrl)
Factory->>Browser: Attach to existing browser
Browser-->>Factory: Browser handle
end
Manager->>Stagehand: Stagehand.create(browser, logging off)
Stagehand->>Context: Resolve browser context
Context-->>Manager: Context and page collection
Manager-->>Daemon: Session initialized
Daemon-->>CLI: Open result, mode, pages, and session identity
CLI->>Daemon: Navigation, query, input, tab, or runtime command
Daemon->>Manager: Dispatch command
Manager->>Context: Resolve active or requested page
Context-->>Manager: Active page
Manager->>Page: Call V4 page API
alt Standard command succeeds
Page->>Page: Navigate, query locator, click, fill, select, type, screenshot, eval, or manage tabs
Page-->>Manager: Result
Manager-->>Daemon: Command response
Daemon-->>CLI: Result data
else Coordinate XPath requested
Page-->>Manager: Error: coordinate XPath unavailable in V4
Manager-->>Daemon: Explicit capability error
Daemon-->>CLI: Command failure
else Cursor or network capability requested
Manager-->>Daemon: Explicit unavailable capability error
Daemon-->>CLI: Command failure
end
Note over Daemon,Manager: Open requests allow browser initialization time plus the configured navigation timeout
CLI->>Daemon: Stop session
Daemon->>Manager: Close session
Manager->>Stagehand: Close Stagehand session
Manager->>Browser: Close owned browser
alt Attached CDP target
Manager->>Browser: Preserve externally owned browser
else Managed local or Browserbase target
Browser-->>Manager: Owned resources cleaned up
end
Manager-->>Daemon: Session stopped
Daemon-->>CLI: Stop result
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
c607e3f to
21e78e2
Compare
21e78e2 to
6f7e9c2
Compare
6f7e9c2 to
07ed1a0
Compare
## Summary Import `packages/cli/**` exactly from the published `browse@0.9.6` V3 release, without changing its source or runtime behavior. This is intentionally a provenance checkpoint, not a line-by-line feature review. The imported source is kept runnable by a root, version-scoped pnpm override that resolves its unchanged Stagehand dependency to `3.7.1`. #2834 removes that override and starts the V4 migration. ## Exact-source provenance - Annotated tag: `browse@0.9.6` (`548c56407431db27823a212f53475443c7e8358d`) - Release commit: `1d49a95c0c230c346f8d50647e10303d6310fcd2` - Authoritative CLI tree: `b4048badce921cf54f199f96033d9a014ef977ec` - This PR's `HEAD:packages/cli` tree: `b4048badce921cf54f199f96033d9a014ef977ec` The tag's ignored README whitespace is retained too; formatting the import would invalidate the tree proof. ## Verification - Current remote head: `a77e1507b85e3c02553f36ead6ebd0237b0cccc6`, based on current `main`. - `HEAD:packages/cli` exactly equals the published V3 tree hash above. - pnpm 11 frozen install and the repository supply-chain release-age policy pass. - Browse lint, typecheck, and build pass; the full baseline suite passes: 25 files / 366 tests. - A fresh extension build still exactly matches the Go-embedded archive: SHA-256 `8efc7d171a625cca95c02d02d369b59435fae776cae6c7dd2f6fe72eb19785c0` on both files. This specifically verifies that adding the V3 dependency graph does not perturb the current V4 extension artifact. - This layer intentionally exercises V3 through the scoped Stagehand 3.7.1 override. V4 behavior starts in #2834. ## Stack (#2872) 1. **#2833 — exact Browse V3 baseline import** 2. #2834 — Stagehand V4 runtime and standard command parity 3. #2869 — CLI-owned cursor overlay 4. #2849 — CLI-private CDP sidecar; V3 network parity 5. #2835 — remove `--return-xpath`; supported V3 parity/release checkpoint 6. #2838 — eval and packaging integration 7. #2839 — managed Context names (fast-follow) 8. #2701 — shared Functions core consumer (fast-follow) ## Review and landing boundary Review this PR by verifying the tree hashes, dependency pin, root package wiring, and changeset—not by treating the imported V3 source as newly authored code. This head deliberately imports V3 code into the V4 repository and is not independently publishable. It lands only as the base of the complete stack. The framework network-event schema proposal in #2832 is intentionally outside this landing stack.
07ed1a0 to
8ff04c9
Compare
AzamAbdul
left a comment
There was a problem hiding this comment.
LGTM at first pass of v4 vs v3 contract changes. One comment from Astra wrt potential left over connections
Addresses review feedback from AzamAbdul.
Summary
Migrate Browse's browser lifecycle and standard command surface together from Stagehand V3 to V4.
Stagehand.create().act()path.Stack (#2872)
--return-xpath; supported V3 parity/release checkpointReview shape
The lifecycle and command migration remain two ordered implementation commits:
389e2dae6— V4 browser/session foundation and lifecycle ownership.b45167462— standard command translation on that foundation.They are one PR because both commits rewrite the same nine command/test files. Reviewing their combined final diff avoids temporary deletion/stubbing followed by reimplementation, while the commits still provide useful lifecycle-versus-command checkpoints. Review follow-up
24178275fadds narrowly scoped ownership, error-sanitization, and timeout guards. The resulting PR diff is 23 files, +988/−436.Cursor DOM injection and private CDP network transport remain separate because they are independently reviewable mechanisms and cleanly additive diffs. The legacy coordinate
returnXPathrequest is still accepted here but fails explicitly until #2835 removes the option. This remains an intentionally non-publishable intermediate head.E2E Test Matrix
Fresh post-flatten verification used the actual built CLI at final head
6f7e9c209. Every daemon command used an isolated owner-only runtime directory.pnpm install --frozen-lockfilepnpm exec turbo run build --filter=browsedistfilespackages/sdk-go/internal/extensionassets/stagehand-extension.zip8efc7d171a625cca95c02d02d369b59435fae776cae6c7dd2f6fe72eb19785c0; archive manifest and package version both1.0.2browse open <synthetic-data-url> --remote;browse statusbrowse get text //h1;fill;select;click;is checked;wait selector;highlight;viewport;screenshot;snapshot --fullReady; input becameAda; select becameb; click producedClicked; checkbox was true; PNG was 17,761 bytes; snapshot contained the fixturetab new;tab list;tab close; read the marker from a new CLI processyesbrowse stop; poll the Browserbase session0700/0600; the owned remote session reachedCOMPLETEDbrowse cursor;browse network on;browse mouse hover ... --return-xpathpnpm --filter browse testThe runner has no Chrome/Chromium installation, so a fresh attached-CDP ownership smoke was not possible. Attached-browser non-ownership remains covered by the focused suite and is not claimed as a fresh live result here.