Skip to content

Feat/clean code#67

Closed
will-lp1 wants to merge 5 commits intomainfrom
feat/clean-code
Closed

Feat/clean code#67
will-lp1 wants to merge 5 commits intomainfrom
feat/clean-code

Conversation

@will-lp1
Copy link
Copy Markdown
Owner

@will-lp1 will-lp1 commented Aug 21, 2025

Summary by CodeRabbit

  • New Features

    • Emoji autocomplete and synonym overlay in the editor.
    • Document actions bar: preview changes, navigate versions, copy content, and saving indicator.
    • Unified document workspace with consistent chat/document context.
  • UX Improvements

    • Header and hero buttons now show “Open” when signed in, “Begin” otherwise.
    • Suggestion overlays enabled across document pages.
    • Sign-out now returns to the home page.
    • Authenticated users are no longer redirected away from the home page.
  • Refactor

    • Migrated to a document-centric model for simpler editing and streaming workflows.

…eneral improvements

Streamline document handling and remove unused context

- Removed the `use-document-context` and `use-document-utils` hooks to simplify document management.
- Introduced a unified `use-document` hook to handle document state and actions.
- Updated various components to utilize the new `use-document` hook, ensuring consistent document state management.
- Adjusted document creation and update logic to eliminate reliance on artifact kinds, setting kind to 'text' by default.
- Enhanced synonym overlay functionality in the editor, with its own react component
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Aug 21, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Replaces artifact-centric architecture with a document-centric model across UI, hooks, streaming, and DB. Adds emoji and synonym overlays to the editor. Simplifies AI toolchains to text-only creation/update. Removes artifact components/hooks, updates prompts and queries, adjusts layouts/providers, and consolidates navigation and middleware rules.

Changes

Cohort / File(s) Summary of changes
Architecture: Artifact → Document refactor
apps/snow-leopard/components/artifact.tsx, .../components/artifact-actions.tsx, .../components/toolbar.tsx, .../artifacts/text/*, apps/snow-leopard/hooks/use-artifact.ts, .../hooks/use-document-context.tsx, apps/snow-leopard/lib/artifacts/server.ts
Removed artifact framework (definitions, UI, actions, toolbar, hooks, server handlers). Migrated to document model; artifact kinds removed.
Document workspace and actions
apps/snow-leopard/components/document/document-workspace.tsx, .../components/document/actions.tsx, .../components/document/version-header.tsx, .../components/document/skeleton.tsx, .../components/document/document-tool.tsx
Introduced document-centric workspace, inline rename/create flows, new DocumentActions bar, updated version restore and tool call/result to document model; removed kind usage.
Document state hook
apps/snow-leopard/hooks/use-document.ts
Added CurrentDocument and initialDocument; SWR-based useDocument hook replacing useDocumentUtils; exposes document/setDocument and CRUD/chat helpers; added createDocument.
Streaming and data flow
apps/snow-leopard/components/data-stream-handler.tsx, apps/snow-leopard/lib/ai/document-helpers.ts, .../lib/ai/tools/document-streaming.ts
Switched to document-based streaming; new documentUpdate delta; added helpers createTextDocument/updateTextDocument; simplified streaming to text-only creation.
AI tools and prompts
apps/snow-leopard/lib/ai/tools/create-document.ts, .../lib/ai/tools/update-document.ts, .../lib/ai/prompts.ts
Dropped kind parameter/metadata; default to text; updated prompt signature to accept null
DB queries
apps/snow-leopard/lib/db/queries.ts
Made kind optional (string
Editor: schema, plugins, serialization
apps/snow-leopard/lib/editor/basic-schema.ts, .../lib/editor/config.ts, .../lib/editor/editor-plugins.ts, .../lib/editor/functions.tsx, .../lib/editor/emoji-plugin.ts, .../lib/editor/synonym-plugin.ts, apps/snow-leopard/components/document/editor.tsx, .../components/synonym-overlay.tsx, .../components/emoji-overlay.tsx
Extracted schema with diff mark; re-exported config; added emoji plugin and overlay; refactored synonym plugin to event-driven overlays; integrated SynonymOverlay in editor; replaced HTML parsing with Markdown-it parser/serializer.
Chat components
apps/snow-leopard/components/chat/chat.tsx, .../chat/chat-header.tsx, .../chat/message.tsx, .../chat/messages.tsx, .../chat/multimodal-input.tsx
Migrated to useDocument hook and document object shape; updated tool import paths; cleaned unused imports.
Layouts and pages
apps/snow-leopard/app/documents/layout.tsx, .../app/layout.tsx, .../app/page.tsx, .../app/documents/page.tsx, .../app/documents/[id]/page.tsx
Moved SuggestionOverlayProvider from app root to documents layout; updated CTA buttons to onClick-based navigation; updated workspace imports.
Sidebar
apps/snow-leopard/components/sidebar/sidebar-documents.tsx, .../sidebar/sidebar-user-nav.tsx
Switched to useDocument for selection/create/delete; removed kind from optimistic updates; sign-out now redirects to '/'.
Suggestion overlay provider
apps/snow-leopard/components/suggestion-overlay-provider.tsx
Rewired to useDocument; event payloads now use documentId; guarded on init id.
Middleware and auth
apps/snow-leopard/middleware.ts, .../lib/auth.ts
Stopped redirecting '/' for authed users; unified Stripe env gating via stripeEnabled with clearer errors.
Types
apps/snow-leopard/types/document.ts, .../types/metadata.ts
Renamed ArtifactContent→DocumentContent; added UIDocument; ArtifactMetadata→DocumentMetadata.
API actions
apps/snow-leopard/app/api/document/actions/create.ts, .../app/documents/actions.ts
Removed ArtifactKind assertions; update flow now saves kind as null; create uses kind directly.
Dependencies
apps/snow-leopard/package.json, /package.json
Added editor/markdown/emoji deps; reorganized dependencies; no runtime code changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant UI as DocumentWorkspace
  participant Editor as Editor
  participant Hook as useDocument
  participant API as /api/document
  participant Stream as DataStreamHandler

  UI->>Hook: setDocument({id,title,content}) on create/rename
  UI->>API: POST/PUT /api/document (id,title,content)
  API-->>UI: 200 OK (id,title,content)
  UI->>Stream: start streaming (new doc)
  Stream-->>Editor: editor:stream-text (text-delta)
  Stream-->>UI: editor:creation-stream-finished (finish)
  UI->>Hook: setDocument(status='idle')
Loading
sequenceDiagram
  autonumber
  participant User
  participant Editor
  participant Emo as emojiPlugin
  participant Overlay as EmojiOverlay

  User->>Editor: Type ":" + query
  Editor->>Emo: keymap/transaction
  Emo->>Overlay: open(position, suggestions)
  User->>Overlay: Navigate/select emoji
  Overlay-->>Emo: insertEmojiSuggestion(code)
  Emo->>Editor: replace text with emoji
  Emo->>Overlay: close
Loading
sequenceDiagram
  autonumber
  participant User
  participant Editor
  participant Syn as synonym-plugin
  participant UI as SynonymOverlay (component)

  User->>Editor: Hover/select word
  Editor->>Syn: fetch synonyms
  Syn-->>UI: dispatch "synonym-overlay:open" (pos, list, range)
  User->>UI: Click synonym
  UI->>Editor: replace range with synonym
  UI-->>Syn: dispatch "synonym-overlay:close"
Loading
sequenceDiagram
  autonumber
  participant Actions as DocumentActions
  participant Win as window
  participant Editor as Editor

  Actions->>Win: preview-document-update {documentId,newContent}
  Note over Editor: Show diff view
  Actions->>Win: cancel-document-update {documentId}
  Note over Editor: Hide diff view
Loading

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Possibly related PRs

Poem

A hare with a pen and a grin so wide,
Hopped from artifacts to documents’ side.
Emojis now sparkle, synonyms glide, ✨
Streams hum softly, edits align the tide.
Schemas compose, toasts pop with pride—
Another neat burrow for users to reside. 🐇📄

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 0bb2471 and fa43b8e.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (53)
  • apps/snow-leopard/app/api/document/actions/create.ts (1 hunks)
  • apps/snow-leopard/app/documents/[id]/page.tsx (1 hunks)
  • apps/snow-leopard/app/documents/actions.ts (1 hunks)
  • apps/snow-leopard/app/documents/layout.tsx (3 hunks)
  • apps/snow-leopard/app/documents/page.tsx (1 hunks)
  • apps/snow-leopard/app/layout.tsx (1 hunks)
  • apps/snow-leopard/app/page.tsx (2 hunks)
  • apps/snow-leopard/artifacts/text/client.tsx (0 hunks)
  • apps/snow-leopard/artifacts/text/server.ts (0 hunks)
  • apps/snow-leopard/components/artifact-actions.tsx (0 hunks)
  • apps/snow-leopard/components/artifact.tsx (0 hunks)
  • apps/snow-leopard/components/chat/chat-header.tsx (2 hunks)
  • apps/snow-leopard/components/chat/chat.tsx (5 hunks)
  • apps/snow-leopard/components/chat/message.tsx (1 hunks)
  • apps/snow-leopard/components/chat/messages.tsx (1 hunks)
  • apps/snow-leopard/components/chat/multimodal-input.tsx (4 hunks)
  • apps/snow-leopard/components/create-artifact.tsx (0 hunks)
  • apps/snow-leopard/components/data-stream-handler.tsx (4 hunks)
  • apps/snow-leopard/components/document/actions.tsx (1 hunks)
  • apps/snow-leopard/components/document/document-tool.tsx (5 hunks)
  • apps/snow-leopard/components/document/document-workspace.tsx (10 hunks)
  • apps/snow-leopard/components/document/editor.tsx (4 hunks)
  • apps/snow-leopard/components/document/skeleton.tsx (0 hunks)
  • apps/snow-leopard/components/document/version-header.tsx (6 hunks)
  • apps/snow-leopard/components/emoji-overlay.tsx (1 hunks)
  • apps/snow-leopard/components/highlight-blog-tool.tsx (0 hunks)
  • apps/snow-leopard/components/sidebar/sidebar-documents.tsx (4 hunks)
  • apps/snow-leopard/components/sidebar/sidebar-user-nav.tsx (1 hunks)
  • apps/snow-leopard/components/suggestion-overlay-provider.tsx (6 hunks)
  • apps/snow-leopard/components/synonym-overlay.tsx (1 hunks)
  • apps/snow-leopard/components/toolbar.tsx (0 hunks)
  • apps/snow-leopard/hooks/use-artifact.ts (0 hunks)
  • apps/snow-leopard/hooks/use-document-context.tsx (0 hunks)
  • apps/snow-leopard/hooks/use-document.ts (13 hunks)
  • apps/snow-leopard/lib/ai/document-helpers.ts (1 hunks)
  • apps/snow-leopard/lib/ai/prompts.ts (1 hunks)
  • apps/snow-leopard/lib/ai/tools/create-document.ts (1 hunks)
  • apps/snow-leopard/lib/ai/tools/document-streaming.ts (1 hunks)
  • apps/snow-leopard/lib/ai/tools/update-document.ts (0 hunks)
  • apps/snow-leopard/lib/artifacts/server.ts (0 hunks)
  • apps/snow-leopard/lib/auth.ts (2 hunks)
  • apps/snow-leopard/lib/db/queries.ts (3 hunks)
  • apps/snow-leopard/lib/editor/basic-schema.ts (1 hunks)
  • apps/snow-leopard/lib/editor/config.ts (1 hunks)
  • apps/snow-leopard/lib/editor/editor-plugins.ts (2 hunks)
  • apps/snow-leopard/lib/editor/emoji-plugin.ts (1 hunks)
  • apps/snow-leopard/lib/editor/functions.tsx (1 hunks)
  • apps/snow-leopard/lib/editor/synonym-plugin.ts (3 hunks)
  • apps/snow-leopard/middleware.ts (1 hunks)
  • apps/snow-leopard/package.json (4 hunks)
  • apps/snow-leopard/types/document.ts (2 hunks)
  • apps/snow-leopard/types/metadata.ts (1 hunks)
  • package.json (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/clean-code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@will-lp1 will-lp1 closed this Aug 21, 2025
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