feat: add Monaco Editor for in-browser code editing#30253
Open
LAOXI-OPS wants to merge 2 commits into
Open
Conversation
Add Monaco Editor as an overlay to the existing Pierre read-only code viewer, enabling direct code editing from the web UI with Ctrl+S save. Changes: - Add PUT /file/content API endpoint for writing files - Add File.write() method to the file service - Add SDK file.write() client method - Create MonacoEditor SolidJS wrapper component with: - Syntax highlighting for 80+ languages - Ctrl+S / Cmd+S save shortcut - Dark/light theme sync - Bracket pair colorization - Add Edit button to file viewer that opens Monaco overlay - Wire save through file context to backend API Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR adds an in-app Monaco-based editor to allow editing and saving file contents from the UI, backed by a new server file.write HTTP API and SDK method.
Changes:
- Added Monaco editor component + language detection utility for syntax highlighting.
- Extended text file viewer to open an edit overlay and persist changes via
file.write. - Implemented server-side write handler + OpenAPI endpoint and generated JS SDK method.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/ui/src/utils/language-map.ts | Adds file extension/name → Monaco language mapping utility. |
| packages/ui/src/components/monaco-editor.tsx | Introduces Monaco editor component with worker wiring and theming. |
| packages/ui/src/components/file.tsx | Adds “Edit” overlay and save wiring for text files. |
| packages/ui/package.json | Adds monaco-editor dependency for UI package. |
| packages/sdk/js/src/v2/gen/sdk.gen.ts | Adds generated file.write SDK method. |
| packages/opencode/src/server/routes/instance/httpapi/handlers/file.ts | Implements write handler and publishes related events. |
| packages/opencode/src/server/routes/instance/httpapi/groups/file.ts | Defines PUT /file/content endpoint schema and OpenAPI metadata. |
| packages/opencode/src/file/index.ts | Adds File.Service.write implementation with path-escape protection. |
| packages/app/vite.js | Adds worker output naming + monaco-editor optimizeDeps include. |
| packages/app/src/pages/session/file-tabs.tsx | Passes filePath + onSave handler into text viewer. |
| packages/app/src/context/file.tsx | Adds save() that calls SDK write then reloads content. |
| packages/app/package.json | Adds monaco-editor dependency for app package. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+120
to
+123
| HttpApiEndpoint.put("write", "/file/content", { | ||
| payload: FileWriteBody, | ||
| success: described(Schema.Struct({ success: Schema.Boolean }), "Write result"), | ||
| }).annotateMerge( |
Comment on lines
+1633
to
+1639
| public write<ThrowOnError extends boolean = false>( | ||
| parameters: { | ||
| directory?: string | ||
| workspace?: string | ||
| path: string | ||
| content: string | ||
| }, |
Comment on lines
+11
to
+17
| getWorker(_: string, label: string) { | ||
| if (label === "json") return new jsonWorker() | ||
| if (label === "css" || label === "scss" || label === "less") return new cssWorker() | ||
| if (label === "html" || label === "handlebars" || label === "razor") return new htmlWorker() | ||
| if (label === "typescript" || label === "javascript") return new tsWorker() | ||
| return new editorWorker() | ||
| }, |
Comment on lines
+9
to
+10
| // @ts-ignore | ||
| self.MonacoEnvironment = { |
Comment on lines
+31
to
+32
| r: "r", | ||
| R: "r", |
| htm: "html", | ||
| css: "css", | ||
| scss: "scss", | ||
| sass: "scss", |
Comment on lines
+950
to
+968
| {editing() && props.filePath && props.onSave && ( | ||
| <div | ||
| style={{ | ||
| position: "absolute", | ||
| inset: "0", | ||
| "z-index": "20", | ||
| background: "var(--background-base)", | ||
| }} | ||
| > | ||
| <MonacoEditor | ||
| filePath={props.filePath} | ||
| content={editContent()} | ||
| onSave={(content) => { | ||
| props.onSave!(content) | ||
| setEditing(false) | ||
| }} | ||
| /> | ||
| </div> | ||
| )} |
- Add WorkspaceRoutingQueryFields to write endpoint - Fix worker routing for typescriptreact/javascriptreact - Add SSR guard for self.MonacoEnvironment - Lazy-load Monaco workers via dynamic imports - Fix language map: remove unreachable R key, fix sass mapping - Add Close button and ESC handler to Monaco edit overlay Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #30205
Type of change
What does this PR do?
This PR adds Monaco Editor to the OpenCode web UI, enabling direct code editing from the browser.
Problem: The web UI only displays code via the read-only Pierre renderer. Users cannot edit files directly - they must ask the agent to make changes.
Solution: Add Monaco Editor as an overlay that appears when the user clicks an Edit button. The Pierre viewer remains for read-only viewing, so Monaco loading failures do not break existing functionality.
Changes:
How did you verify your code works?
Screenshots / recordings
N/A - backend + frontend change, tested locally
Checklist