Skip to content

feat(studio): wire editor draft and publish flows#13

Merged
iipanda merged 17 commits into
mainfrom
codex/cms-56-cms-133-editor-publish
Mar 31, 2026
Merged

feat(studio): wire editor draft and publish flows#13
iipanda merged 17 commits into
mainfrom
codex/cms-56-cms-133-editor-publish

Conversation

@iipanda
Copy link
Copy Markdown
Collaborator

@iipanda iipanda commented Mar 27, 2026

Summary

  • wire the routed Studio document page to real draft load/save behavior with local schema-hash gating and truthful read-only handling
  • add publish, version history, and arbitrary version diff flows on the editor route, including stale load/save race protection
  • document the routed editor contract and add focused integration coverage for load/save/publish/history/diff behavior

Test Plan

  • bun test packages/studio/src
  • bun nx build studio
  • bun nx typecheck studio
  • bun run format:check
  • bun run check

Summary by CodeRabbit

  • New Features

    • Routed document editor: draft load/save, publish, version history, deterministic version diffs, state-driven editor with debounced autosave and save-state feedback.
    • Mount context may include document-route info with write capability and deterministic schema-hash when available.
  • Documentation

    • README expanded describing routed document editor behavior and MVP scope.
  • Bug Fixes

    • Improved error normalization and handling for malformed responses and schema-derivation failures.
  • Tests

    • Extensive new and tightened tests covering APIs, schema resolution, diffs, and UI flows.
  • Chores

    • Updated ignore and dev script/watch assertions.

Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

⚠️ Code review skipped — your organization's overage spend limit has been reached.

Code review is billed via overage credits. To resume reviews, an organization admin can raise the monthly limit at claude.ai/admin-settings/claude-code.

Once credits are available, reopen this pull request to trigger a review.

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
mdcms Error Error Mar 31, 2026 10:57am

Request Review

@iipanda
Copy link
Copy Markdown
Collaborator Author

iipanda commented Mar 30, 2026

@codex review

Copy link
Copy Markdown

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

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: 9c6e0af274

ℹ️ 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/studio/src/lib/runtime-ui/pages/content-document-page.tsx Outdated
Comment thread packages/studio/src/lib/runtime-ui/pages/content-document-page.tsx Outdated
@iipanda
Copy link
Copy Markdown
Collaborator Author

iipanda commented Mar 30, 2026

@coderabbitai

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 30, 2026

The author of this PR is on the CodeRabbit Free Plan. In order to use the Chat feature, please upgrade the PR author to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 30, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Adds routed-document support: new contract types and Zod schemas, deterministic schema-hash capability resolver, a Document Route HTTP API, version-diff logic, bootstrap integration to populate optional documentRoute in mount context, a state-driven content document page, UI/auth helpers, many tests, and docs/dev script tweaks.

Changes

Cohort / File(s) Summary
Git Configuration
\.gitignore
Add .worktrees/ to ignore.
Contracts & Validation
packages/shared/src/lib/contracts/extensibility.ts, packages/shared/src/lib/contracts/extensibility.test.ts
Add StudioDocumentRouteWriteContext, StudioDocumentRouteMountContext, optional documentRoute on StudioMountContext, new Zod schemas; tests updated including a negative case for missing schemaHash.
Document Route Schema Resolution
packages/studio/src/lib/document-route-schema.ts, packages/studio/src/lib/document-route-schema.test.ts
Add resolveStudioDocumentRouteSchemaCapability and capability types; derive deterministic environment schemaHash or return read-only reasons; tests for determinism and failure modes.
Document Route API & Tests
packages/studio/src/lib/document-route-api.ts, packages/studio/src/lib/document-route-api.test.ts
New createStudioDocumentRouteApi with loadDraft, bootstrapSessionCsrf, updateDraft, publish, listVersions, getVersion; header/auth handling, defensive response validation and RuntimeError mapping; comprehensive request/response tests.
Version Diffing & Tests
packages/studio/src/lib/document-version-diff.ts, packages/studio/src/lib/document-version-diff.test.ts
Add diffDocumentVersions with recursive frontmatter diff, LCS/fallback body diffing, exported diff types; extensive tests for normalization, large inputs, and determinism.
Runtime Loader & Integration
packages/studio/src/lib/studio-loader.ts, packages/studio/src/lib/studio-loader.test.ts, packages/studio/src/lib/studio.ts
Resolve schema capability during bootstrap and optionally populate documentRoute in mount context (write-capability or read-only message); add helpers and re-export resolver/type; tests updated to assert documentRoute.
Document Shell & Page Logic
packages/studio/src/lib/document-shell.ts, packages/studio/src/lib/runtime-ui/pages/content-document-page.tsx, packages/studio/src/lib/runtime-ui/pages/content-document-page.test.tsx
Delegate draft loading to createStudioDocumentRouteApi(...).loadDraft, extend StudioDocumentShellData with publish/version metadata, implement state-driven ContentDocumentPage (auto-save, publish, versions/diff, write-blocking), and add extensive tests.
UI & Auth Utilities
packages/studio/src/lib/request-auth.ts, packages/studio/src/lib/runtime-ui/components/ui/dialog.tsx, packages/studio/src/lib/remote-studio-app.test.ts
Add isStudioCookieAuth/isStudioTokenAuth type guards; add forceMount prop to DialogContent and adjust SSR/portal render; tests updated to include documentRoute and document-state assertions.
Studio Module Exports & Index
packages/studio/src/index.ts, packages/studio/src/lib/studio.ts
Export and re-export resolveStudioDocumentRouteSchemaCapability and StudioDocumentRouteSchemaCapability type.
Dev Scripts & Tests
packages/studio/package.json, packages/studio/src/lib/dev-runtime-watch.test.ts
Change dev script to use bun x --bun with relative tsconfig and watch path; tighten test assertions to expect explicit Bun invocation and ban packages/studio/ path segment.
Documentation
packages/studio/README.md
Add "Routed Document Editor" section describing documentRoute in mount context, schema-hash derivation, write-disabled fallback, and MVP scope/behavior.

Sequence Diagrams

sequenceDiagram
    participant UI as ContentDocumentPage
    participant API as DocumentRouteAPI
    participant Server as DocumentRoute Server
    participant Auth as AuthService

    UI->>API: loadDraft(documentId, locale)
    API->>Server: GET /api/v1/content/<id>?draft=true (x-mdcms-project/env/locale)
    Server-->>API: 200 ContentDocumentResponse
    API-->>UI: Draft data

    UI->>UI: User edits -> debounce auto-save
    UI->>API: updateDraft(documentId, payload)
    alt cookie auth
        API->>Auth: GET /api/v1/auth/session (credentials: include)
        Auth-->>API: CSRF token
        API->>Server: PUT /api/v1/content/<id>?draft=true (with x-mdcms-csrf-token, x-mdcms-schema-hash)
    else token auth
        API->>Server: PUT /api/v1/content/<id>?draft=true (with Authorization: Bearer <token>)
    end
    Server-->>API: Updated document
    API-->>UI: Persisted document
Loading
sequenceDiagram
    participant Loader as StudioLoader
    participant Config as LocalConfig
    participant Resolver as SchemaResolver
    participant Runtime as RemoteRuntime

    Loader->>Config: read authored config (project/environment)
    Loader->>Resolver: resolveStudioDocumentRouteSchemaCapability(config)
    Resolver-->>Loader: { canWrite: true, schemaHash } | { canWrite: false, message }
    Loader->>Runtime: mount remote runtime (mountContext includes documentRoute)
    Runtime-->>Loader: mounted
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Poem

🐰 I nibble on hashes, soft and bright,
Drafts take flight under moonlit byte.
Versions whisper what changed and why,
Publish a carrot, diff wings fly.
Hooray for routes that guide the night!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 1.92% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(studio): wire editor draft and publish flows' clearly and concisely summarizes the main change: implementing draft and publish functionality for the Studio editor, which aligns with the substantial additions of document-route API, document versioning/diffing, and page state management.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/cms-56-cms-133-editor-publish

Comment @coderabbitai help to get the list of available commands and usage tips.

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@iipanda
Copy link
Copy Markdown
Collaborator Author

iipanda commented Mar 30, 2026

@codex review

Copy link
Copy Markdown

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

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: fdf0648ee2

ℹ️ 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/studio/src/lib/runtime-ui/pages/content-document-page.tsx
Comment thread packages/studio/src/lib/runtime-ui/pages/content-document-page.tsx Outdated
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@iipanda
Copy link
Copy Markdown
Collaborator Author

iipanda commented Mar 31, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@iipanda
Copy link
Copy Markdown
Collaborator Author

iipanda commented Mar 31, 2026

@coderabbitai

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 31, 2026

@iipanda Sure! I'll go ahead and review this PR now.

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
packages/studio/src/lib/runtime-ui/components/ui/dialog.tsx (1)

92-92: Remove redundant data-slot at Line 92.

DialogPortal already sets data-slot="dialog-portal" internally, so passing it again is unnecessary.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/studio/src/lib/runtime-ui/components/ui/dialog.tsx` at line 92,
Remove the redundant data-slot prop from the DialogPortal usage in
components/ui/dialog.tsx: locate the JSX element DialogPortal (the line with
<DialogPortal data-slot="dialog-portal" forceMount={forceMount}>) and delete the
data-slot="dialog-portal" attribute so DialogPortal relies on its internal
data-slot; keep the forceMount prop as-is.
packages/studio/src/lib/runtime-ui/pages/content-document-page.tsx (1)

1-1: The @ts-nocheck directive disables type safety for this entire file.

This file implements complex state management and API orchestration where type checking would catch many potential issues. Consider removing the directive and resolving the underlying type errors, or document why it's necessary (e.g., incompatible third-party types, work-in-progress).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/studio/src/lib/runtime-ui/pages/content-document-page.tsx` at line
1, Remove the top-level "// `@ts-nocheck`" and fix the real typing issues in this
file instead of disabling checking: add proper TypeScript types for the React
component export (ContentDocumentPage), its props/state, and for any API helpers
such as loadDocument/updateDocument/fetchDocument (or similarly named functions
and hooks used inside the component), annotate responses and event handlers, and
update useEffect/useState generics to eliminate errors; if a narrow suppression
is absolutely required, replace the file-level directive with targeted //
`@ts-ignore` or typed any casts on the specific problematic lines and add a brief
comment explaining why (e.g., third-party type mismatch) so type-checking
remains enabled for the rest of the file.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/studio/src/lib/runtime-ui/components/ui/dialog.tsx`:
- Around line 82-94: Remove the unnecessary SSR check that tests typeof document
=== "undefined" and always render the portal branch; specifically delete the
conditional block and ensure the component unconditionally returns the
DialogPortal element containing <DialogOverlay forceMount={forceMount} /> and
{content} (keep existing props like forceMount and data-slot). This removes dead
code in the client component while preserving DialogPortal, DialogOverlay,
forceMount and content usage.

---

Nitpick comments:
In `@packages/studio/src/lib/runtime-ui/components/ui/dialog.tsx`:
- Line 92: Remove the redundant data-slot prop from the DialogPortal usage in
components/ui/dialog.tsx: locate the JSX element DialogPortal (the line with
<DialogPortal data-slot="dialog-portal" forceMount={forceMount}>) and delete the
data-slot="dialog-portal" attribute so DialogPortal relies on its internal
data-slot; keep the forceMount prop as-is.

In `@packages/studio/src/lib/runtime-ui/pages/content-document-page.tsx`:
- Line 1: Remove the top-level "// `@ts-nocheck`" and fix the real typing issues
in this file instead of disabling checking: add proper TypeScript types for the
React component export (ContentDocumentPage), its props/state, and for any API
helpers such as loadDocument/updateDocument/fetchDocument (or similarly named
functions and hooks used inside the component), annotate responses and event
handlers, and update useEffect/useState generics to eliminate errors; if a
narrow suppression is absolutely required, replace the file-level directive with
targeted // `@ts-ignore` or typed any casts on the specific problematic lines and
add a brief comment explaining why (e.g., third-party type mismatch) so
type-checking remains enabled for the rest of the file.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2de36815-1bb7-4604-af14-5fa22c45130e

📥 Commits

Reviewing files that changed from the base of the PR and between 2e4cea1 and 8117d7b.

📒 Files selected for processing (23)
  • .gitignore
  • packages/shared/src/lib/contracts/extensibility.test.ts
  • packages/shared/src/lib/contracts/extensibility.ts
  • packages/studio/README.md
  • packages/studio/package.json
  • packages/studio/src/index.ts
  • packages/studio/src/lib/dev-runtime-watch.test.ts
  • packages/studio/src/lib/document-route-api.test.ts
  • packages/studio/src/lib/document-route-api.ts
  • packages/studio/src/lib/document-route-schema.test.ts
  • packages/studio/src/lib/document-route-schema.ts
  • packages/studio/src/lib/document-shell.ts
  • packages/studio/src/lib/document-version-diff.test.ts
  • packages/studio/src/lib/document-version-diff.ts
  • packages/studio/src/lib/remote-studio-app.test.ts
  • packages/studio/src/lib/request-auth.ts
  • packages/studio/src/lib/runtime-ui/components/ui/dialog.tsx
  • packages/studio/src/lib/runtime-ui/pages/content-document-page.test.tsx
  • packages/studio/src/lib/runtime-ui/pages/content-document-page.tsx
  • packages/studio/src/lib/studio-loader.test.ts
  • packages/studio/src/lib/studio-loader.ts
  • packages/studio/src/lib/studio.test.ts
  • packages/studio/src/lib/studio.ts

Comment thread packages/studio/src/lib/runtime-ui/components/ui/dialog.tsx
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@iipanda iipanda merged commit fdee02d into main Mar 31, 2026
4 of 6 checks passed
@iipanda iipanda deleted the codex/cms-56-cms-133-editor-publish branch April 6, 2026 01:22
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