Skip to content

feat(mothership): draft persistence, new task eager creation, doc preview fix, and loading polish#4361

Merged
waleedlatif1 merged 12 commits intostagingfrom
fix/loading
Apr 30, 2026
Merged

feat(mothership): draft persistence, new task eager creation, doc preview fix, and loading polish#4361
waleedlatif1 merged 12 commits intostagingfrom
fix/loading

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • Add useMothershipDraftsStore with persist middleware — saves and restores draft text, file attachments, and contexts per chat scope key across sessions; cleared on workspace reset
  • Add useCreateTask mutation that eagerly creates a new chat via POST /api/mothership/chats, optimistically prepends it to the sidebar, and navigates directly to /workspace/:id/task/:newId — removes the id:'new' placeholder pattern entirely
  • Fix docx/pptx/pdf preview errors during agent writes — remove !isDocFormat guards in file-preview-adapter so preview sessions are created and streaming content is passed to DocxPreview/PptxPreview, which suppresses intermediate compilation errors and shows the skeleton instead
  • Replace Loader2 from lucide-react with Loader from emcn across auth, chat, knowledge, logs, deploy, and tool-input; add Clipboard icon to emcn barrel
  • Add EditorContextMenu to the Monaco file viewer
  • Expand Monaco SIM_DARK and SIM_LIGHT token rules with string.link, delimiter, tag, attribute.name, attribute.value, and Markdown-specific tokens (strong, emphasis, variable, meta.separator)

Type of Change

  • New feature
  • Bug fix
  • Improvement

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 30, 2026

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Apr 30, 2026 8:38pm

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 30, 2026

PR Summary

Medium Risk
Medium risk due to new persisted draft state and optimistic task-creation/navigation changes, plus adjusted file preview handling that affects streamed editing for more file types.

Overview
Adds persisted mothership draft support via useMothershipDraftsStore, restoring/saving input text plus selected contexts and attachments per draftScopeKey, clearing drafts on submit and on global store reset.

Changes “New task” to eagerly create a real task/chat (useCreateTask + sidebar wiring) with an optimistic list prepend and direct navigation to the new /task/:id, removing the previous placeholder-task behavior.

Improves workspace file UX by adding a custom Monaco editor context menu (cut/copy/paste/select-all/find) and tweaking Monaco theming/token rules and editor options; also tweaks file preview streaming to generate previews for doc formats during content edits.

Replaces widespread lucide-react Loader2 spinners with the shared emcn Loader component (and adds an emcn Clipboard icon), plus minor loading UI polish (e.g., files page loading state).

Reviewed by Cursor Bugbot for commit 45c965d. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 30, 2026

Greptile Summary

This PR introduces draft persistence for mothership chat inputs (useMothershipDraftsStore with Zustand persist), replaces the id:'new' sidebar placeholder with an eager useCreateTask mutation that navigates directly to the new task, fixes doc-format preview errors by removing !isDocFormat guards in file-preview-adapter, adds an EditorContextMenu to the Monaco file viewer, and swaps Loader2 for the emcn Loader component across ~30 files. The implementation is well-structured: the isFirstSaveRef guard correctly prevents a first-render wipe of file-only drafts, and the isCreatingTaskRef + disabled button combination handles double-invocation of task creation.

Confidence Score: 5/5

Safe to merge — no P0/P1 issues found; all substantive concerns are P2 style notes.

Changes span draft persistence, eager task creation, a doc-preview fix, icon replacements, and editor enhancements. All patterns are consistent with the existing codebase. The only flagged items are an undocumented intentional ref-over-dep pattern and a potential future memoisation concern — neither affects correctness today.

No files require special attention; the two P2 comments in user-input.tsx and mothership-chat.tsx are the only items worth a second look.

Important Files Changed

Filename Overview
apps/sim/stores/mothership-drafts/store.ts New Zustand store with persist middleware for per-scope draft text, files, and contexts; correctly handles isEmpty, partial-state persistence, and workspace reset.
apps/sim/hooks/queries/tasks.ts Adds useCreateTask mutation with optimistic sidebar prepend (correct TaskMetadata shape including Date for updatedAt) followed by query invalidation in onSettled.
apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx Draft persistence via draftScopeKey prop; mount-only restore effect, isFirstSaveRef guard prevents wipe on first render — solid, but draftScopeKey dep intentionally absent from save effect using ref pattern without a comment.
apps/sim/app/workspace/[workspaceId]/w/components/sidebar/sidebar.tsx Replaces id:'new' placeholder pattern with useCreateTask mutation, adds isCreatingTaskRef guard and disabled state on Plus button; all id !== 'new' guards correctly removed.
apps/sim/lib/copilot/request/go/file-preview-adapter.ts Removes two !isDocFormat guards so docx/pptx/pdf files get preview sessions and streaming content during agent writes; DocxPreview/PptxPreview handles intermediate content gracefully.
apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/text-editor.tsx Adds EditorContextMenu integration with proper disposable cleanup, expands SIM_DARK/SIM_LIGHT token rules, and refines Monaco editor options.
apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/editor-context-menu.tsx New context menu component using emcn DropdownMenu; Cut/Paste correctly gated behind canEdit, uses fixed-position 1px trigger div pattern.
apps/sim/app/workspace/[workspaceId]/files/files.tsx Loading skeleton replaced with centered Loader spinner, skeleton-only shown when isLoading is true, useEffect deps fixed.
apps/sim/app/workspace/[workspaceId]/home/home.tsx Computes draftScopeKey and threads it to both UserInput instances; straightforward wiring.

Sequence Diagram

sequenceDiagram
    participant U as User
    participant SB as Sidebar
    participant API as POST /api/mothership/chats
    participant QC as QueryClient
    participant Router as Router
    participant DS as MothershipDraftsStore

    U->>SB: Click "New task" (Plus button)
    SB->>SB: isCreatingTaskRef = true, button disabled
    SB->>API: mutateAsync()
    API-->>SB: { id: newTaskId }
    SB->>QC: setQueryData (optimistic prepend)
    SB->>DS: clearDraft(workspaceId + ':new')
    SB->>Router: navigate /workspace/:id/task/:newTaskId
    SB->>QC: invalidateQueries (onSettled)
    QC-->>SB: re-fetch task list
    SB->>SB: isCreatingTaskRef = false

    Note over U,DS: Draft Persistence Flow
    U->>SB: Types draft on home view
    SB->>DS: setDraft(workspaceId:new, payload)
    U->>Router: Navigates away without submitting
    Router-->>SB: Returns to home
    DS-->>SB: Restores draft on UserInput mount
Loading

Reviews (4): Last reviewed commit: "revert(database-tools): restore mongo us..." | Re-trigger Greptile

Comment thread apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/text-editor.tsx Outdated
Comment thread apps/sim/app/workspace/[workspaceId]/home/home.tsx
@gitguardian
Copy link
Copy Markdown

gitguardian Bot commented Apr 30, 2026

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them.
While these secrets were previously flagged, we no longer have a reference to the
specific commits where they were detected. Once a secret has been leaked into a git
repository, you should consider it compromised, even if it was deleted immediately.
Find here more information about risks.


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

…view fix, and loading polish

- Add `useMothershipDraftsStore` (persist) to save and restore draft text, file
  attachments, and contexts per chat scope key; cleared on workspace reset
- Add `useCreateTask` mutation that eagerly POSTs a new chat, optimistically
  prepends it to the sidebar task list, and navigates to `/task/:id` — removes
  the `id:'new'` placeholder pattern entirely
- Fix docx/pptx/pdf preview: remove `!isDocFormat` guards in
  `file-preview-adapter` so preview sessions are created and streaming content
  is set during agent writes, suppressing intermediate compilation errors
- Replace `Loader2` (lucide) with `Loader` (emcn) across auth, chat, knowledge,
  logs, deploy, and tool-input components; add `Clipboard` icon to emcn
- Add `EditorContextMenu` to the Monaco file viewer
- Expand Monaco `SIM_DARK` and `SIM_LIGHT` token rules with string.link,
  delimiter, tag, attribute, and Markdown tokens (strong, emphasis, variable)
…ange

Prevents stale ref when defaultValue transitions through empty — if
defaultValue goes non-empty → empty → same non-empty value, the ref
was not updated on the empty transition, causing setValue to be skipped
on the subsequent change.

Also removes unnecessary useCallback wrapping from handleSendQueuedHead,
handleEditQueued, handleEditQueuedTail in MothershipChat — none have a
reference observer (UserInput stores them via refs, QueuedMessages is
not React.memo-wrapped).
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

…ile-only drafts

On mount the save effect fired before the restore effect's setState calls
propagated, so fileAttachments and contexts were still empty. For a draft
with files but no text this caused isEmpty() to return true and setDraft to
delete the entry. Added isFirstSaveRef to skip the initial run; the restore
triggers a re-render that fires the save with the full, correct payload.
…th validation

- files.tsx: gate loading skeleton on isLoading so navigating to a missing
  file ID doesn't permanently show the skeleton after load completes
- database-tools.ts: remove refine() pairing username+password on mongo
  connection schema so either field can be provided independently
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/lib/api/contracts/database-tools.ts Outdated
Comment thread apps/sim/lib/api/contracts/database-tools.ts Outdated
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 45c965d. Configure here.

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