Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
c73923a
docs for CDP layer plan
Dingway98 Nov 10, 2025
19d111a
phase 1.1 workstream A
Dingway98 Nov 11, 2025
40c1b29
finished up Phase 1
Dingway98 Nov 11, 2025
05781f7
phase 2 - initial working version
Dingway98 Nov 11, 2025
acf3141
fix edge cases for CDP action interactions
Dingway98 Nov 12, 2025
f033bd4
phase 2 polish
Dingway98 Nov 12, 2025
7ae18e5
pahse 3 docs plan
Dingway98 Nov 12, 2025
5b9ab38
initial working version of CDP first frames
Dingway98 Nov 12, 2025
0dcfeb9
auto attach frames
Dingway98 Nov 12, 2025
dcdb63f
finish phase 3 with some leftover code
Dingway98 Nov 13, 2025
5f2b882
optimized dom settling and CDP session management
Dingway98 Nov 13, 2025
b0b94e5
more optimizations
Dingway98 Nov 14, 2025
ed1af7d
remove planning docs
Dingway98 Nov 14, 2025
b2f3878
make geta11ydom retry if couldn't get AX TRee
Dingway98 Nov 14, 2025
d71fdfd
fix scroll, removed feature flags
Dingway98 Nov 14, 2025
f841c97
update .gitignore
Dingway98 Nov 14, 2025
1089613
simplify CDP opt out
Dingway98 Nov 14, 2025
ff7dcbf
clean up debug logging
Dingway98 Nov 14, 2025
0857000
update readme
Dingway98 Nov 14, 2025
0c0b086
remove unused deps
Dingway98 Nov 14, 2025
628f338
remove more logging
Dingway98 Nov 14, 2025
78df8f3
fix
Dingway98 Nov 14, 2025
7ce1533
fix
Dingway98 Nov 14, 2025
3d3e97c
fix oopif
Dingway98 Nov 15, 2025
ff979d7
fix frame mapping, remove legacy code
Dingway98 Nov 16, 2025
a7eab81
fix screenshots
Dingway98 Nov 16, 2025
f87fd85
tighten the prompt some more
Dingway98 Nov 16, 2025
676d673
update scripts
Dingway98 Nov 16, 2025
7ac6532
add more comments and DOM pierce: false for OOPIF
Dingway98 Nov 17, 2025
fb21bdf
fix resolve
Dingway98 Nov 17, 2025
08bbf11
parallelize iframe fetching
Dingway98 Nov 17, 2025
02e05a1
captureOOPIF on every dom refresh
Dingway98 Nov 17, 2025
0c25905
cache CDP OOPIF sessions
Dingway98 Nov 17, 2025
d64996b
cache CDP OOPIF frames, fix prompt, use tools for claude
Dingway98 Nov 18, 2025
e12460a
ignore ads. fix prompt. make agent better when it's long task
Dingway98 Nov 18, 2025
40e1c8c
add errors from schema, so LLM learns from them
Dingway98 Nov 18, 2025
225b039
update docs
Dingway98 Nov 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions docs/cdp-architecture-overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# HyperAgent CDP Architecture Overview

Phase-by-phase snapshot of the end state we are marching toward. Each layer builds on the previous to deliver a fully CDP-driven agent that can run on Playwright, Puppeteer, or raw CDP sessions via connectors.

```
┌────────────────────────────────────────────────────────────────────────────┐
│ Phase 6 (Diagnostics) │
│ Frame ↔ Driver Mapping, Debug artifacts, Optional driver hooks │
└────────────┬───────────────────────────────────────────────────────────────┘
┌────────────▼───────────────────────────────────────────────────────────────┐
│ Phase 5 (Core Agent) │
│ CDP-only actions, Lifecycle/Network waits, structured logging, retries │
└────────────┬───────────────────────────────────────────────────────────────┘
┌────────────▼───────────────────────────────────────────────────────────────┐
│ Phase 4 (Driver Abstraction) │
│ GenericPage/Context, Playwright & Puppeteer adapters, connectors │
└────────────┬───────────────────────────────────────────────────────────────┘
┌────────────▼───────────────────────────────────────────────────────────────┐
│ Phase 3 (Frame & Lifecycle Core) │
│ FrameGraph, ExecutionContextRegistry, NetworkManager, LifecycleWatcher │
└────────────┬───────────────────────────────────────────────────────────────┘
┌────────────▼───────────────────────────────────────────────────────────────┐
│ Phase 2 (CDP Element & Actions) │
│ Frame-first resolver, backend node cache, CDP interaction library, diffs │
└────────────┬───────────────────────────────────────────────────────────────┘
┌────────────▼───────────────────────────────────────────────────────────────┐
│ Phase 1 (CDP Foundation) │
│ CDP client cache, transport/multiplexer, script injectors, adapters │
└────────────────────────────────────────────────────────────────────────────┘
```

## Component Relationships

1. **CDP Transport & Sessions (Phase 1)**
- `CdpConnection` owns the WebSocket, auto-attaches targets, multiplexes child sessions.
- Script injector ensures bounding-box/DOM helpers exist in every session.

2. **Element Resolution & Actions (Phase 2)**
- Encoded IDs decode to `{ frameIndex, backendNodeId }` → FrameGraph supplies frameId/session.
- CDP interaction library (click, fill, drag, file upload, wheel) operates solely via CDP.
- Snapshot diff/focus selectors reduce DOM payload sent to the LLM.

3. **FrameGraph, Execution Contexts, Network/Lifecycle (Phase 3)**
- FrameGraph tracks parent/child links, session ownership, backend node IDs, ordinals.
- ExecutionContextRegistry listens to `Runtime.executionContextCreated` per session.
- NetworkManager + LifecycleWatcher coordinate `waitForDomIdle` across all frames.

4. **Driver Abstraction & Connectors (Phase 4)**
- `GenericPage` interface hides Playwright/Puppeteer specifics.
- `GenericContext` mirrors Stagehand’s context manager: manages multiple pages, popups, OOPIF adoption.
- Connectors (`connectPlaywrightSession`, `connectPuppeteerSession`, raw CDP in future) plug user sessions into the stack.

5. **Core Agent (Phase 5)**
- `runAgentTask` / `page.aiAction` call the LifecycleWatcher before/after each DOM fetch or action.
- `ActionContext` exposes helpers (`resolveElement`, `executeCDPAction`, `getBoundingBox`, `waitForDomIdle`).
- Structured logging and debug artifacts (`frameGraph.json`, `cdp-actions.json`, `network-log.json`).

6. **Frame-to-Driver Mapping (Phase 6)**
- Optional map between CDP frameIds and driver handles for diagnostics or escape hatches.
- Not required for execution but improves observability and parity with existing tooling.

## Execution Flow (High Level)

1. **Bootstrap**
- Transport connects, auto-attaches targets, script injector installs helpers.
- GenericContext creates `GenericPage` instances, FrameGraph + ExecutionContextRegistry begin tracking.
2. **DOM Capture**
- LifecycleWatcher waits for network idle.
- `getA11yDOM` uses FrameGraph + CDP sessions per frame, collecting encoded IDs, XPath, bounding boxes.
- Snapshot diffing optionally trims the payload.
3. **LLM Planning**
- Combined tree + screenshot sent to the model; result includes encoded IDs + methods.
4. **Action Execution**
- `ActionContext.resolveElement(encodedId)` → frameId/session/backendNodeId via FrameGraph.
- `executeCDPAction` runs the appropriate CDP routine (click, fill, etc.) with retries.
- LifecycleWatcher confirms DOM settled afterward.
5. **Diagnostics**
- Each step logs frameId/backendNodeId, bounding boxes, CDP commands, network state.
- Optional frame-driver map surfaces driver-specific handles when needed.

This layered approach ensures we can swap browser drivers, adopt connectors, and continue iterating on agent intelligence without revisiting the foundational plumbing. Each phase builds concrete subsystems that the subsequent phases rely on, culminating in a fully CDP-native agent runtime.
Loading