mbeditor 0.14.2 → 0.14.3

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.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +43 -0
  3. data/app/assets/javascripts/mbeditor/application.js +5 -1
  4. data/app/assets/javascripts/mbeditor/collaboration_identity.js +4 -2
  5. data/app/assets/javascripts/mbeditor/collaboration_service.js +74 -2
  6. data/app/assets/javascripts/mbeditor/components/AiRoundTripModal.js +452 -0
  7. data/app/assets/javascripts/mbeditor/components/ChangelogView.js +1 -1
  8. data/app/assets/javascripts/mbeditor/components/CombinedFileView.js +3 -2
  9. data/app/assets/javascripts/mbeditor/components/EditorPanel.js +28 -27
  10. data/app/assets/javascripts/mbeditor/components/FileHistoryPanel.js +2 -7
  11. data/app/assets/javascripts/mbeditor/components/FileTree.js +144 -4
  12. data/app/assets/javascripts/mbeditor/components/GitPanel.js +1 -1
  13. data/app/assets/javascripts/mbeditor/components/ImportConflictModal.js +7 -68
  14. data/app/assets/javascripts/mbeditor/components/ImportDialog.js +2 -16
  15. data/app/assets/javascripts/mbeditor/components/MbeditorApp.js +340 -472
  16. data/app/assets/javascripts/mbeditor/components/ModalDialog.js +203 -0
  17. data/app/assets/javascripts/mbeditor/components/PastePlaceModal.js +1 -9
  18. data/app/assets/javascripts/mbeditor/components/Popover.js +88 -0
  19. data/app/assets/javascripts/mbeditor/components/PopupMenu.js +166 -0
  20. data/app/assets/javascripts/mbeditor/components/ProblemsPanel.js +8 -4
  21. data/app/assets/javascripts/mbeditor/components/QuickOpenDialog.js +5 -7
  22. data/app/assets/javascripts/mbeditor/components/SettingsModal.js +3 -14
  23. data/app/assets/javascripts/mbeditor/components/ShortcutHelp.js +4 -25
  24. data/app/assets/javascripts/mbeditor/components/TabBar.js +15 -32
  25. data/app/assets/javascripts/mbeditor/components/TestResultsPanel.js +2 -7
  26. data/app/assets/javascripts/mbeditor/editor_plugins.js +3 -23
  27. data/app/assets/javascripts/mbeditor/file_service.js +1 -1
  28. data/app/assets/javascripts/mbeditor/git_service.js +0 -7
  29. data/app/assets/javascripts/mbeditor/patch_select.js +156 -0
  30. data/app/assets/javascripts/mbeditor/tab_manager.js +19 -0
  31. data/app/assets/stylesheets/mbeditor/application.css +7 -110
  32. data/app/assets/stylesheets/mbeditor/editor.css +195 -192
  33. data/app/assets/stylesheets/mbeditor/glass.css +1 -1
  34. data/app/channels/mbeditor/collaboration_channel.rb +24 -5
  35. data/app/controllers/mbeditor/editors_controller.rb +75 -38
  36. data/app/controllers/mbeditor/git_controller.rb +1 -12
  37. data/app/services/mbeditor/ai_bundle_service.rb +181 -0
  38. data/app/services/mbeditor/archive_service.rb +43 -6
  39. data/app/services/mbeditor/availability_probe.rb +2 -2
  40. data/app/services/mbeditor/code_search_service.rb +1 -3
  41. data/app/services/mbeditor/collaboration_doc_store.rb +37 -1
  42. data/app/services/mbeditor/exclusion_matcher.rb +0 -4
  43. data/app/services/mbeditor/file_import_service.rb +4 -1
  44. data/app/services/mbeditor/file_operation_service.rb +3 -3
  45. data/app/services/mbeditor/git_service.rb +11 -45
  46. data/app/services/mbeditor/js_definition_service.rb +1 -0
  47. data/app/services/mbeditor/model_graph_service.rb +1 -0
  48. data/app/services/mbeditor/patch_apply_service.rb +185 -0
  49. data/app/services/mbeditor/rails_related_files_service.rb +1 -1
  50. data/app/services/mbeditor/redmine_config_error.rb +6 -0
  51. data/app/services/mbeditor/redmine_disabled_error.rb +10 -0
  52. data/app/services/mbeditor/redmine_service.rb +0 -8
  53. data/app/services/mbeditor/ruby_definition_service.rb +1 -0
  54. data/app/services/mbeditor/schema_service.rb +1 -0
  55. data/app/services/mbeditor/test_runner_service.rb +1 -1
  56. data/lib/mbeditor/rack/silence_ping_request.rb +14 -14
  57. data/lib/mbeditor/route_map.rb +5 -2
  58. data/lib/mbeditor/ruby_lsp_client.rb +7 -26
  59. data/lib/mbeditor/version.rb +1 -1
  60. data/public/monaco-editor/VERSIONS +2 -1
  61. data/public/monaco-editor/monaco.js +226 -226
  62. metadata +11 -4
  63. data/app/assets/javascripts/mbeditor/components/CommitGraph.js +0 -65
  64. data/app/services/mbeditor/git_commit_graph_service.rb +0 -62
@@ -45,18 +45,6 @@ module Mbeditor
45
45
  ref.match?(SAFE_GIT_REF) ? ref : nil
46
46
  end
47
47
 
48
- # Returns [ahead_count, behind_count] relative to upstream, or [0,0].
49
- def ahead_behind(repo_path, upstream)
50
- return [0, 0] if upstream.blank?
51
- return [0, 0] unless upstream.match?(SAFE_GIT_REF)
52
-
53
- out, status = run_git(repo_path, "rev-list", "--left-right", "--count", "HEAD...#{upstream}")
54
- return [0, 0] unless status.success?
55
-
56
- parts = out.strip.split("\t", 2)
57
- [parts[0].to_i, parts[1].to_i]
58
- end
59
-
60
48
  # Returns [merge_base_sha, ref_name] of the first candidate base branch that
61
49
  # exists, or [nil, nil] when none does.
62
50
  #
@@ -190,16 +178,20 @@ module Mbeditor
190
178
  map
191
179
  end
192
180
 
193
- # Parse compact `git log --pretty=format:%H%x1f%P%x1f%s%x1f%an%x1f%aI%x1e` output.
194
- # Returns Array of hashes with string keys.
195
- def self.parse_git_log_with_parents(raw_output)
196
- parse_log_entries(raw_output, with_parents: true)
197
- end
198
-
199
181
  # Parse compact `git log --pretty=format:%H%x1f%s%x1f%an%x1f%aI%x1e` output.
200
182
  # Returns Array of hashes with string keys.
201
183
  def self.parse_git_log(raw_output)
202
- parse_log_entries(raw_output, with_parents: false)
184
+ raw_output.split("\x1e").filter_map do |entry|
185
+ fields = entry.strip.split("\x1f", 4)
186
+ next unless fields.length == 4
187
+
188
+ {
189
+ "hash" => fields[0],
190
+ "title" => fields[1],
191
+ "author" => fields[2],
192
+ "date" => fields[3]
193
+ }
194
+ end
203
195
  end
204
196
 
205
197
  # Resolve a file path safely within repo_path. Returns full path string or
@@ -226,31 +218,5 @@ module Mbeditor
226
218
  rescue Errno::EACCES
227
219
  nil
228
220
  end
229
-
230
- def self.parse_log_entries(raw_output, with_parents:)
231
- field_count = with_parents ? 5 : 4
232
- raw_output.split("\x1e").filter_map do |entry|
233
- fields = entry.strip.split("\x1f", field_count)
234
- next unless fields.length == field_count
235
-
236
- if with_parents
237
- {
238
- "hash" => fields[0],
239
- "parents" => fields[1].split.reject(&:blank?),
240
- "title" => fields[2],
241
- "author" => fields[3],
242
- "date" => fields[4]
243
- }
244
- else
245
- {
246
- "hash" => fields[0],
247
- "title" => fields[1],
248
- "author" => fields[2],
249
- "date" => fields[3]
250
- }
251
- end
252
- end
253
- end
254
- private_class_method :parse_log_entries
255
221
  end
256
222
  end
@@ -57,6 +57,7 @@ module Mbeditor
57
57
  # whitespace, and `(^|[^A-Za-z0-9_$])` / `([^A-Za-z0-9_$]|$)` for word
58
58
  # boundaries.
59
59
  NOT_IDENT = "[^A-Za-z0-9_$]"
60
+ private_constant :NOT_IDENT
60
61
 
61
62
  # Stage 1: explicit member assignment anywhere in the workspace — the
62
63
  # parent name on the line makes the pattern precise enough for a global
@@ -221,6 +221,7 @@ module Mbeditor
221
221
  "has_many" => "||--o{",
222
222
  "has_and_belongs_to_many" => "}o--o{"
223
223
  }.freeze
224
+ private_constant :MERMAID_CARDINALITY
224
225
 
225
226
  def to_mermaid(payload)
226
227
  lines = ["erDiagram"]
@@ -0,0 +1,185 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mbeditor
4
+ # Checks and applies a unified diff pasted from a chat reply, with
5
+ # `git apply` (it works outside a repository too).
6
+ #
7
+ # The patch goes in on stdin rather than a Tempfile: nothing to clean up, and
8
+ # ProcessRunner already drains and bounds the pipes.
9
+ class PatchApplyService
10
+ MAX_PATCH_BYTES = 5 * 1024 * 1024
11
+ TIMEOUT = 30
12
+ OUTPUT_CAP = 1024 * 1024
13
+
14
+ # Message is shown to the user verbatim; for a failed apply it is git's
15
+ # stderr, which names the failing hunk.
16
+ class Error < StandardError; end
17
+
18
+ def initialize(workspace_root)
19
+ @root = workspace_root.to_s
20
+ end
21
+
22
+ # Returns { ok:, files: [{path, added, removed, status}], output:, patch: }
23
+ # where patch is the normalised text that was checked or applied.
24
+ #
25
+ # +blocked+ is an optional predicate over a workspace-relative path; a patch
26
+ # touching a path it accepts is refused before anything is written.
27
+ def call(raw_patch, check: true, blocked: nil)
28
+ patch = normalize(raw_patch)
29
+ reject_symlinks!(patch)
30
+ prefix = git_prefix
31
+
32
+ # A workspace below the repository root: git reads `diff --git` paths as
33
+ # repo-root-relative, the AI wrote them workspace-relative.
34
+ base = %w[git -c core.quotepath=off apply --whitespace=nowarn]
35
+ base << "--directory=#{prefix}" unless prefix.empty?
36
+
37
+ args, check_error = pick_args(base, patch)
38
+ files = list_files(patch, args, prefix)
39
+ reject_blocked!(files, blocked)
40
+ raise check_error if check_error
41
+
42
+ result = check ? nil : run!(args, patch)
43
+ { ok: true, files: files, output: result ? result[:stderr].strip : "", patch: patch }
44
+ end
45
+
46
+ private
47
+
48
+ # Chat replies arrive as fenced blocks with prose around them. A bare ```
49
+ # can never be a hunk line (those start with space, + or -).
50
+ def normalize(raw)
51
+ raise Error, "Patch is too large (limit #{MAX_PATCH_BYTES / 1024 / 1024} MB)." if raw.to_s.bytesize > MAX_PATCH_BYTES
52
+
53
+ text = raw.to_s
54
+ # A paste that is CRLF throughout gets normalised. A mixed one is a
55
+ # patch for a CRLF file (LF structure, CRLF content) and must stay as is.
56
+ text = text.gsub("\r\n", "\n") unless text.match?(/(?<!\r)\n/)
57
+ lines = text.lines
58
+
59
+ # Every diff block in the reply, fenced or not: from a diff line to the
60
+ # closing fence (or the end of the text), then on to the next block.
61
+ chunks = []
62
+ while (start = lines.index { |l| l.start_with?("diff --git ", "--- ") })
63
+ body = lines.drop(start)
64
+ fence = body.index { |l| l.start_with?("```") }
65
+ chunk = (fence ? body.first(fence) : body).join
66
+ chunks << (chunk.end_with?("\n") ? chunk : "#{chunk}\n")
67
+ lines = fence ? body.drop(fence + 1) : []
68
+ end
69
+ raise Error, "No diff found. Paste a unified diff (diff --git / --- / +++ lines)." if chunks.empty?
70
+
71
+ chunks.join
72
+ end
73
+
74
+ # `--recount` rescues wrong hunk counts, but on a patch with no `diff --git`
75
+ # headers it reads a `--- a/b` line as a removed line, so a failed check
76
+ # retries without it. Returns [args, nil], or [args, error] when nothing
77
+ # applies; the error says so if only whitespace differs.
78
+ def pick_args(base, patch)
79
+ variants = [base + ["--recount"], base]
80
+ ok = variants.find { |args| passes?(args + ["--check"], patch) }
81
+ return [ok, nil] if ok
82
+
83
+ error = begin
84
+ run!(variants.first + ["--check"], patch)
85
+ rescue Error => e
86
+ e
87
+ end
88
+ if variants.any? { |args| passes?(args + %w[--ignore-whitespace --check], patch) }
89
+ error = Error.new("#{error.message}\n\nHint: line endings or trailing newline differ from the file on disk.")
90
+ end
91
+ [variants.first, error]
92
+ end
93
+
94
+ def passes?(cmd, patch)
95
+ run!(cmd, patch)
96
+ true
97
+ rescue Error
98
+ false
99
+ end
100
+
101
+ # A symlink made by a patch can point anywhere, and later writes would go
102
+ # through it.
103
+ def reject_symlinks!(patch)
104
+ return unless patch.match?(/^(?:new (?:file )?mode|index [0-9a-f]+\.\.[0-9a-f]+) 120000\b/)
105
+
106
+ raise Error, "Refusing a patch that creates or changes a symbolic link."
107
+ end
108
+
109
+ def reject_blocked!(files, blocked)
110
+ return unless blocked
111
+
112
+ files.flat_map { |f| [f[:path], f[:from]] }.compact.each do |p|
113
+ raise Error, "Refusing to touch #{p.inspect}: this path is excluded from editing." if blocked.call(p)
114
+ end
115
+ end
116
+
117
+ # A non-repo directory gives "" (git apply works there), as does the repo root.
118
+ def git_prefix
119
+ r = run(%w[git rev-parse --show-prefix])
120
+ r[:exit_status].success? ? r[:stdout].strip : ""
121
+ end
122
+
123
+ def list_files(patch, args, prefix)
124
+ r = run!(args + %w[--numstat --summary -z], patch)
125
+ tokens = r[:stdout].split("\0", -1)
126
+ summary = tokens.pop.to_s
127
+ created = summary.scan(/^ create mode \d+ (.+)$/).flatten.map { |p| strip(p, prefix) }
128
+ deleted = summary.scan(/^ delete mode \d+ (.+)$/).flatten.map { |p| strip(p, prefix) }
129
+ # A pure rename's numstat entry carries only the new name.
130
+ renames = patch.scan(/^rename from (.+)\nrename to (.+)$/).to_h { |from, to| [to, from] }
131
+
132
+ files = []
133
+ until tokens.empty?
134
+ m = tokens.shift.match(/\A(\d+|-)\t(\d+|-)\t(.*)\z/m) or next
135
+ from = nil
136
+ path = m[3]
137
+ # -z numstat: a rename is an empty path followed by old then new.
138
+ from, path = tokens.shift(2).map { |p| strip(p, prefix) } if path.empty?
139
+ path = strip(path, prefix)
140
+ from ||= renames[path]
141
+ status = if from then :renamed
142
+ elsif created.include?(path) then :created
143
+ elsif deleted.include?(path) then :deleted
144
+ else :modified
145
+ end
146
+ files << { path: path, added: m[1].to_i, removed: m[2].to_i, status: status }.tap { |f| f[:from] = from if from }
147
+ end
148
+ reject_unsafe!(files.flat_map { |f| [f[:path], f[:from]] }.compact)
149
+ files
150
+ end
151
+
152
+ # git apply refuses most of these itself (no --unsafe-paths is ever
153
+ # passed); this is the explicit second check, and the only one for .git.
154
+ def reject_unsafe!(paths)
155
+ paths.each do |p|
156
+ segments = p.split("/")
157
+ next unless p.start_with?("/") || p.include?("\0") || segments.include?("..") ||
158
+ segments.any? { |s| s.casecmp?(".git") }
159
+
160
+ raise Error, "Refusing to touch #{p.inspect}: paths must be inside the project and not under .git."
161
+ end
162
+ end
163
+
164
+ def strip(path, prefix)
165
+ prefix.empty? ? path : path.delete_prefix(prefix)
166
+ end
167
+
168
+ def run(cmd, stdin = nil)
169
+ ProcessRunner.call(cmd, timeout: TIMEOUT, stdin_data: stdin, chdir: @root, max_bytes: OUTPUT_CAP)
170
+ rescue ProcessRunner::TimeoutError
171
+ raise Error, "git timed out after #{TIMEOUT}s."
172
+ rescue Errno::EPIPE
173
+ raise Error, "git stopped reading the patch before the end; it may be malformed."
174
+ rescue Errno::ENOENT
175
+ raise Error, "git is not installed; it is needed to apply patches."
176
+ end
177
+
178
+ def run!(cmd, stdin)
179
+ r = run(cmd, stdin)
180
+ raise Error, (r[:stderr].presence || r[:stdout]).strip unless r[:exit_status].success?
181
+
182
+ r
183
+ end
184
+ end
185
+ end
@@ -189,7 +189,7 @@ module Mbeditor
189
189
  # All path segments between "views" and the view filename form the resource path.
190
190
  # e.g. app/views/admin/users/index.html.erb → view_resource = ["admin","users"]
191
191
  # e.g. app/views/users/index.html.erb → view_resource = ["users"]
192
- view_resource = parts[2..parts.length - 2]
192
+ view_resource = parts[2..(parts.length - 2)]
193
193
  plural = view_resource.join("/")
194
194
  singular = (view_resource[0..-2] + [singularize(view_resource.last)]).join("/")
195
195
  [plural, singular]
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mbeditor
4
+ # Raised by RedmineService when the integration is enabled but misconfigured.
5
+ class RedmineConfigError < StandardError; end
6
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mbeditor
4
+ # Raised by RedmineService when the integration is switched off.
5
+ class RedmineDisabledError < StandardError
6
+ def initialize
7
+ super("Redmine integration is not enabled. Set config.mbeditor.redmine_enabled = true.")
8
+ end
9
+ end
10
+ end
@@ -6,14 +6,6 @@ require "uri"
6
6
  require "json"
7
7
 
8
8
  module Mbeditor
9
- class RedmineDisabledError < StandardError
10
- def initialize
11
- super("Redmine integration is not enabled. Set config.mbeditor.redmine_enabled = true.")
12
- end
13
- end
14
-
15
- class RedmineConfigError < StandardError; end
16
-
17
9
  # Fetches a Redmine issue via the REST API.
18
10
  #
19
11
  # Only usable when Mbeditor.configuration.redmine_enabled is true.
@@ -295,6 +295,7 @@ module Mbeditor
295
295
  # Throttled: stat()ing every cached path on every definition lookup grows
296
296
  # with workspace size, so run at most once per EVICT_INTERVAL.
297
297
  EVICT_INTERVAL = 30 # seconds
298
+ private_constant :EVICT_INTERVAL
298
299
 
299
300
  def evict_deleted_cache_entries
300
301
  now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
@@ -320,6 +320,7 @@ module Mbeditor
320
320
  'polygon' => 'string',
321
321
  'circle' => 'string'
322
322
  }.freeze
323
+ private_constant :SQL_TYPE_TO_RAILS
323
324
 
324
325
  def sql_type_to_rails(sql_type)
325
326
  SQL_TYPE_TO_RAILS[sql_type.downcase] || sql_type
@@ -280,7 +280,7 @@ module Mbeditor
280
280
  line_num = name_line[/:(\d+)\]/, 1]&.to_i
281
281
  file = relativize(name_line[/\[([^\]]+):\d+\]/, 1], repo_path)
282
282
  msg_lines = []
283
- (idx + 2...lines.length).each do |j|
283
+ ((idx + 2)...lines.length).each do |j|
284
284
  break if lines[j].strip.empty? || lines[j].match?(/^\s+\d+\)\s+/)
285
285
  msg_lines << lines[j].strip
286
286
  end
@@ -16,20 +16,20 @@ module Mbeditor
16
16
 
17
17
  def call(env)
18
18
  path = normalized_request_path(env)
19
- if root_request?(env, path)
20
- @app.call(env)
21
- elsif mbeditor_request?(path) || cable_request?(path) || editor_asset_request?(env, path)
22
- # Silence to WARN, not the default ERROR. The point is to hide Rails'
23
- # own request lines ("Started GET ...", "Completed 200 ..."), which are
24
- # INFO — but the default swallows everything below ERROR, including
25
- # anything a host app logs from inside authenticate_with or
26
- # user_name_callback. Those procs run within this request, so a
27
- # developer debugging their own hook with Rails.logger.warn saw
28
- # nothing at all and had no way to know why.
29
- Rails.logger.silence(::Logger::WARN) { @app.call(env) }
30
- else
31
- @app.call(env)
32
- end
19
+ # The engine root stays loud (see the class comment); only the rest of
20
+ # mbeditor's own traffic is quieted.
21
+ quiet = !root_request?(env, path) &&
22
+ (mbeditor_request?(path) || cable_request?(path) || editor_asset_request?(env, path))
23
+ return @app.call(env) unless quiet
24
+
25
+ # Silence to WARN, not the default ERROR. The point is to hide Rails'
26
+ # own request lines ("Started GET ...", "Completed 200 ..."), which are
27
+ # INFO — but the default swallows everything below ERROR, including
28
+ # anything a host app logs from inside authenticate_with or
29
+ # user_name_callback. Those procs run within this request, so a
30
+ # developer debugging their own hook with Rails.logger.warn saw
31
+ # nothing at all and had no way to know why.
32
+ Rails.logger.silence(::Logger::WARN) { @app.call(env) }
33
33
  end
34
34
 
35
35
  private
@@ -15,6 +15,8 @@ module Mbeditor
15
15
  get 'file', to: 'editors#show'
16
16
  get 'raw', to: 'editors#raw'
17
17
  get 'archive', to: 'editors#archive'
18
+ get 'ai_bundle', to: 'editors#ai_bundle'
19
+ post 'apply_patch', to: 'editors#apply_patch'
18
20
  post 'file', to: 'editors#save'
19
21
  post 'create_file', to: 'editors#create_file'
20
22
  post 'create_dir', to: 'editors#create_dir'
@@ -61,7 +63,9 @@ module Mbeditor
61
63
  post 'quick_fix', to: 'editors#quick_fix'
62
64
  post 'format', to: 'editors#format_file'
63
65
  post 'rubocop', to: 'editors#rubocop_run'
64
- post 'test', to: 'editors#run_test'
66
+ # Named explicitly: the default name `test` generates test_path/test_url,
67
+ # which Minitest runs as tests in any test that mixes in the url_helpers.
68
+ post 'test', to: 'editors#run_test', as: :run_test
65
69
  get 'logs/tail', to: 'logs#tail'
66
70
 
67
71
  # ── Git & Code Review ──────────────────────────────────────────────────────
@@ -69,7 +73,6 @@ module Mbeditor
69
73
  get 'git/blame', to: 'git#blame'
70
74
  get 'git/line_diff', to: 'git#line_diff'
71
75
  get 'git/file_history', to: 'git#file_history'
72
- get 'git/commit_graph', to: 'git#commit_graph'
73
76
  get 'git/commit_detail', to: 'git#commit_detail'
74
77
  get 'git/combined_diff', to: 'git#combined_diff'
75
78
 
@@ -98,31 +98,6 @@ module Mbeditor
98
98
  @state == :ready
99
99
  end
100
100
 
101
- # A snapshot for the editor's status indicator. Deliberately does not start
102
- # the process — asking "how are you?" must not be what boots the server.
103
- #
104
- # Deliberately lock-free: @state_mutex is held for the whole of a start
105
- # (up to INIT_TIMEOUT) and a restart, and a status chip polled every 10s
106
- # must not queue behind a handshake. Each field is one reference read, so
107
- # the worst case is a snapshot that is one transition out of date.
108
- def health
109
- { state: @state, restarts: @crash_times.length, error: @last_error }
110
- end
111
-
112
- # Clears the crash budget so a client latched at :failed can be revived
113
- # without restarting the whole Rails process. Clearing @crash_times is the
114
- # load-bearing part: restart_allowed? re-latches :failed immediately if the
115
- # window still holds MAX_RESTARTS entries.
116
- def reset!
117
- stop
118
- @state_mutex.synchronize do
119
- @crash_times.clear
120
- @last_error = nil
121
- @state = :stopped
122
- end
123
- ready?
124
- end
125
-
126
101
  # Syncs the document (didOpen / full-text didChange) and issues a request
127
102
  # against it, so concurrent Puma threads can't interleave a positional
128
103
  # request with a stale document.
@@ -279,7 +254,11 @@ module Mbeditor
279
254
  # a caller is told "not ready" and falls back to the grep/Ripper path.
280
255
  def ensure_started
281
256
  @state_mutex.synchronize do
282
- return if %i[ready failed starting].include?(@state)
257
+ # :failed is not short-circuited here: restart_allowed? keeps it latched
258
+ # while RESTART_WINDOW still holds MAX_RESTARTS crashes, and lets the
259
+ # next request start the server once they have aged out. Nothing else
260
+ # can revive it — there is no manual reset.
261
+ return if %i[ready starting].include?(@state)
283
262
  return unless restart_allowed?
284
263
 
285
264
  @state = :starting
@@ -292,6 +271,8 @@ module Mbeditor
292
271
 
293
272
  now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
294
273
  @crash_times.reject! { |t| now - t > RESTART_WINDOW }
274
+ # Every crash has aged out: a clean slate, and no .last to back off from.
275
+ return true if @crash_times.empty?
295
276
  if @crash_times.length >= MAX_RESTARTS
296
277
  @state = :failed
297
278
  return false
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mbeditor
4
- VERSION = "0.14.2"
4
+ VERSION = "0.14.3"
5
5
  end
@@ -1,3 +1,4 @@
1
1
  monaco-editor 0.57.0
2
2
  monaco-vim 0.4.4
3
- esbuild 0.28.0
3
+ esbuild 0.28.2
4
+ dompurify 3.4.17