mbeditor 0.11.0 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +193 -0
- data/README.md +190 -3
- data/app/assets/javascripts/mbeditor/application.js +5 -0
- data/app/assets/javascripts/mbeditor/application_iife_tail.js +6 -0
- data/app/assets/javascripts/mbeditor/collaboration_identity.js +234 -0
- data/app/assets/javascripts/mbeditor/collaboration_service.js +690 -0
- data/app/assets/javascripts/mbeditor/components/EditorPanel.js +120 -19
- data/app/assets/javascripts/mbeditor/components/FileTree.js +127 -8
- data/app/assets/javascripts/mbeditor/components/GitPanel.js +12 -3
- data/app/assets/javascripts/mbeditor/components/ImportConflictModal.js +127 -0
- data/app/assets/javascripts/mbeditor/components/MbeditorApp.js +916 -72
- data/app/assets/javascripts/mbeditor/components/ModelGraph.js +934 -0
- data/app/assets/javascripts/mbeditor/components/ProblemsPanel.js +130 -10
- data/app/assets/javascripts/mbeditor/components/ShortcutHelp.js +1 -0
- data/app/assets/javascripts/mbeditor/components/TabBar.js +4 -2
- data/app/assets/javascripts/mbeditor/editor_plugins.js +517 -111
- data/app/assets/javascripts/mbeditor/file_import.js +146 -0
- data/app/assets/javascripts/mbeditor/file_service.js +52 -3
- data/app/assets/javascripts/mbeditor/tab_manager.js +50 -1
- data/app/assets/javascripts/mbeditor/websocket_service.js +89 -0
- data/app/assets/stylesheets/mbeditor/editor.css +365 -10
- data/app/channels/mbeditor/channel_authentication.rb +94 -0
- data/app/channels/mbeditor/collaboration_channel.rb +84 -0
- data/app/channels/mbeditor/editor_channel.rb +40 -1
- data/app/controllers/mbeditor/application_controller.rb +5 -1
- data/app/controllers/mbeditor/editors_controller.rb +492 -19
- data/app/controllers/mbeditor/git_controller.rb +9 -2
- data/app/services/mbeditor/availability_probe.rb +76 -17
- data/app/services/mbeditor/code_search_service.rb +23 -3
- data/app/services/mbeditor/collaboration_doc_store.rb +116 -0
- data/app/services/mbeditor/file_import_service.rb +103 -0
- data/app/services/mbeditor/git_combined_diff_service.rb +36 -5
- data/app/services/mbeditor/git_info_service.rb +6 -0
- data/app/services/mbeditor/git_service.rb +22 -6
- data/app/services/mbeditor/lsp_diagnostics_translator.rb +99 -5
- data/app/services/mbeditor/model_graph_service.rb +232 -0
- data/app/services/mbeditor/presence_registry.rb +83 -0
- data/app/services/mbeditor/ri_definition_service.rb +39 -5
- data/app/services/mbeditor/search_replace_service.rb +24 -4
- data/app/views/layouts/mbeditor/application.html.erb +2 -0
- data/lib/mbeditor/configuration.rb +37 -3
- data/lib/mbeditor/engine.rb +34 -0
- data/lib/mbeditor/exception_log.rb +84 -0
- data/lib/mbeditor/route_map.rb +5 -0
- data/lib/mbeditor/ruby_lsp_client.rb +28 -1
- data/lib/mbeditor/version.rb +1 -1
- data/lib/mbeditor.rb +1 -0
- data/vendor/assets/javascripts/yjs-collab.js +12 -0
- metadata +15 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b6645751ebceaf2b9754d5aabb417549334518db35027e1bd6c08d9fede2d7a5
|
|
4
|
+
data.tar.gz: edb2a8a2696f5aac16fcdcd4bbbf728f5d05a7af14ffca326a59ec7c0d40b860
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5f9d7559b69d80a1d8d9d094d5513a69048ce62ea385630ca59811e0dafd50ca65afa988e1f560cc32d78fc7b71dceedb78b30f1ba190e00b465d1026e3554d5
|
|
7
|
+
data.tar.gz: a8a3de31439ff3a937db30a04dbfd631694f50ccbcce4c3fb3571dfa66cd798cf8df29b45855467a9ff783a919893829472b241523d7230468944a3accad04f9
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,199 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.12.1] - 2026-08-03
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- **The collaboration name now comes from the signed-in user automatically.**
|
|
14
|
+
Previously it required a `user_name_callback`; with none set the editor fell
|
|
15
|
+
straight through to a generated name like "Witty Operator" even on an
|
|
16
|
+
authenticated instance. When no callback is configured, the name is now read
|
|
17
|
+
off `current_user`, trying `name`, `full_name`, `display_name`, `username`,
|
|
18
|
+
`login` and `email` in order. New `config.user_name_methods` names your own
|
|
19
|
+
column instead — `%w[preferred_name]` — so the common case no longer needs a
|
|
20
|
+
callback at all. An explicit `user_name_callback` still wins.
|
|
21
|
+
|
|
22
|
+
This works when your auth library exposes `current_user` to an
|
|
23
|
+
`ActionController::Base` subclass, which Devise and Sorcery do. A
|
|
24
|
+
`current_user` written by hand on your own `ApplicationController` is **not**
|
|
25
|
+
reachable — the engine's controllers do not inherit from it — so that case
|
|
26
|
+
still needs a callback reading `session` directly.
|
|
27
|
+
|
|
28
|
+
### Changed
|
|
29
|
+
- **The model graph is laid out by dependency, not by traversal order.** It now
|
|
30
|
+
uses the Sugiyama layered method — break cycles, layer by longest path, cut
|
|
31
|
+
crossings with the median heuristic, then straighten — which is what Graphviz
|
|
32
|
+
`dot`, and so Rails ERD, uses for this picture. The previous radial layout
|
|
33
|
+
became one enormous circle on a real schema, fitted so far out that no box was
|
|
34
|
+
legible. A model's position now tells you something: depth reads left to
|
|
35
|
+
right, and each connected part of the schema is drawn as its own area.
|
|
36
|
+
|
|
37
|
+
- **Your own presence chip only appears once someone else is connected.** Action
|
|
38
|
+
Cable is up in any normal dev setup, so it used to sit in the toolbar
|
|
39
|
+
permanently announcing a session of one.
|
|
40
|
+
|
|
41
|
+
### Fixed
|
|
42
|
+
- **The model graph was unusable on a large schema.** On 300 models and 513
|
|
43
|
+
associations a single zoom tick cost 27 ms; it is now 0.2 ms. Three causes,
|
|
44
|
+
all compounding: the entire layout ran on every render, the pan/zoom transform
|
|
45
|
+
sat in the render output so each tick rebuilt ~7,000 SVG elements, and the
|
|
46
|
+
wheel handler read `getBoundingClientRect()` per tick, forcing a synchronous
|
|
47
|
+
reflow of the whole scene.
|
|
48
|
+
- **Fit-to-pane produced a zoom the controls refused to honour.** It clamped to
|
|
49
|
+
`min(1, ...)` but not to the minimum zoom, so a large graph fitted at ~0.04
|
|
50
|
+
against a 0.2 floor — and the first scroll snapped up to the floor, a fivefold
|
|
51
|
+
jump anchored on the cursor that looked like the diagram leaping somewhere
|
|
52
|
+
random. The floor is now low enough to frame a few hundred models, and the fit
|
|
53
|
+
clamps to the same range the wheel enforces. Opening the tab also no longer
|
|
54
|
+
leaves the graph unfitted when the pane has not been sized yet.
|
|
55
|
+
- **Hovering a model now shows what its associations actually are** — macro,
|
|
56
|
+
name, direction and `through:` — and dims every unrelated edge, which is the
|
|
57
|
+
only way to follow one model's relationships among hundreds of lines.
|
|
58
|
+
- **Clicking a model zooms to it** instead of opening its schema; the schema is
|
|
59
|
+
an explicit button in the model's header, so navigating no longer throws a
|
|
60
|
+
modal at you.
|
|
61
|
+
- **The model-graph search field drew its text over a magnifier icon.** The icon
|
|
62
|
+
comes from the vendored Pico stylesheet, whose selector outranks a plain class
|
|
63
|
+
rule — disabling the browser's own `type="search"` decorations did not touch
|
|
64
|
+
it.
|
|
65
|
+
- **A failing `user_name_callback` was swallowed silently.** Any exception
|
|
66
|
+
returned a bare `nil`, which made a broken callback indistinguishable from an
|
|
67
|
+
unconfigured one: you got the generated name and no clue why. The usual cause
|
|
68
|
+
is a `NameError` on a `current_user` the engine cannot see. It is now logged
|
|
69
|
+
as `[mbeditor] user name lookup failed: ...` and still never breaks the
|
|
70
|
+
request.
|
|
71
|
+
|
|
72
|
+
## [0.12.0] - 2026-07-31
|
|
73
|
+
|
|
74
|
+
### Added
|
|
75
|
+
- **Realtime collaborative editing (pair programming).** When Action Cable is
|
|
76
|
+
available, two or more people can open the same file and edit it together —
|
|
77
|
+
content converges through a Yjs CRDT, with live remote carets, selections and
|
|
78
|
+
a coloured name label per participant. Undo is scoped to your own edits, so
|
|
79
|
+
Ctrl+Z can never revert your partner's work. Joining late is safe: the shared
|
|
80
|
+
document wins over the copy on disk, and one save on any side settles the file
|
|
81
|
+
for everyone.
|
|
82
|
+
|
|
83
|
+
Participants appear as chips in the toolbar. A solid dot means they are in the
|
|
84
|
+
file you are looking at, a hollow ring means they are elsewhere (with their
|
|
85
|
+
filename beside it, when the toolbar is showing labels). Hovering gives their
|
|
86
|
+
name, current file and measured cable latency; clicking follows them, so their
|
|
87
|
+
file and scroll position track yours. Past three participants the chips
|
|
88
|
+
collapse to colour dots so the toolbar cannot overflow. Colours are assigned
|
|
89
|
+
against the live roster rather than hashed from the name, so two people never
|
|
90
|
+
share one while a free colour exists.
|
|
91
|
+
|
|
92
|
+
Collaboration only activates once someone else is actually connected — on your
|
|
93
|
+
own, the editor behaves exactly as before, keeping persistent undo history and
|
|
94
|
+
external-change detection.
|
|
95
|
+
|
|
96
|
+
**This is the one feature intended to be reached from another machine**, so it
|
|
97
|
+
is a deliberate exception to mbeditor's localhost-only posture. Read the
|
|
98
|
+
[Collaborative pairing](README.md#collaborative-pairing-optional) section
|
|
99
|
+
before exposing it: put it behind a trusted tunnel, set `authenticate_with`
|
|
100
|
+
(now also evaluated on the WebSocket handshake, fail-closed), restrict
|
|
101
|
+
`action_cable.allowed_request_origins`, and run a single web process. New
|
|
102
|
+
`user_name_callback` config resolves the display name from your host app.
|
|
103
|
+
|
|
104
|
+
- **Drag files and folders from your desktop straight into the explorer.**
|
|
105
|
+
Drop onto a folder row to import there, or onto the empty space below the
|
|
106
|
+
tree to import into the workspace root. Folders are imported recursively.
|
|
107
|
+
Any file type works — binary content round-trips byte for byte. When a
|
|
108
|
+
target path already exists, a dialog offers Overwrite all, Keep both (which
|
|
109
|
+
writes `name 2.ext` beside the original), or Skip. Imports are capped at 100
|
|
110
|
+
files and 50 MB per drop, and 5 MB per file, and every target path goes
|
|
111
|
+
through the same sandbox checks as every other file operation.
|
|
112
|
+
|
|
113
|
+
- **A model graph — an entity diagram of the host app's ActiveRecord models.**
|
|
114
|
+
The activity-bar button opens it as a full-width editor tab, drawing each
|
|
115
|
+
model with its fields. Search centres the view on a model; hovering an edge
|
|
116
|
+
names the relation. (Released with a radial layout; replaced by a layered one
|
|
117
|
+
in the next version — see Unreleased.)
|
|
118
|
+
|
|
119
|
+
Associations are read by **reflection, not by parsing model files**. mbeditor
|
|
120
|
+
runs inside the host app, so `reflect_on_all_associations` is right there and
|
|
121
|
+
resolves `class_name:`, `through:`, polymorphic and inverse sides correctly —
|
|
122
|
+
all of which regex or AST parsing of `has_many` lines silently gets wrong.
|
|
123
|
+
The graph never touches the database connection, so it works against a
|
|
124
|
+
database that isn't running or migrated. It is built only when the tab is
|
|
125
|
+
opened (it eager-loads the host app) and cached on a fingerprint of
|
|
126
|
+
`app/models` and `db/migrate`, so saving a model invalidates it. It also
|
|
127
|
+
writes `tmp/mbeditor_model_graph.mmd`, a Mermaid `erDiagram` that GitHub and
|
|
128
|
+
VS Code render natively.
|
|
129
|
+
|
|
130
|
+
- **Ruby navigation through real Monaco providers.** Go-to-definition was
|
|
131
|
+
hand-wired per editor with an `onMouseDown` and an `addAction`, so Monaco
|
|
132
|
+
never knew Ruby had definitions and peek-definition, Ctrl+hover previews and
|
|
133
|
+
the references widget all did nothing. Definition, references, document
|
|
134
|
+
symbols, folding, highlights, rename, formatting, signature help and
|
|
135
|
+
selection ranges are now registered providers, fed by a raw ruby-lsp
|
|
136
|
+
passthrough instead of a bespoke translator per method.
|
|
137
|
+
|
|
138
|
+
- **F2 renames a Ruby constant across the workspace.** Open files get their
|
|
139
|
+
edits back for Monaco to apply, so the change is undoable and marks the tab
|
|
140
|
+
dirty; closed files are written server-side. That split is what keeps
|
|
141
|
+
unsaved work safe — anything dirty is by definition open.
|
|
142
|
+
- **Shift+Alt+F and format-on-save now work for Ruby.**
|
|
143
|
+
- **RuboCop fixes apply straight from the diagnostic.** The edits are already
|
|
144
|
+
in the diagnostics response, so the lightbulb no longer makes a second
|
|
145
|
+
request or spawns a `rubocop -A` over the buffer on every click. "Disable
|
|
146
|
+
<cop> for this line" comes from the same payload.
|
|
147
|
+
- **Diagnostics are graded Error / Warning / Info / Hint** instead of
|
|
148
|
+
everything non-error being one yellow warning, and unnecessary code is
|
|
149
|
+
faded rather than squiggled. A status-bar chip shows ruby-lsp health.
|
|
150
|
+
|
|
151
|
+
- **Host-app exceptions appear in the Problems panel.** A failed request used to
|
|
152
|
+
show up only in the log. Controller exceptions are now listed with clickable
|
|
153
|
+
backtrace frames and pushed live over the existing cable channel. Backtraces
|
|
154
|
+
are filtered to frames under the workspace root and capped, since absolute
|
|
155
|
+
host paths are both a leak and unopenable. Development only, and
|
|
156
|
+
`config.exception_capture = false` disables it.
|
|
157
|
+
|
|
158
|
+
- **PageUp/PageDown cycle between the cursor and the last jump origin.**
|
|
159
|
+
Opening a file at a line — go-to-definition, a search result, a hover link —
|
|
160
|
+
snapshots where you came from, and PageUp/PageDown swap between the two.
|
|
161
|
+
Replaces the default page-scroll binding.
|
|
162
|
+
|
|
163
|
+
### Changed
|
|
164
|
+
- **Search is dramatically faster on host apps without ripgrep**, where it was
|
|
165
|
+
effectively unusable. Three separate causes, all on the `git grep` tier:
|
|
166
|
+
the exclusion list was computed and then never put on the command line, so
|
|
167
|
+
git walked `node_modules` in full and the results were discarded afterwards;
|
|
168
|
+
`search_respect_gitignore` defaulted to `false`, which asks git to search
|
|
169
|
+
every ignored tree the app has; and `LC_ALL=C` was set, measured neutral for
|
|
170
|
+
the default and 2.2× *slower* for regex. Measured 3714 files walked → 253.
|
|
171
|
+
`search_respect_gitignore` now defaults to `true`, matching VS Code and
|
|
172
|
+
ripgrep. `GET /workspace` reports `searchBackend` so the live tier is visible,
|
|
173
|
+
and `ripgrep_command` now resolves the usual install prefixes as well as
|
|
174
|
+
`PATH` — a server started from launchd, systemd or an IDE has a stripped
|
|
175
|
+
`PATH`, which silently dropped search to the 10–30× slower tier.
|
|
176
|
+
|
|
177
|
+
- **Assignments to undeclared variables are reported as errors.** `foo = 1`
|
|
178
|
+
with no declaration anywhere is an implicit global the host's Babel pipeline
|
|
179
|
+
rejects, so it keeps Error severity with an explanatory hint. Read-side
|
|
180
|
+
unknowns still downgrade to a warning, since those are usually host globals
|
|
181
|
+
the language service cannot see.
|
|
182
|
+
|
|
183
|
+
### Fixed
|
|
184
|
+
- **The bottom drawers covered the code instead of making room for it.** The
|
|
185
|
+
log and problems drawers were absolutely positioned, so they sat on top of
|
|
186
|
+
what you were reading. They are now ordinary flow siblings of the split
|
|
187
|
+
panes, so opening one shrinks the editor.
|
|
188
|
+
- **"Changes in Branch" showed nothing on a branch well ahead of the base.**
|
|
189
|
+
With no base branch resolved it fell back to diffing against the branch's
|
|
190
|
+
upstream — which for a feature branch is its own remote copy, reliably empty.
|
|
191
|
+
Every layer then degraded to empty rather than erroring, so it looked like
|
|
192
|
+
there were no changes.
|
|
193
|
+
- **The What's New tab was wiped by the session restore** when it opened on a
|
|
194
|
+
version change.
|
|
195
|
+
- **An idle editor no longer re-renders.** Polls that found nothing changed were
|
|
196
|
+
still writing fresh objects into state — the file tree every 10 s and the
|
|
197
|
+
ruby-lsp health chip every 10 s — each costing a full reconciliation of a
|
|
198
|
+
tree that had not changed. Verified by counting React renders over an idle
|
|
199
|
+
minute: now zero.
|
|
200
|
+
|
|
8
201
|
## [0.11.0] - 2026-07-29
|
|
9
202
|
|
|
10
203
|
### Added
|
data/README.md
CHANGED
|
@@ -25,6 +25,14 @@ Mbeditor exposes read and write access to your Rails application directory over
|
|
|
25
25
|
- Always keep it in the development group in your Gemfile.
|
|
26
26
|
- The engine enforces environment restrictions at runtime, and Gemfile scoping is a second line of defense that keeps the gem out of deploy builds.
|
|
27
27
|
|
|
28
|
+
> **Pairing crosses the localhost-only boundary by design.** Realtime collaborative
|
|
29
|
+
> editing (see [Collaborative pairing](#collaborative-pairing-optional)) is meant to
|
|
30
|
+
> be reached by a second person, so it necessarily exposes the editor beyond your own
|
|
31
|
+
> machine. Treat that as an explicit, deliberate exception to the rules above — confine
|
|
32
|
+
> exposure to a trusted tunnel or LAN, set an authentication hook, and tear it down when
|
|
33
|
+
> you finish pairing. It does not change the core rule: mbeditor is development-only and
|
|
34
|
+
> must never be reachable by untrusted users.
|
|
35
|
+
|
|
28
36
|
## Installation
|
|
29
37
|
1. Add the gem to the host app Gemfile in development only:
|
|
30
38
|
|
|
@@ -97,21 +105,24 @@ end
|
|
|
97
105
|
| `rubocop_command` | `"rubocop"` | Command used for inline Ruby linting and formatting. |
|
|
98
106
|
| `git_timeout` | `10` | Seconds each git subprocess may run; a timed-out call degrades its own field of the git panel instead of failing the request. `nil` disables the bound. |
|
|
99
107
|
| `search_timeout` | `15` | Wall-clock bound on project-search subprocesses; a tripped deadline returns the partial results collected so far. `nil` disables. |
|
|
100
|
-
| `search_respect_gitignore` | `
|
|
108
|
+
| `search_respect_gitignore` | `true` | Project search and definition lookups skip files ignored by `.gitignore`, matching VS Code and ripgrep. Set to `false` to search ignored files too — expect it to be slow without ripgrep installed, since git then has to walk `node_modules`, `public/packs`, build output and caches. |
|
|
109
|
+
| `ripgrep_command` | `nil` | Path to the `rg` binary. `nil` auto-resolves: `PATH` first, then the usual install prefixes (`/opt/homebrew/bin`, `/usr/local/bin`, `/usr/bin`, linuxbrew, cargo). Set this if ripgrep lives somewhere unusual. See [Search performance](#search-performance). |
|
|
101
110
|
| `js_global_identifiers` | `[]` | Extra JS names declared as ambient globals in the editor — for runtime-only globals the static workspace scan can't see (e.g. `%w[Routes I18n]`). |
|
|
102
111
|
| `js_program` | `true` | Load the workspace's own JS source into Monaco's TypeScript program, so cross-file references get real inferred types instead of ambient `any`. See [JavaScript intelligence](#javascript-intelligence). `false` falls back to ambient declarations alone. |
|
|
103
112
|
| `js_program_exclude` | `%w[vendor]` | Directories excluded from that program, on top of `excluded_paths`. Point this at any third-party or generated JS — vendored libraries are UMD-wrapped, so their source costs parse time and contributes no globals. |
|
|
104
113
|
| `js_syntax_check` | `:auto` | Save-time babel parse check for JS/JSX using the host's `mini_racer` + babel-standalone (auto-detected; no-op when either is absent). `false` disables. |
|
|
105
114
|
| `babel_standalone_path` | `nil` | Explicit path to the babel-standalone bundle for the syntax check; `nil` looks up `babel.min.js`/`babel.js` in the host's asset pipeline. |
|
|
106
|
-
| `ruby_lsp` | `:auto` | Use the host's [ruby-lsp](https://github.com/Shopify/ruby-lsp) for Ruby go-to-definition, hover, completion, and
|
|
115
|
+
| `ruby_lsp` | `:auto` | Use the host's [ruby-lsp](https://github.com/Shopify/ruby-lsp) for Ruby go-to-definition (with peek), find-references, hover, completion, diagnostics, document symbols, folding, formatting, signature help, smart-select, and constant rename when it's installed (a persistent process is managed per workspace). `false` disables. Without ruby-lsp everything degrades to the built-in grep/Ripper services — no behavior change. Adding `ruby-lsp-rails` to your Gemfile needs no configuration here: ruby-lsp loads it as an addon and its Rails-aware results come through automatically. |
|
|
107
116
|
| `ruby_lsp_command` | `nil` | Override the ruby-lsp launch command (String or Array). `nil` auto-resolves `bin/ruby-lsp` → installed gem → `bundle exec ruby-lsp`. |
|
|
108
117
|
| `ruby_lsp_timeout` | `3` | Seconds per LSP request; on timeout (e.g. during initial indexing) the editor falls back to the built-in services for that request. |
|
|
118
|
+
| `model_graph` | *(no setting)* | The Models sidebar tab draws an entity diagram of your ActiveRecord models and their associations, read by reflection when the tab is opened. Pan by dragging, zoom by scrolling, click a model for its schema. Also writes `tmp/mbeditor_model_graph.mmd`, a Mermaid ER diagram that GitHub and VS Code render natively. Needs no configuration; apps without ActiveRecord simply see a message. |
|
|
119
|
+
| `exception_capture` | `:auto` | Record exceptions raised by your controllers and list them in the Problems panel, with clickable backtrace frames. Development only; backtraces are trimmed to frames inside the workspace. `false` disables. Note exception messages can include request params — the same exposure the log panel already has. |
|
|
109
120
|
|
|
110
121
|
### Authentication
|
|
111
122
|
|
|
112
123
|
| Option | Default | Description |
|
|
113
124
|
|--------|---------|-------------|
|
|
114
|
-
| `authenticate_with` | `nil` | Proc run as a `before_action` in all engine controllers. Executed via `instance_exec` inside the controller, so it has access to `session`, `cookies`, `redirect_to`, and auth-library class methods (e.g. Authlogic's `UserSession.find`) — but not helper methods from the host's `ApplicationController`. |
|
|
125
|
+
| `authenticate_with` | `nil` | Proc run as a `before_action` in all engine controllers. Executed via `instance_exec` inside the controller, so it has access to `session`, `cookies`, `redirect_to`, and auth-library class methods (e.g. Authlogic's `UserSession.find`) — but not helper methods from the host's `ApplicationController`. The same hook is also evaluated when the collaboration / editor **WebSocket** subscribes (see [Collaborative pairing](#collaborative-pairing-optional)); if it halts or raises, that subscription is rejected (fail-closed). Over the cable the proc runs against a request-derived probe, so request-scoped state may be narrower than over HTTP. |
|
|
115
126
|
| `authentication_cache_ttl` | `0` | Seconds to cache the auth result in the session (`0` = no caching). Set e.g. `300` to avoid calling `authenticate_with` on every request when the proc is expensive. Trade-off: after host logout, mbeditor stays accessible for up to TTL seconds. |
|
|
116
127
|
|
|
117
128
|
### Test runner
|
|
@@ -147,6 +158,13 @@ See [Resilient Routing](#resilient-routing) for details.
|
|
|
147
158
|
| `mount_path` | `nil` | Explicit URL prefix to serve resilient routing from. When `nil`, auto-detected from your `mount Mbeditor::Engine, at: "..."` line on every healthy boot. Set only to override detection. |
|
|
148
159
|
| `resilient_routing` | `true` | Keeps mbeditor reachable when the host's `config/routes.rb` is broken, by serving its traffic from middleware that dispatches to a private route set. Set to `false` as an escape hatch: no middleware is inserted and the private set is never built. |
|
|
149
160
|
|
|
161
|
+
### Collaboration
|
|
162
|
+
|
|
163
|
+
| Option | Default | Description |
|
|
164
|
+
|--------|---------|-------------|
|
|
165
|
+
| `user_name_callback` | `nil` | Proc resolving the display name shown on your caret during realtime collaboration. Only needed when the automatic lookup can't reach your user — see `user_name_methods` below. Executed via `instance_exec` inside the engine's controller (like `authenticate_with`), so it can read `session`, `cookies`, `params`, and anything your auth library exposes to an `ActionController::Base` subclass — e.g. `proc { User.find_by(id: session[:user_id])&.name }`. **It cannot see helper methods defined on your own `ApplicationController`**, because the engine's controllers do not inherit from it; a hand-rolled `current_user` living there will raise `NameError`, which is logged as `[mbeditor] user name lookup failed` and falls back to the generated name. |
|
|
166
|
+
| `user_name_methods` | `%w[name full_name display_name username login email]` | Attributes tried on `current_user`, in order, when no `user_name_callback` is set — the first non-blank one becomes your collaboration display name. This is what makes an authenticated editor show real names with no extra wiring, provided your auth library exposes `current_user` to `ActionController::Base` (Devise and Sorcery do; a `current_user` you wrote yourself on `ApplicationController` does not). Set it to your own column instead of writing a callback, e.g. `%w[preferred_name]`. |
|
|
167
|
+
|
|
150
168
|
## JavaScript intelligence
|
|
151
169
|
|
|
152
170
|
Under Sprockets every JS file shares one global scope, with no imports. The
|
|
@@ -279,6 +297,149 @@ The gem keeps host/tooling responsibilities in the host app:
|
|
|
279
297
|
|
|
280
298
|
All lint and test tools are auto-detected at runtime. The engine gracefully disables features if the tools are not available. Neither `rubocop`, `haml_lint`, nor any test framework are runtime dependencies of the gem itself — they are discovered from the host app's environment.
|
|
281
299
|
|
|
300
|
+
### Realtime via Action Cable (Optional)
|
|
301
|
+
|
|
302
|
+
Mbeditor works without Action Cable. If Action Cable is unavailable, unreachable, or returns transient errors, the editor automatically falls back to polling.
|
|
303
|
+
|
|
304
|
+
To enable realtime features in a host app:
|
|
305
|
+
|
|
306
|
+
1. Ensure Action Cable is enabled in the host app (for apps that do not load it by default, add the framework/gem explicitly).
|
|
307
|
+
2. Mount cable in host routes:
|
|
308
|
+
|
|
309
|
+
```ruby
|
|
310
|
+
mount ActionCable.server => '/cable'
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
3. Make Action Cable JavaScript available to the page (for asset-pipeline apps, `actioncable.js` is typically sufficient).
|
|
314
|
+
|
|
315
|
+
If any of these are missing, mbeditor still runs in polling mode.
|
|
316
|
+
|
|
317
|
+
### Collaborative pairing (Optional)
|
|
318
|
+
|
|
319
|
+
When Action Cable is available, mbeditor supports **realtime collaborative editing** —
|
|
320
|
+
live cursors and content sync over a WebSocket, so a second person can join the same
|
|
321
|
+
files. This is the one feature intended to be reached from another machine, so exposing
|
|
322
|
+
it is a **deliberate exception** to the localhost-only [Security Warning](#security-warning)
|
|
323
|
+
above. Expose it narrowly and only while you are actively pairing.
|
|
324
|
+
|
|
325
|
+
Collaboration activates only once **another participant is actually connected**, not
|
|
326
|
+
merely because Action Cable is up. On your own the editor behaves exactly as it does
|
|
327
|
+
without cable — persistent undo history and external-change detection stay in force,
|
|
328
|
+
both of which defer to the shared document while a session is live.
|
|
329
|
+
|
|
330
|
+
**1. Restrict the network exposure to a trusted path.**
|
|
331
|
+
Put the editor behind a **trusted tunnel** (e.g. an authenticated `ngrok`/Tailscale/
|
|
332
|
+
Cloudflare tunnel, or SSH port-forward) or keep it on a **trusted LAN**. Never bind it to
|
|
333
|
+
a public interface or an untrusted network. The person you pair with is the only one who
|
|
334
|
+
should be able to reach the port.
|
|
335
|
+
|
|
336
|
+
**2. Set an authentication hook — it runs on the WebSocket handshake.**
|
|
337
|
+
Configure `authenticate_with` (see the [Authentication](#authentication) options).
|
|
338
|
+
The same hook that gates the HTTP editor is now also evaluated when the collaboration /
|
|
339
|
+
editor WebSocket subscribes: if it halts (e.g. `redirect_to`/`render`/`head`) — or raises —
|
|
340
|
+
the socket subscription is **rejected (fail-closed)**, so pairing cannot bypass your auth.
|
|
341
|
+
|
|
342
|
+
```ruby
|
|
343
|
+
Mbeditor.configure do |c|
|
|
344
|
+
# Runs as a controller before_action AND on the cable subscribe.
|
|
345
|
+
c.authenticate_with = proc { head :forbidden unless UserSession.find }
|
|
346
|
+
end
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
Because the cable mount can bypass parts of the host middleware stack, a hook that leans on
|
|
350
|
+
request-scoped state (full `session`, encrypted `cookies`) may see less over the WebSocket
|
|
351
|
+
than it does over HTTP. For defence in depth, also authenticate at your host app's
|
|
352
|
+
`ApplicationCable::Connection` (the standard `identified_by` / `reject_unauthorized_connection`
|
|
353
|
+
pattern) — mbeditor's hook is an additional gate, not a replacement for securing the cable
|
|
354
|
+
connection itself.
|
|
355
|
+
|
|
356
|
+
**3. Configure Action Cable allowed request origins.**
|
|
357
|
+
Action Cable rejects cross-origin WebSocket connections. When you reach the editor through a
|
|
358
|
+
tunnel or LAN host, that origin must be allowed, or the socket silently fails and pairing
|
|
359
|
+
falls back to single-user mode. Allow exactly the origin(s) you pair through — never `/.*/`:
|
|
360
|
+
|
|
361
|
+
```ruby
|
|
362
|
+
# config/environments/development.rb
|
|
363
|
+
config.action_cable.allowed_request_origins = [
|
|
364
|
+
"https://your-pairing-tunnel.example.com",
|
|
365
|
+
%r{https://.*\.trusted-lan\.local}
|
|
366
|
+
]
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
When you finish pairing, close the tunnel / stop the forward so the editor is local-only again.
|
|
370
|
+
|
|
371
|
+
**4. Run a single web process.**
|
|
372
|
+
The shared document buffer is held in process memory and relayed over Action Cable's
|
|
373
|
+
default in-process (`async`) adapter, so collaboration state is **per-process**. If your
|
|
374
|
+
server runs multiple workers (e.g. Puma with `workers > 0` / `WEB_CONCURRENCY`), two
|
|
375
|
+
browsers can land on different workers and each see an empty or stale document — the most
|
|
376
|
+
common cause of *"the other person's edits never show up."* For pairing, run a single
|
|
377
|
+
worker (`WEB_CONCURRENCY=0`, or `bundle exec rails server` which is single-process by
|
|
378
|
+
default). A multi-worker setup would additionally need a cross-process cable adapter, but
|
|
379
|
+
the in-memory buffer still would not be shared — single-process is the supported mode.
|
|
380
|
+
|
|
381
|
+
#### Showing real usernames
|
|
382
|
+
|
|
383
|
+
Each participant's caret and presence chip are labelled. With no configuration
|
|
384
|
+
the label is a generated name like *Witty Operator*, persisted per browser and
|
|
385
|
+
editable by clicking your own chip.
|
|
386
|
+
|
|
387
|
+
**If your auth library exposes `current_user` to controllers** — Devise and
|
|
388
|
+
Sorcery both do, because they include their helpers into `ActionController::Base`
|
|
389
|
+
— it already works with no configuration at all. mbeditor reads the first
|
|
390
|
+
non-blank of `name`, `full_name`, `display_name`, `username`, `login`, `email`.
|
|
391
|
+
|
|
392
|
+
To point it at a different column:
|
|
393
|
+
|
|
394
|
+
```ruby
|
|
395
|
+
Mbeditor.configure do |c|
|
|
396
|
+
c.user_name_methods = %w[preferred_name email]
|
|
397
|
+
end
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
**If `current_user` is your own method on `ApplicationController`**, mbeditor
|
|
401
|
+
cannot see it — the engine's controllers inherit from `ActionController::Base`,
|
|
402
|
+
not from your `ApplicationController`. Resolve the user yourself instead; the
|
|
403
|
+
proc runs in the engine's controller, so `session`, `cookies` and `params` are
|
|
404
|
+
all available:
|
|
405
|
+
|
|
406
|
+
```ruby
|
|
407
|
+
Mbeditor.configure do |c|
|
|
408
|
+
c.user_name_callback = proc { User.find_by(id: session[:user_id])&.name }
|
|
409
|
+
end
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
An explicit `user_name_callback` always wins over the automatic lookup. If it
|
|
413
|
+
raises or returns blank you get the generated name, and the reason is logged as
|
|
414
|
+
`[mbeditor] user name lookup failed: …` rather than silently swallowed.
|
|
415
|
+
|
|
416
|
+
## Search performance
|
|
417
|
+
|
|
418
|
+
Project search and JS definition lookups pick a backend per call:
|
|
419
|
+
**ripgrep → `git grep` → `grep`**. ripgrep is 10–30× faster than the fallbacks,
|
|
420
|
+
so installing it is the single biggest thing you can do for search speed:
|
|
421
|
+
|
|
422
|
+
```bash
|
|
423
|
+
brew install ripgrep # macOS
|
|
424
|
+
apt install ripgrep # Debian/Ubuntu
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
`GET /mbeditor/workspace` reports `searchBackend` (`"rg"`, `"git"` or `"grep"`)
|
|
428
|
+
so you can check which tier is actually in use. Two things commonly make it
|
|
429
|
+
`"git"` when you expected `"rg"`:
|
|
430
|
+
|
|
431
|
+
- **ripgrep isn't on the server process's `PATH`.** A Rails server started from
|
|
432
|
+
launchd, systemd, foreman or an IDE inherits a stripped `PATH` that often
|
|
433
|
+
omits `/opt/homebrew/bin`. Mbeditor probes the usual install prefixes as well
|
|
434
|
+
as `PATH`; if yours is elsewhere, set `config.ripgrep_command`.
|
|
435
|
+
- **ripgrep genuinely isn't installed.** The `git grep` tier is then used. It
|
|
436
|
+
honours `excluded_paths` and `.gitignore`, so it stays usable — but it is
|
|
437
|
+
still far slower than ripgrep on a large workspace.
|
|
438
|
+
|
|
439
|
+
If search is slow, check `searchBackend` first, then confirm your build output
|
|
440
|
+
(`public/packs`, `app/assets/builds`, bundler/npm caches) is either gitignored
|
|
441
|
+
or listed in `excluded_paths`. Setting `search_respect_gitignore = false` makes
|
|
442
|
+
git walk every ignored tree and will be slow without ripgrep.
|
|
282
443
|
|
|
283
444
|
## Asset Pipeline
|
|
284
445
|
|
|
@@ -294,6 +455,32 @@ cd test/dummy && rails server
|
|
|
294
455
|
|
|
295
456
|
Then visit http://localhost:3000/mbeditor.
|
|
296
457
|
|
|
458
|
+
### Vendored JavaScript (no consumer build step)
|
|
459
|
+
|
|
460
|
+
All third-party JS is **prebuilt and committed** under `vendor/assets/javascripts/`
|
|
461
|
+
and served as-is by Sprockets. Installing the gem needs **zero JS tooling** — no
|
|
462
|
+
Node, npm, or bundler — which is the contract recorded in
|
|
463
|
+
[ADR-0001](docs/adr/0001-no-frontend-build-step.md). `package.json` exists only as
|
|
464
|
+
a dependency manifest for `npm audit`.
|
|
465
|
+
|
|
466
|
+
Most vendored libs are committed verbatim from npm. The one exception is the
|
|
467
|
+
collaborative-editing bundle, `vendor/assets/javascripts/yjs-collab.js`, which
|
|
468
|
+
combines Yjs + y-monaco + y-protocols (awareness) into a single IIFE exposing
|
|
469
|
+
`window.Y`, `window.MonacoBinding`, and `window.awarenessProtocol`. It is produced
|
|
470
|
+
by a **maintainer-only** build script. Monaco itself is not bundled — the binding
|
|
471
|
+
forwards to the page's runtime `window.monaco`.
|
|
472
|
+
|
|
473
|
+
To regenerate it after bumping any of those pinned versions in `package.json`:
|
|
474
|
+
|
|
475
|
+
```bash
|
|
476
|
+
npm install # installs yjs / y-monaco / y-protocols + esbuild (maintainer-only)
|
|
477
|
+
npm run build:yjs # === node script/build-yjs-bundle.mjs
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
then commit the regenerated `vendor/assets/javascripts/yjs-collab.js`. The build is
|
|
481
|
+
deterministic: rebuilding from the same pinned versions reproduces identical bytes.
|
|
482
|
+
This step is for maintainers only; it never runs on a consumer's machine.
|
|
483
|
+
|
|
297
484
|
## Testing
|
|
298
485
|
|
|
299
486
|
The test suite uses Minitest via the dummy Rails app. Run all tests from the project root:
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
//= require mbeditor/editor_store
|
|
3
3
|
//= require mbeditor/file_icon
|
|
4
4
|
//= require mbeditor/file_service
|
|
5
|
+
//= require mbeditor/file_import
|
|
5
6
|
//= require mbeditor/history_service
|
|
6
7
|
//= require mbeditor/websocket_service
|
|
7
8
|
//= require mbeditor/git_service
|
|
@@ -9,6 +10,8 @@
|
|
|
9
10
|
//= require mbeditor/conflict_parser
|
|
10
11
|
//= require mbeditor/search_service
|
|
11
12
|
//= require mbeditor/tab_manager
|
|
13
|
+
//= require mbeditor/collaboration_identity
|
|
14
|
+
//= require mbeditor/collaboration_service
|
|
12
15
|
//= require mbeditor/color_provider
|
|
13
16
|
//= require mbeditor/editor_plugins
|
|
14
17
|
//= require mbeditor/ruby_outline
|
|
@@ -18,6 +21,7 @@
|
|
|
18
21
|
//= require mbeditor/components/DiffViewer
|
|
19
22
|
//= require mbeditor/components/CombinedDiffViewer
|
|
20
23
|
//= require mbeditor/components/CommitGraph
|
|
24
|
+
//= require mbeditor/components/ModelGraph
|
|
21
25
|
//= require mbeditor/components/ChangelogView
|
|
22
26
|
//= require mbeditor/components/FileHistoryPanel
|
|
23
27
|
//= require mbeditor/components/TestResultsPanel
|
|
@@ -31,3 +35,4 @@
|
|
|
31
35
|
//= require mbeditor/components/TabBar
|
|
32
36
|
//= require mbeditor/components/MbeditorApp
|
|
33
37
|
//= require mbeditor/application_iife_tail
|
|
38
|
+
//= require mbeditor/components/ImportConflictModal
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
window.SearchService = SearchService;
|
|
2
2
|
window.GitService = GitService;
|
|
3
3
|
window.FileService = FileService;
|
|
4
|
+
// Exposed for system tests to observe collaboration state and drive store updates
|
|
5
|
+
// (same test-seam convention as the services above).
|
|
6
|
+
window.EditorStore = EditorStore;
|
|
7
|
+
window.CollaborationService = CollaborationService;
|
|
8
|
+
window.CollaborationIdentity = CollaborationIdentity;
|
|
9
|
+
window.WebSocketService = WebSocketService;
|
|
4
10
|
})(window.MbeditorRuntime.React, window.MbeditorRuntime.ReactDOM);
|