Skip to content

feat(workbench): Agent Document stage over server-decoded render events (#105 stage 2) - #231

Merged
ScriptedAlchemy merged 1 commit into
mainfrom
wave5/105-s2-docstage
Sep 1, 2026
Merged

feat(workbench): Agent Document stage over server-decoded render events (#105 stage 2)#231
ScriptedAlchemy merged 1 commit into
mainfrom
wave5/105-s2-docstage

Conversation

@ScriptedAlchemy

Copy link
Copy Markdown
Owner

Second and final #105 stage-2 slice (per #107 rev 2: "Agent Document stage + Markdown projection"). The Workbench now renders the #140 Agent Document / render-event stream for route runs instead of raw JSON.

Flight stays internal (#107 constraint)

  • New read-only GET /api/runtime/runs/:id/document on the foreground dev server (same-session guard, query strings rejected, GET-only): reads the succeeded run's stored Flight bytes (same source as the existing flight download) and decodes them through decodeAgentFlightStream with the default AgentRenderLimits, responding with the ordered shell/progress/replace/error/complete event sequence as JSON. The browser never sees Flight bytes.
  • @agent-bundle/runtime is an optional peer, so the route uses the repo's documented cached lazy-import pattern: a missing peer yields AB8207 (503), an undecodable payload AB8208 (409) — honest diagnostics, never a fabricated document. A unit test renders REAL Flight in a react-server-condition child worker and proves the foreground process decodes it (plus absent-peer, guard, and query-rejection cases).

Browser wire discipline

  • AgentDocumentClient (workbench) fetches via the same foreground-request authority as the manifest client and strictly decodes the full event union and every node kind with z.strictObject schemas (recursive result, markdown, text, context, json, progress, image, audio, resource, error; document {version:1,status,root,value?}). Unknown fields fail loudly. Endpoint + decoder land together; no existing DTO widened. The Workbench does not import the runtime package.

Stage + fold + integration

  • Pure foldAgentDocumentEvents: latest snapshot-carrying event wins (replace IS the Suspense replacement, resolved server-side), progress drives a live status line, error events accumulate into a diagnostics strip, complete pins final status.
  • AgentDocumentStage: markdown through the SAME audited projector the Skills page uses (extracted as MarkdownProjector from skill-markdown.tsx — no new markdown dependency), context labeled as the host context channel, json pretty-printed, image/audio as real data-URI elements, resource rows, error nodes marked with code+message, document status/version, and an event timeline where selecting an event renders the document as of that event.
  • Runtime Playground inspector gains a "Document" tab beside the existing six; explicit loading/failure states; runs without stored Flight or with undecodable payloads show the diagnostic honestly. All existing tabs unchanged.

MCP wire shape (investigated, reported honestly)

documentToCallToolResult lowers the final document into plain MCP content blocks (text/image/audio/resource_link) with structuredContent from document.value — the AgentDocument itself is deliberately NOT on the MCP protocol wire (that lowering is the target-projection story). So the MCP page keeps showing the projection the server actually returned, and compiled MCP tools reach the document stage through their runtime runs (mcp-tool surfaces produce Flight-bearing envelopes the playground now decodes). Nothing is fabricated client-side.

Verification

  • pnpm typecheck + all example typechecks: clean. pnpm lint: clean.
  • Unit: 2251 passed / 5 skipped across agent-bundle, workbench, and rsc-runtime slices (fold ordering/replace-wins/error strip; strict decode incl. unknown-field rejection at every level; per-node stage rendering through the real projector; real-Flight foreground decode; honest diagnostics).
  • Browser: runtime-playground.e2e.test.ts (real Chrome, 1440×900) 3/3 — the hook run's stored Flight decodes into a rendered Agent Document (Version 1 · success, text content as elements, Complete timeline entry) and an MCP-element run shows the honest decode diagnostic; rstest-browser Document-tab coverage renders real markdown headings.

…ts (#105 stage 2)

Decode a succeeded run's stored Flight on the dev server through the optional
runtime peer, serve the bounded render-event sequence read-only, and render it
in a shared Workbench stage with markdown projection, all node kinds, live
progress, render diagnostics, and an inspectable event timeline.
@changeset-bot

changeset-bot Bot commented Sep 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6e28fc8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
agent-bundle Minor

Not sure what this means? Click here to learn what changesets are.

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-01T23:05:18.399941Z 6e28fc8 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ScriptedAlchemy
ScriptedAlchemy merged commit 8a5b425 into main Sep 1, 2026
6 of 9 checks passed
@ScriptedAlchemy
ScriptedAlchemy deleted the wave5/105-s2-docstage branch September 1, 2026 23:03

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6e28fc83df

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/agent-bundle/src/dev/runtime-routes.ts
Comment thread packages/workbench/src/runtime/agent-document-stage.tsx
@ScriptedAlchemy

Copy link
Copy Markdown
Owner Author

Heads-up: hosted main CI went red with this merge and stayed red through #234 — deterministic failures in runtime-inspector.test.ts (six-panels census) and public-api.test.ts (bundled config extension declarations) on all three Verify legs. Bisect details and run links in #240. Every open PR is currently failing on the merge ref because of this.

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