Skip to content

How PEAR works

PEAR is a durable control loop for applications that help people execute plans under changing conditions.

Two flows, one boundary

Compile

text
Source upload → R2 bytes + D1 metadata
→ Interpret → Clarify? → Synthesize
→ Zod + Domain validation
→ versioned Plan Artifact → Review → Ready

A Plan Artifact is reusable, reviewable work definition. It is not yet a running session.

Execute

text
Ready Plan Artifact → Execution Session
→ Runtime Event → pure reducer
→ atomic D1 event + materialized-state update
→ WebSocket invalidation pulse → HTTP Snapshot refetch

An Execution Session is durable work state: plan version, step states, world state, timers, criteria, continuations, and recent events.

The PEAR loop

PhaseQuestionDurable output
PlanWhat should happen, in what dependency order?Validated Plan DAG
ExecuteWhat action occurred?Typed Runtime Event
AssessWhat changed in facts, resources, constraints, or criteria?Updated materialized state
ReplanWhich future work is actually affected?Validated Plan Patch and new Plan Version

State changes do not jump around this loop. User actions, tools, and models propose typed inputs; policy, authorization, schemas, and reducers decide what becomes durable.

Source of truth

HTTP Snapshots are authoritative for clients. Agent WebSockets contain only invalidation metadata such as revision and lastEventId. This avoids maintaining competing state between the Durable Object connection and D1.

D1 stores the event log and materialized state. The event append and state update are atomic and idempotent. R2 stores source bytes; D1 stores source metadata and checksums.

Host and Runtime ownership

Host application ownsPEAR owns
Domain schemas and policyportable Zod contracts
authentication and authorizationauthorization hooks
UI and routingtyped React clients and hooks
provider credentials and model choiceprovider-neutral AI adapters
product-specific capabilitiescapability and event contracts
Cloudflare resourcesD1/R2/Agent/Workflow adapters

This boundary keeps Core environment-independent and makes the host responsible for product decisions that a generic runtime cannot safely infer.

Sessions are not connections

Execution Session is durable. Voice Session and WebSocket connections are ephemeral. Closing a browser, losing audio, or reconnecting a socket does not implicitly stop work. Continuations persist enough state to resume deliberately.

Bounded replanning

A replan begins from cause Events and expands only through the affected downstream subgraph. Completed and skipped steps are immutable. Active-step changes require pause and human confirmation. The result is a Plan Patch with an auditable operation list, not an unstructured replacement plan.

Execution support, not autonomous guesswork.