Skip to content

RFC: CodingAgent — a new @cloudflare/coding-agent package#1831

Merged
threepointone merged 5 commits into
mainfrom
rfc/coding-agent
Jun 28, 2026
Merged

RFC: CodingAgent — a new @cloudflare/coding-agent package#1831
threepointone merged 5 commits into
mainfrom
rfc/coding-agent

Conversation

@threepointone

@threepointone threepointone commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds design/rfc-coding-agent.md (status: proposed) — an RFC to extract the sandbox-coding-agent example into a new @cloudflare/coding-agent package: a CodingAgent that drives a coding agent (Claude Code first) inside a Cloudflare Sandbox, with a chat UI, durable sessions, recovery, and orchestration-friendliness.

import { CodingAgent } from "@cloudflare/coding-agent/claude-code";

export class MyCoder extends CodingAgent<Env> {
  repo = "https://github.com/threepointone/aywson"; // a default — usually resolved per-instance
}

The RFC was rewritten after an adversarial review. The original draft made CodingAgent a Think subclass behind a new internal turn-runtime seam in Think core; that's been dropped — see below.

Key decisions

  • Own package, AIChatAgent base — not Think. CodingAgent extends AIChatAgent, so onChatMessage is the seam and Think core is untouched (drops the riskiest piece of the original plan). A coding agent isn't a chat-model agent, so inheriting Think would leave ~half its surface inert; and a separate package honors the AGENTS.md layering preference (containers don't belong in the chat base) and can track whatever AI-SDK major @ai-sdk/harness needs without gating the repo.
  • Pluggable engine. CliEngine ships first (the example's mapper, works today, no new deps); HarnessEngine is the goal — it reuses the AI SDK HarnessAgent's tested stream-mapping and session lifecycle (detach/stop/suspendTurn/resume) for free, gated on the CF sandbox provider (Add an @ai-sdk/sandbox-cloudflare HarnessAgent provider (during ai v7 migration) #1829). No speculative multi-CLI adapter interface — extract after codex actually lands.
  • Durability redesigned around two decoupled lifecycles. The DO (control plane) and the container (compute) have different shutdown behaviors and fail independently, so it's a reconcile-on-wake protocol with the DO as source of truth — not one checkpoint. Honest about the limits: claude -p can't resume a killed turn (mid-turn recovery = reset-to-checkpoint + re-run, with double-apply risk called out), and snapshot cost must be bounded.
  • Egress scoped honestly (per-provider, TLS-interception-dependent, OAuth CLIs can't be tokenless), branch is mutable working state (only repo identity is frozen), and a Testing & CI section (fixtures on the PR path; real-Docker e2e gated nightly).
  • Filesystem VFS / preview / git ops / HITL / a Workers-native "Runtime B" are explicit Directions, not v1 seams.

Alternatives (Think subclass + core seam; hand-rolled mapper as the only engine; a Think subpath; adopt cloudflare/workspace now; keep as example) are documented with rationale.

Open questions for reviewers

  1. Package name (@cloudflare/coding-agent?) + /claude-code subpath convention.
  2. CliEngine vs HarnessEngine as the default for the first release (ship now and migrate, or wait for Add an @ai-sdk/sandbox-cloudflare HarnessAgent provider (during ai v7 migration) #1829?).
  3. CliEngine snapshot policy (what/how-often/the node_modules question).
  4. First-PR scope: new package skeleton + CliEngine + tokenless egress + two-lifecycle durability + dynamic config + rewrite the example onto the package. Codex, HarnessEngine, preview, git ops, HITL, VFS deferred.

Related

Test plan

  • Docs-only; pnpm run format clean, no other files touched.
  • Reviewers: weigh in on the four open questions before implementation begins.

Proposes promoting examples/sandbox-coding-agent (#1830) into @cloudflare/think
as a supported `CodingAgent` class — a Think subclass that drives a CLI coding
agent (Claude Code first) inside a Cloudflare Sandbox, exported per-CLI as
`@cloudflare/think/claudecode`.

Locks the surface before any core code moves: an internal TurnRuntime seam in
Think (private, CodingAgent is its only consumer), a per-CLI adapter contract,
tokenless AI Gateway egress + snapshot-based durability built in, DO-tuned
recovery, and a conformance-test strategy for stream-json drift. Strategic
stance: own the public interface, keep the engine swappable (a matured
@ai-sdk/harness could become an impl detail behind the same class — #1829).

Status: proposed.
Co-authored-by: Cursor <cursoragent@cursor.com>
@changeset-bot

changeset-bot Bot commented Jun 28, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 091cd72

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

threepointone and others added 3 commits June 28, 2026 14:07
Folds in the firm follow-ups from review:
- §8 dynamic config (resolve-by-precedence, freeze-on-first-turn) + topology
  (standalone / Chats-child threads / orchestrated), with the "no top-level
  binding assumption" requirement.
- §9 two seams designed in from day one: a filesystem backend interface (so the
  durable cloudflare/workspace VFS can supersede snapshots later) and run/preview
  by target (container dev server vs worker-bundler + env.LOADER).
- §10 future-work pointer to a Workers-native runtime (Runtime B) behind the same
  TurnRuntime seam.
- New alternative (adopt cloudflare/workspace now — rejected, preview-only) and
  expanded decision questions.

Co-authored-by: Cursor <cursoragent@cursor.com>
…y pattern

The fixed chats_index/ChatSummary schema is the part consumers outgrow
immediately — a coding directory needs repo/branch/status/lastDiff, etc. So:

- rfc-coding-agent §8: reframe "threads" as a userland directory pattern (plain
  Agent + subAgent with domain-specific metadata), not a `Chats` base class. The
  shipped, load-bearing primitives it leans on are unchanged (subAgent + Props,
  parentAgent, RemoteContextProvider).
- rfc-think-multi-session: record the third (now-leaning) answer to open question
  #1 — don't ship a Chats base class; ship primitives + a thin client hook + an
  example.

Co-authored-by: Cursor <cursoragent@cursor.com>
…e, pluggable engine

Adversarial review reshaped the design:
- New @cloudflare/coding-agent package, NOT a Think subclass/subpath. Extends
  AIChatAgent, so onChatMessage is the seam and Think core is untouched (drops
  the riskiest piece — the turn-runtime refactor). Honors the AGENTS.md layering
  preference (containers don't belong in the chat base).
- Pluggable engine: CliEngine ships first (lift the example's mapper), HarnessEngine
  is the goal (reuses HarnessAgent's tested stream-mapping + session lifecycle;
  gated on #1829). No speculative multi-CLI adapter interface — extract after codex.
- Durability redesigned around two decoupled lifecycles (DO vs container have
  different shutdown behaviors); reconcile-on-wake; honest that claude -p can't
  resume a killed turn and that re-run can double-apply edits; bound snapshot cost.
- Egress scoped honestly (per-provider, TLS-dependent, OAuth CLIs can't be tokenless).
- Branch is mutable working state (git checkout), only repo identity is frozen.
- Filesystem VFS, preview, git ops, HITL, and Runtime B moved to "Directions"
  (not v1 seams). Added a Testing & CI section.

Co-authored-by: Cursor <cursoragent@cursor.com>
@threepointone threepointone changed the title RFC: first-class CodingAgent for Think (@cloudflare/think/claudecode) RFC: CodingAgent — a new @cloudflare/coding-agent package Jun 28, 2026
Package name @cloudflare/coding-agent + /claude-code subpath confirmed. Engine
default, snapshot policy, and first-PR scope remain deliberately open.

Co-authored-by: Cursor <cursoragent@cursor.com>
@threepointone threepointone merged commit 4d30a84 into main Jun 28, 2026
2 checks passed
@threepointone threepointone deleted the rfc/coding-agent branch June 28, 2026 23:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant