mbeditor 0.15.2 → 0.15.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83016422a76630d14cbb22af14568f8c9f1794f07df09a6fff2096566ce53db9
4
- data.tar.gz: c74da11012a790da6aca3e5cb1e77a993103baa55e0bd61a83e3bf9e08710d49
3
+ metadata.gz: 3d5f5b702dfd223a9ae051b32aa6dc210c9b528ddd59f786581c3d567c74949c
4
+ data.tar.gz: ad2ec60715cfd67d970e85bebc623e174d33ec630678a42d59b3f0135295a676
5
5
  SHA512:
6
- metadata.gz: 59b397cd44533ac91789a68d874e9aaaf0f7c56a56cbac306d50e4634c134460497adffd15ab324eaf4bbaee9b970fe23a2a66f5c52fd9c4d37d8dc0dc36da30
7
- data.tar.gz: 9cdd323e0bf8e6bdb797a4a0f36d1ce6cd93b37df790f29c223eca3b3d4d1d00d7fba565596c8044a97b76b6f40e627e4f06965e3a8b4845961d4bcfee45a0fd
6
+ metadata.gz: 57a737043fab9ae30d1e1e74b889f1a9fb585f76b0d34dc5fa4ef0fc9147968e45abe5d2e8ebd267e5a3f71b4ac01c1bbc3a7c54c99b893f76861d6989b5ec5d
7
+ data.tar.gz: 1cad0a46d4303610f9eb009cbcd0fe081cd8efbe4c8e5777efb0e731887e5629c56f80efe6fa7cc8c1916a386f7a35c9b9a05859e7ddf8afc2947c1a3d47b6ea
data/CHANGELOG.md CHANGED
@@ -5,6 +5,13 @@ 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
+ ## [0.15.3] - 2026-12-04
9
+
10
+ ### Fixed
11
+ - The AI dialog's diff queue is kept when the dialog is closed and reopened,
12
+ and saved to `tmp/mbeditor_ai_queue.json` so it also survives a page reload
13
+ or a new session. Entries not yet applied are re-checked on reopen.
14
+
8
15
  ## [0.15.2] - 2026-12-04
9
16
 
10
17
  ### Added
@@ -235,6 +235,54 @@ function aiClock() {
235
235
 
236
236
  var AI_GROUP_PEEK = 3;
237
237
 
238
+ // The apply queue outlives the dialog: closing and reopening it keeps the
239
+ // entries, until the page reloads.
240
+ var aiKeptQueue = { queue: [], selId: null, nextId: 1, pasted: 0 };
241
+
242
+ // The queue also survives a reload: the patch text and status go to the
243
+ // workspace's tmp dir. Loaded once per page; saves wait for a good load so a
244
+ // failed GET never overwrites the file with an empty queue.
245
+ var aiQueueLoad = null;
246
+ var aiQueueLoadedOk = false;
247
+ var aiQueueSavedJson = '[]';
248
+ var aiQueueSaveTimer = null;
249
+ var aiQueueWire = function () {
250
+ return aiKeptQueue.queue.map(function (e) {
251
+ var o = { name: e.name, patch: e.patch, status: e.status };
252
+ if (e.appliedAt) o.appliedAt = e.appliedAt;
253
+ return o;
254
+ });
255
+ };
256
+ var aiLoadQueue = function (base) {
257
+ if (!aiQueueLoad) {
258
+ aiQueueLoad = axios.get(base + '/ai_queue').then(function (resp) {
259
+ var saved = (resp.data && resp.data.queue) || [];
260
+ if (!aiKeptQueue.queue.length) {
261
+ aiKeptQueue.queue = saved.map(function (e) {
262
+ var entry = { id: aiKeptQueue.nextId++, name: e.name, patch: e.patch, status: e.status === 'applied' ? 'applied' : 'checking' };
263
+ if (e.appliedAt) entry.appliedAt = e.appliedAt;
264
+ return entry;
265
+ });
266
+ if (!aiKeptQueue.selId && aiKeptQueue.queue.length) aiKeptQueue.selId = aiKeptQueue.queue[0].id;
267
+ }
268
+ aiQueueSavedJson = JSON.stringify(aiQueueWire());
269
+ aiQueueLoadedOk = true;
270
+ }, function () { /* nothing remembered */ });
271
+ }
272
+ return aiQueueLoad;
273
+ };
274
+ var aiScheduleQueueSave = function (base) {
275
+ if (!aiQueueLoadedOk) return;
276
+ clearTimeout(aiQueueSaveTimer);
277
+ aiQueueSaveTimer = setTimeout(function () {
278
+ var wire = aiQueueWire();
279
+ var json = JSON.stringify(wire);
280
+ if (json === aiQueueSavedJson) return;
281
+ aiQueueSavedJson = json;
282
+ axios.post(base + '/ai_queue', { queue: wire })["catch"](function () { aiQueueSavedJson = null; });
283
+ }, 500);
284
+ };
285
+
238
286
  var AiRoundTripModal = function AiRoundTripModal(_ref) {
239
287
  var h = React.createElement;
240
288
  var treeData = _ref.treeData || [];
@@ -318,13 +366,13 @@ var AiRoundTripModal = function AiRoundTripModal(_ref) {
318
366
  setMigrated(true);
319
367
  }, []);
320
368
 
321
- // Apply queue (component state only). qRef mirrors it so a sequence of
369
+ // Apply queue, restored from aiKeptQueue. qRef mirrors it so a sequence of
322
370
  // applies reads what the previous step wrote.
323
- var _queue = React.useState([]);
371
+ var _queue = React.useState(aiKeptQueue.queue);
324
372
  var queue = _queue[0];
325
373
  var setQueue = _queue[1];
326
- var qRef = React.useRef([]);
327
- var _selId = React.useState(null);
374
+ var qRef = React.useRef(aiKeptQueue.queue);
375
+ var _selId = React.useState(aiKeptQueue.selId);
328
376
  var selId = _selId[0];
329
377
  var setSelId = _selId[1];
330
378
  var _draft = React.useState('');
@@ -333,8 +381,8 @@ var AiRoundTripModal = function AiRoundTripModal(_ref) {
333
381
  var _result = React.useState({ text: '', error: false, busy: false });
334
382
  var result = _result[0];
335
383
  var setResult = _result[1];
336
- var nextId = React.useRef(1);
337
- var pastedCount = React.useRef(0);
384
+ var nextId = React.useRef(aiKeptQueue.nextId);
385
+ var pastedCount = React.useRef(aiKeptQueue.pasted);
338
386
 
339
387
  var knownPaths = React.useMemo(function () { return aiKnownPaths(treeData, {}); }, [treeData]);
340
388
 
@@ -600,6 +648,7 @@ var AiRoundTripModal = function AiRoundTripModal(_ref) {
600
648
 
601
649
  var upd = function (id, fields) {
602
650
  qRef.current = qRef.current.map(function (e) { return e.id === id ? Object.assign({}, e, fields) : e; });
651
+ aiKeptQueue.queue = qRef.current;
603
652
  setQueue(qRef.current);
604
653
  };
605
654
  var entryOf = function (id) { return qRef.current.filter(function (e) { return e.id === id; })[0]; };
@@ -647,6 +696,7 @@ var AiRoundTripModal = function AiRoundTripModal(_ref) {
647
696
  qRef.current = qRef.current.concat({ id: id, name: name, patch: it.text, status: 'checking' });
648
697
  return id;
649
698
  });
699
+ aiKeptQueue.queue = qRef.current;
650
700
  setQueue(qRef.current);
651
701
  setSelId(function (cur) { return cur || ids[0]; });
652
702
  ids.forEach(checkEntry);
@@ -677,6 +727,35 @@ var AiRoundTripModal = function AiRoundTripModal(_ref) {
677
727
  }, Promise.resolve());
678
728
  };
679
729
 
730
+ // The queue itself is written to aiKeptQueue beside every setQueue, so an
731
+ // apply that closes the dialog in the same tick is still kept.
732
+ React.useEffect(function () {
733
+ Object.assign(aiKeptQueue, { selId: selId, nextId: nextId.current, pasted: pastedCount.current });
734
+ }, [queue, selId]);
735
+
736
+ // Save when the persisted fields change (the timer outlives the dialog).
737
+ React.useEffect(function () { aiScheduleQueueSave(base); }, [queue]);
738
+
739
+ // Opened: on the first open this page, load the saved queue first. Then an
740
+ // entry not yet applied may no longer match the workspace, and one still
741
+ // checking when the dialog closed never got its answer.
742
+ React.useEffect(function () {
743
+ var alive = true;
744
+ aiLoadQueue(base).then(function () {
745
+ if (!alive) return;
746
+ if (!qRef.current.length && aiKeptQueue.queue.length) {
747
+ qRef.current = aiKeptQueue.queue;
748
+ nextId.current = aiKeptQueue.nextId;
749
+ setQueue(qRef.current);
750
+ setSelId(aiKeptQueue.selId);
751
+ }
752
+ qRef.current.filter(function (e) { return e.status !== 'applied'; }).reduce(function (chain, e) {
753
+ return chain.then(function () { return checkEntry(e.id); });
754
+ }, Promise.resolve());
755
+ });
756
+ return function () { alive = false; };
757
+ }, []);
758
+
680
759
  // Resolves true when the entry was applied. Closing is left to the caller.
681
760
  var applyEntry = function (id, skipConflicts) {
682
761
  var e = entryOf(id);
@@ -937,6 +1016,7 @@ var AiRoundTripModal = function AiRoundTripModal(_ref) {
937
1016
  onClick: function (ev) {
938
1017
  ev.stopPropagation();
939
1018
  qRef.current = qRef.current.filter(function (q) { return q.id !== e.id; });
1019
+ aiKeptQueue.queue = qRef.current;
940
1020
  setQueue(qRef.current);
941
1021
  if (selId === e.id) setSelId(qRef.current[0] ? qRef.current[0].id : null);
942
1022
  }
@@ -415,6 +415,29 @@ module Mbeditor
415
415
  render json: { error: "State payload too large" }, status: :content_too_large
416
416
  end
417
417
 
418
+ # GET /mbeditor/ai_queue — the AI dialog's apply queue ([] before a save).
419
+ def ai_queue
420
+ render json: { queue: editor_state_service.read_ai_queue }
421
+ end
422
+
423
+ # POST /mbeditor/ai_queue — JSON { queue: [{ name, patch, status, appliedAt? }] }
424
+ def save_ai_queue
425
+ raw = params.to_unsafe_h[:queue]
426
+ unless raw.is_a?(Array) && raw.all?(Hash)
427
+ return render json: { error: "queue must be an array of objects" }, status: :unprocessable_content
428
+ end
429
+
430
+ entries = raw.first(EditorStateService::AI_QUEUE_MAX_ENTRIES).map do |e|
431
+ entry = %w[name patch status].to_h { |k| [k, e[k].is_a?(String) ? e[k] : ""] }
432
+ entry["appliedAt"] = e["appliedAt"] if e["appliedAt"].is_a?(String)
433
+ entry
434
+ end
435
+ editor_state_service.write_ai_queue(entries)
436
+ render json: { ok: true }
437
+ rescue EditorStateService::PayloadTooLargeError
438
+ render json: { error: "Queue too large" }, status: :content_too_large
439
+ end
440
+
418
441
  # GET /mbeditor/ai_prompt — the editable guidance part of the AI prompt.
419
442
  def ai_prompt
420
443
  render json: { text: AiBundleService.new(workspace_root).instructions }
@@ -97,8 +97,31 @@ module Mbeditor
97
97
  nil
98
98
  end
99
99
 
100
+ # The AI dialog's apply queue (patch text is stored, never interpreted).
101
+ AI_QUEUE_MAX_ENTRIES = 50
102
+ AI_QUEUE_MAX_PATCH_BYTES = 5 * 1024 * 1024
103
+
104
+ def read_ai_queue
105
+ queue = locked_json_file(ai_queue_path).read["queue"]
106
+ queue.is_a?(Array) ? queue : []
107
+ rescue JSON::ParserError, Errno::ENOENT
108
+ []
109
+ end
110
+
111
+ def write_ai_queue(entries)
112
+ queue = entries.first(AI_QUEUE_MAX_ENTRIES)
113
+ raise PayloadTooLargeError, "Queue too large" if queue.sum { |e| e["patch"].bytesize } > AI_QUEUE_MAX_PATCH_BYTES
114
+ file = locked_json_file(ai_queue_path)
115
+ file.with_lock { file.write({ "queue" => queue }.to_json) }
116
+ nil
117
+ end
118
+
100
119
  private
101
120
 
121
+ def ai_queue_path
122
+ @root.join("tmp", "mbeditor_ai_queue.json")
123
+ end
124
+
102
125
  def ai_selection_path
103
126
  @root.join("tmp", "mbeditor_ai_selection.json")
104
127
  end
@@ -18,6 +18,8 @@ module Mbeditor
18
18
  post 'ai_bundle', to: 'editors#ai_bundle'
19
19
  get 'ai_selection', to: 'editors#ai_selection'
20
20
  post 'ai_selection', to: 'editors#save_ai_selection'
21
+ get 'ai_queue', to: 'editors#ai_queue'
22
+ post 'ai_queue', to: 'editors#save_ai_queue'
21
23
  get 'ai_prompt', to: 'editors#ai_prompt'
22
24
  post 'ai_prompt', to: 'editors#save_ai_prompt'
23
25
  post 'apply_patch', to: 'editors#apply_patch'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mbeditor
4
- VERSION = "0.15.2"
4
+ VERSION = "0.15.3"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mbeditor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.2
4
+ version: 0.15.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oliver Noonan