Skip to content

feat(routes): conventional shared layout module for rendered routes (#312) - #396

Merged
ScriptedAlchemy merged 4 commits into
mainfrom
lane/tails-312-297
Sep 3, 2026
Merged

feat(routes): conventional shared layout module for rendered routes (#312)#396
ScriptedAlchemy merged 4 commits into
mainfrom
lane/tails-312-297

Conversation

@ScriptedAlchemy

Copy link
Copy Markdown
Owner

Summary

Implements #312: a layout.tsx-style convention for the shell around every rendered route.

  • Convention. src/layout.{ts,tsx} default-exports one component receiving { children, route, signal } (AgentLayoutProps from @agent-bundle/runtime) and wraps every rendered route: generated MCP tools/resources/prompts, rendered src/cli/** commands, projected MCP commands, and rendered src/scripts/*.tsx. src/mcp/<server>/layout.{ts,tsx} nests inside it for one generated server (root → server → route). Event routes and browser App routes are never wrapped. _layout.tsx opts out.
  • Compiler. The route graph discovers layouts (CompiledRouteGraph.layouts, only present when declared so pre-layout graph digests are unchanged), validates them statically — AB4830 contract (non-function default, route-only config/inputSchema/resultSchema, execute/render), AB4831 duplicate scope, AB4832 orphaned server layout — and threads them through the normalized model, project identity, and every worker source input.
  • Generated workers. The MCP Flight worker and the rendered CLI/script worker bake each route's layout chain plus stable route identity (id, kind, name, serverId). With layouts, one root component awaits the route element and then wraps it, so a throwing route still rejects the Flight root and fails closed exactly as before (no degradation into a represented boundary error under the shell). Without layouts the emitted worker is the same shape as today (composeLayouts is createElement(route.module.default, props)).
  • Runtime. decodeAgentDocument treats an Agent.Result without a value as a container; a directly nested valued result merges into it (value adopted, children spliced in place, object metadata merged key-by-key with the container winning). A layout shell therefore never changes a route's result value, MCP content/structuredContent, or CLI Markdown. Exports AgentLayoutProps/AgentLayoutRoute/AgentLayoutRouteKind; agent-bundle root exports the React-free identity types only (root declarations stay React-free for config-only consumers — pinned by public-api.test.ts).
  • Test harness. agent-bundle/test composes the same chain at route-unit (renderRoute), cli-dispatch (invokeCli), and mcp-in-memory (invokeMcpTool) levels via manifest layouts + generated layoutLoaders (registry version 4). A module passed directly to renderRoute() composes no layout.
  • Example. examples/audiobook-curator adopts src/layout.tsx as the document shell (root Agent.Result + route provenance metadata) and drops the per-route CuratorDocument wrapper from 21 routes; MCP and CLI output are byte-identical (the Refactor audiobook audit route composition #336 pins pass unchanged). examples/rsc-agent-runtime is a custom-server/prebuilt-payload example with no generated routes, so the convention does not apply there.
  • Docs/changeset. docs/entry-conventions.md (table rows + “Shared layouts”), docs/framework-mode.md, docs/diagnostics.md (AB4830AB4832), README note for output.distPath (Configurable artifact output path (output.distPath) landed in #296 #297 verification), changeset (agent-bundle minor, @agent-bundle/runtime minor).

Evidence

  • Unit: packages/agent-bundle/tests/route-graph.test.ts (discovery, digest stability, opt-out, AB4830/AB4831/AB4832), tests/entry-shell.test.ts (chain baking, root/server/none, identity fields, root-await composition), tests/test-harness-manifest.test.ts (manifest layouts, layoutLoaders), packages/rsc-runtime/tests/dispatcher.test.ts (container merge, nested merge, metadata rules, valued root unchanged).
  • Route-unit: tests/route-unit/render-route.test.ts — root+server layouts around tool:harness/echo keep node kinds and value; probe route shows server-layout content + merged metadata; CLI route takes only the root layout; direct module render composes nothing.
  • Projection: tests/projection/mcp-in-memory.test.ts (layout-probe content + structuredContent), tests/projection/cli-dispatch-mcp.test.ts (projected tool keeps its server layout), contract matrix green with the new fixture route.
  • Integration: new packages/agent-bundle/tests/layout-build.test.ts — one build ships the layouts around the generated MCP server (stdio client), the routed CLI bin (piped Markdown, --json, --ndjson metadata + value), a projected MCP command, and a rendered script; a throwing route under a layout fails closed on both MCP and CLI; a layout-free build ships byte-identical surfaces; an invalid layout fails the build with AB4830.
  • Example: examples/audiobook-curator pnpm typecheck, pnpm test (40), pnpm test:routes (31, incl. new layout-metadata assertions and the unchanged byte-identical CLI pins).

Test plan

  • pnpm typecheck, pnpm lint
  • pnpm test:unit (2 pre-existing environmental failures reproduce on clean origin/main: mcp-probe-service teardown timing, native-claude-contract 5 s timeout)
  • pnpm test:route-unit, pnpm test:projection
  • pnpm build && pnpm test:integration:run (rerunning after rebase; pre-rebase run: 938 passed, 2 failed — host-install-proof Codex logo field fixed on main by test(install): expect the Codex interface.logo field in the packed host-install proof #367, and public-api root-declaration React leak fixed in the second commit)
  • CI green

Closes #312.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 3, 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-03T13:03:23.987888Z 0087552 Manual request
ℹ️ 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.

@changeset-bot

changeset-bot Bot commented Sep 3, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0087552

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

This PR includes changesets to release 2 packages
Name Type
agent-bundle Minor
@agent-bundle/runtime 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 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: 7d61864efa

ℹ️ 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/build/entry-shell.ts Outdated
Comment thread packages/rsc-runtime/src/decode-document.ts Outdated
@pkg-pr-new

pkg-pr-new Bot commented Sep 3, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/ScriptedAlchemy/agent-bundle@396
npm i https://pkg.pr.new/ScriptedAlchemy/agent-bundle/create-agent-bundle@396
npm i https://pkg.pr.new/ScriptedAlchemy/agent-bundle/@agent-bundle/runtime@396

commit: 0087552

ScriptedAlchemy added a commit that referenced this pull request Sep 3, 2026
…ll container metadata

Address Codex review on #396:
- generated MCP and rendered-route workers now import only the layouts some
  route of that worker composes through, so a server-scoped layout for one
  server can no longer be evaluated (or fail) inside an unrelated CLI, script,
  or server process
- decodeAgentDocument treats an explicit metadata={null} on a layout container
  as authored metadata that wins over the inner result, matching the
  non-object-container-wins contract; only undefined adopts the inner metadata
@ScriptedAlchemy

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 43e202c698

ℹ️ 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".

@ScriptedAlchemy

Copy link
Copy Markdown
Owner Author

@codex review

ScriptedAlchemy added a commit that referenced this pull request Sep 3, 2026
…ll container metadata

Address Codex review on #396:
- generated MCP and rendered-route workers now import only the layouts some
  route of that worker composes through, so a server-scoped layout for one
  server can no longer be evaluated (or fail) inside an unrelated CLI, script,
  or server process
- decodeAgentDocument treats an explicit metadata={null} on a layout container
  as authored metadata that wins over the inner result, matching the
  non-object-container-wins contract; only undefined adopts the inner metadata

@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: a4658c1210

ℹ️ 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 .changeset/shared-route-layouts.md Outdated
Comment thread packages/agent-bundle/src/routes/graph.ts
ScriptedAlchemy added a commit that referenced this pull request Sep 3, 2026
…et per convention

Address Codex review on #396 (rebased head a4658c1):
- a src/mcp/<server>/layout.* under a server pinned to custom, command, or
  remote via routes.servers is skipped entirely — not validated (AB4830),
  not retained, and never AB4832 — matching the documented opt-out and the
  way that server's route modules are dropped; the AB4832 recovery names the
  override
- the changeset is one imperative, user-facing summary naming the exports and
  AB4830-AB4832, ends with the PR reference, and uses patch per the pre-1.0
  rule (minor is reserved for breaking changes)
@ScriptedAlchemy

Copy link
Copy Markdown
Owner Author

@codex review

@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: 4d33030e7b

ℹ️ 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/routes/graph.ts
@ScriptedAlchemy

Copy link
Copy Markdown
Owner Author

@codex review

@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: eb7a916821

ℹ️ 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 .changeset/shared-route-layouts.md Outdated
Comment thread packages/agent-bundle/src/build/entry-shell.ts
@ScriptedAlchemy

Copy link
Copy Markdown
Owner Author

@codex review

ScriptedAlchemy added a commit that referenced this pull request Sep 3, 2026
…ll container metadata

Address Codex review on #396:
- generated MCP and rendered-route workers now import only the layouts some
  route of that worker composes through, so a server-scoped layout for one
  server can no longer be evaluated (or fail) inside an unrelated CLI, script,
  or server process
- decodeAgentDocument treats an explicit metadata={null} on a layout container
  as authored metadata that wins over the inner result, matching the
  non-object-container-wins contract; only undefined adopts the inner metadata
ScriptedAlchemy added a commit that referenced this pull request Sep 3, 2026
…et per convention

Address Codex review on #396 (rebased head a4658c1):
- a src/mcp/<server>/layout.* under a server pinned to custom, command, or
  remote via routes.servers is skipped entirely — not validated (AB4830),
  not retained, and never AB4832 — matching the documented opt-out and the
  way that server's route modules are dropped; the AB4832 recovery names the
  override
- the changeset is one imperative, user-facing summary naming the exports and
  AB4830-AB4832, ends with the PR reference, and uses patch per the pre-1.0
  rule (minor is reserved for breaking changes)

@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: f3b560195f

ℹ️ 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/rsc-runtime/src/decode-document.ts
Comment thread packages/agent-bundle/src/routes/graph.ts Outdated
ScriptedAlchemy added a commit that referenced this pull request Sep 3, 2026
…r layouts, version as minor

Address Codex review on #396 (heads eb7a916 and f3b5601):
- decodeAgentDocument snapshots both metadata operands through the document's
  JSON wire boundary before merging a layout container with its valued child,
  so a Date, class instance, accessor, or cyclic value fails closed exactly as
  it does without a layout instead of being flattened into {}
- AB4832 now also fires for a server layout whose server declares only apps/
  routes, which never take a layout, so an accepted layout is always composed
- the changeset returns to minor for both packages: AgentBundleTestManifest
  gains a required layouts field and the decoder changes the output of
  previously valid valueless-root documents, both breaking under the pre-1.0
  policy; the summary names both
- docs record the deliberate route-first composition trade-off (no Suspense
  fallback around children) and the sharpened AB4832 scope
@ScriptedAlchemy

Copy link
Copy Markdown
Owner Author

@codex review

@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: 06de53338c

ℹ️ 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/rsc-runtime/src/decode-document.ts Outdated
@ScriptedAlchemy

Copy link
Copy Markdown
Owner Author

@codex review

@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: c7de7465cb

ℹ️ 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/rsc-runtime/src/decode-document.ts Outdated
@ScriptedAlchemy

Copy link
Copy Markdown
Owner Author

@codex review

@ScriptedAlchemy

Copy link
Copy Markdown
Owner Author

@codex review

@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: 8efaed59b8

ℹ️ 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/rsc-runtime/src/decode-document.ts Outdated
Comment thread docs/entry-conventions.md Outdated
@ScriptedAlchemy

Copy link
Copy Markdown
Owner Author

@codex review

@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: bb9001a47d

ℹ️ 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 examples/audiobook-curator/src/layout.tsx Outdated
@ScriptedAlchemy

Copy link
Copy Markdown
Owner Author

@codex review

@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: 888a941f1a

ℹ️ 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 .changeset/shared-route-layouts.md Outdated
@ScriptedAlchemy

Copy link
Copy Markdown
Owner Author

@codex review

@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: 397c29c543

ℹ️ 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/rsc-runtime/src/decode-document.ts
@ScriptedAlchemy

Copy link
Copy Markdown
Owner Author

@codex review

@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: cdf458254e

ℹ️ 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/rsc-runtime/src/decode-document.ts
Comment thread packages/agent-bundle/README.md Outdated
…splicing; README states the CLI artifact default
@ScriptedAlchemy

Copy link
Copy Markdown
Owner Author

@codex review

@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: daffae1431

ℹ️ 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/build/build.ts
@ScriptedAlchemy

Copy link
Copy Markdown
Owner Author

@codex review

@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: 3bc0e09442

ℹ️ 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/rsc-runtime/src/decode-document.ts
@ScriptedAlchemy

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 0087552a98

ℹ️ 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".

@ScriptedAlchemy
ScriptedAlchemy merged commit 43a39ad into main Sep 3, 2026
11 checks passed
@ScriptedAlchemy
ScriptedAlchemy deleted the lane/tails-312-297 branch September 3, 2026 13:19
ScriptedAlchemy added a commit that referenced this pull request Sep 3, 2026
main (#396) adds src/layout.tsx and src/mcp/<server>/layout.tsx. The
conventions table and source tree list both, MCP servers and Apps gains a
Shared layouts section covering composition order, container merging,
route identity, failure semantics, and AB4830-AB4832, and the reference
code-family table names the layout codes.
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.

Add a conventional shared layout module for server routes

1 participant