reslop 0.1.9 → 0.2.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.
Files changed (96) hide show
  1. package/CHANGELOG.md +25 -1
  2. package/README.md +3 -1
  3. package/bin/reslop.js +2 -2
  4. package/lib/ansi.js +148 -5
  5. package/lib/api.js +4 -2
  6. package/lib/capabilities.js +13 -14
  7. package/lib/cli.js +38 -49
  8. package/lib/clipboard.js +1 -1
  9. package/lib/{deps/changes.js → deps-diff.js} +309 -19
  10. package/lib/deps.js +498 -29
  11. package/lib/detect.js +1 -7
  12. package/lib/diff/align.js +7 -10
  13. package/lib/diff/diff.js +53 -0
  14. package/lib/diff/display.js +5 -4
  15. package/lib/diff/inline.js +26 -21
  16. package/lib/diff/items.js +6 -4
  17. package/lib/diff/patch.js +1 -3
  18. package/lib/diff/unit.js +392 -0
  19. package/lib/files.js +5 -8
  20. package/lib/{git/branches.js → git-branches.js} +191 -11
  21. package/lib/{git/dependencies.js → git-deps.js} +111 -38
  22. package/lib/git-reword-todo.js +20 -0
  23. package/lib/git.js +606 -68
  24. package/lib/github.js +28 -197
  25. package/lib/gitlab.js +24 -195
  26. package/lib/highlight/bash.js +1 -3
  27. package/lib/highlight/css.js +1 -3
  28. package/lib/highlight/js.js +11 -14
  29. package/lib/highlight.js +6 -9
  30. package/lib/keys.js +14 -8
  31. package/lib/manifest.js +330 -0
  32. package/lib/remote.js +374 -0
  33. package/lib/render/branches.js +18 -100
  34. package/lib/render/chrome.js +71 -14
  35. package/lib/render/commits.js +69 -60
  36. package/lib/render/diff.js +20 -20
  37. package/lib/render/files.js +6 -34
  38. package/lib/render/frame.js +36 -13
  39. package/lib/render/notes.js +26 -8
  40. package/lib/render/primitives.js +99 -11
  41. package/lib/{render.js → render/render.js} +8 -8
  42. package/lib/render/unit.js +41 -0
  43. package/lib/review-merge.js +270 -0
  44. package/lib/review.js +782 -14
  45. package/lib/select.js +5 -10
  46. package/lib/session/accessors.js +9 -1
  47. package/lib/session/actions.js +61 -18
  48. package/lib/session/branches.js +116 -128
  49. package/lib/session/change-actions.js +202 -123
  50. package/lib/session/commit.js +201 -115
  51. package/lib/session/compose.js +181 -15
  52. package/lib/session/dispatch.js +110 -60
  53. package/lib/session/files-pane.js +156 -148
  54. package/lib/session/items.js +22 -30
  55. package/lib/session/lifecycle.js +151 -54
  56. package/lib/session/load.js +19 -33
  57. package/lib/session/navigation.js +12 -1
  58. package/lib/session/ops.js +28 -41
  59. package/lib/session/pointer.js +57 -57
  60. package/lib/session/review.js +23 -37
  61. package/lib/session/terminal.js +6 -12
  62. package/lib/session/todos.js +37 -13
  63. package/lib/session/unit.js +208 -0
  64. package/lib/session/update.js +33 -46
  65. package/lib/session/view.js +78 -9
  66. package/lib/session/watch.js +128 -24
  67. package/lib/session.js +22 -246
  68. package/lib/source.js +3 -3
  69. package/lib/update.js +40 -75
  70. package/lib/{git/proc.js → utilities.js} +75 -11
  71. package/lib/wrap.js +1 -3
  72. package/package.json +2 -2
  73. package/lib/deps/items.js +0 -134
  74. package/lib/deps/manifest.js +0 -152
  75. package/lib/deps/merge.js +0 -120
  76. package/lib/deps/proposals.js +0 -164
  77. package/lib/deps/reports.js +0 -180
  78. package/lib/deps/rows.js +0 -176
  79. package/lib/deps/scan.js +0 -138
  80. package/lib/deps/usage.js +0 -68
  81. package/lib/deps/versions.js +0 -119
  82. package/lib/diff.js +0 -33
  83. package/lib/git/changes.js +0 -164
  84. package/lib/git/read.js +0 -253
  85. package/lib/git/run.js +0 -100
  86. package/lib/npm/commands.js +0 -100
  87. package/lib/remote/changes.js +0 -37
  88. package/lib/remote/headers.js +0 -36
  89. package/lib/remote/http.js +0 -122
  90. package/lib/remote/notes.js +0 -94
  91. package/lib/review/format.js +0 -434
  92. package/lib/review/storage.js +0 -150
  93. package/lib/review/store.js +0 -178
  94. package/lib/review/templates.js +0 -49
  95. package/lib/session/origins.js +0 -7
  96. package/lib/sys.js +0 -84
@@ -1,434 +0,0 @@
1
- 'use strict';
2
-
3
- const path = require('node:path');
4
-
5
- const { TODO_FILE } = require('../files.js');
6
- const store = require('./store.js');
7
- const { createStore, feedbackKey } = store;
8
-
9
- const REVIEW_STATUSES = ['editing', 'ready', 'partial', 'done'];
10
- const FEED_HEAD = /^### Feedback `([^`]+)` \+(\d+) \((.*)\)\s*$/;
11
- const FEED_BLOCK = /^(.*), block (\d+)$/;
12
- const FEED_BLOCK_ONLY = /^block (\d+)$/;
13
- const FEED_META = /^<!-- reslop:(.*) -->\s*$/;
14
- const FEED_SUFFIX = /^(.*) - (.+):(\d+):(\d+):(\d+)$/;
15
- const CHECK_ITEM = /^- \[([ xX])\] (.*)$/;
16
- const CODE_HEAD = /^- \[([ xX])\] code `([^`]+)`\s*$/;
17
- const FENCE_LINE = /^(`{3,})\s*$/;
18
- const FILE_QUOTE = /^> (.+)$/;
19
- const STATUS_LINE = /^status:\s*(\S+)\s*$/;
20
- const GIT_ORIGINS = ['unstaged', 'staged', 'untracked', 'commit', 'pr'];
21
- const SECTION_LINE = {
22
- '### Todo': 'todo',
23
- '### Feedback': 'feedback',
24
- };
25
-
26
- const AGENT_INSTRUCTIONS = [
27
- 'Execute reviews with `status: ready` or `status: partial`.',
28
- 'Do not start `editing` or `done` review files.',
29
- 'Work through unchecked items. After finishing one, mark it `[x]`.',
30
- 'For `code` items, replace added lines at that location with the fence.',
31
- 'Set `status` to `partial` if some remain, or `done` if all are `[x]`.',
32
- 'Do not redo items already marked `[x]`.',
33
- ].join('\n');
34
-
35
- const toInt = (text) => parseInt(text, 10);
36
-
37
- const canonicalStatus = (raw) => {
38
- if (!raw) return '';
39
- const name = raw === 'pending' ? 'ready' : raw;
40
- if (REVIEW_STATUSES.includes(name)) return name;
41
- return '';
42
- };
43
-
44
- const parseFrontmatterStatus = (text) => {
45
- if (!text.startsWith('---')) return '';
46
- const nl = text.indexOf('\n');
47
- if (nl < 0) return '';
48
- const rest = text.slice(nl + 1);
49
- const end = rest.indexOf('\n---');
50
- if (end < 0) return '';
51
- const matter = rest.slice(0, end);
52
- for (const line of matter.split('\n')) {
53
- const match = STATUS_LINE.exec(line);
54
- if (match) return canonicalStatus(match[1]);
55
- }
56
- return '';
57
- };
58
-
59
- const isDoneMark = (mark) => mark === 'x' || mark === 'X';
60
-
61
- const pushTodo = (builder, file, text, done) => {
62
- const id = builder.nextTodoId;
63
- builder.nextTodoId += 1;
64
- builder.todos.push({ id, file, text, done });
65
- };
66
-
67
- const checkboxLine = (text, done) => {
68
- const flat = text.trim().replace(/\n/g, ' ');
69
- const mark = done ? 'x' : ' ';
70
- return `- [${mark}] ${flat}`;
71
- };
72
-
73
- const storeFeedback = (builder, note, key) => {
74
- const next = {
75
- file: note.file,
76
- oldStart: note.oldStart ?? 0,
77
- newStart: note.newStart ?? 0,
78
- blockId: note.blockId ?? 0,
79
- origin: note.origin ?? '',
80
- header: note.header ?? '',
81
- text: note.text,
82
- done: note.done ?? false,
83
- };
84
- builder.feedback.set(key || feedbackKey(next), next);
85
- };
86
-
87
- const storeCode = (builder, note, key) => {
88
- const next = {
89
- file: note.file,
90
- oldStart: note.oldStart ?? 0,
91
- newStart: note.newStart ?? 0,
92
- blockId: note.blockId ?? 0,
93
- origin: note.origin ?? '',
94
- header: note.header ?? '',
95
- text: note.text,
96
- done: note.done ?? false,
97
- };
98
- builder.code.set(key || feedbackKey(next), next);
99
- };
100
-
101
- const feedbackLine = (note) => {
102
- const loc = feedbackKey(note);
103
- return `${checkboxLine(note.text, note.done)} - ${loc}`;
104
- };
105
-
106
- const parseLoc = (raw) => {
107
- const parts = raw.split(':');
108
- const n = parts.length;
109
- if (n < 4) return null;
110
- const blockId = toInt(parts[n - 1]);
111
- const newStart = toInt(parts[n - 2]);
112
- const oldStart = toInt(parts[n - 3]);
113
- if (!Number.isFinite(blockId + newStart + oldStart)) return null;
114
- let fileParts = parts.slice(0, n - 3);
115
- let origin = '';
116
- if (fileParts.length > 1 && GIT_ORIGINS.includes(fileParts[0])) {
117
- origin = fileParts[0];
118
- fileParts = fileParts.slice(1);
119
- }
120
- if (!fileParts.length) return null;
121
- const file = fileParts.join(':');
122
- return { origin, file, oldStart, newStart, blockId };
123
- };
124
-
125
- const parseFeedSuffix = (textItem) => {
126
- const match = FEED_SUFFIX.exec(textItem);
127
- if (!match) return null;
128
- const text = match[1];
129
- const file = match[2];
130
- const oldStart = toInt(match[3]);
131
- const newStart = toInt(match[4]);
132
- const blockId = toInt(match[5]);
133
- return { text, file, oldStart, newStart, blockId };
134
- };
135
-
136
- const fileGroup = (groups, file) => {
137
- let group = groups.get(file);
138
- if (!group) {
139
- group = { todos: [], feedback: [], code: [] };
140
- groups.set(file, group);
141
- }
142
- return group;
143
- };
144
-
145
- const groupReviewNotes = (notes) => {
146
- const groups = new Map();
147
- for (const todo of notes.todos) {
148
- if (!todo.text.trim()) continue;
149
- fileGroup(groups, TODO_FILE).todos.push(todo);
150
- }
151
- for (const key of notes.feedback.keys()) {
152
- const note = notes.feedback.get(key);
153
- if (!note.text.trim()) continue;
154
- fileGroup(groups, note.file).feedback.push({ key, note });
155
- }
156
- for (const key of notes.code.keys()) {
157
- const note = notes.code.get(key);
158
- fileGroup(groups, note.file).code.push({ key, note });
159
- }
160
- return groups;
161
- };
162
-
163
- const reviewHeader = (notes) => {
164
- const name = path.basename(notes.reviewPath, '.md');
165
- const status = canonicalStatus(notes.status) || 'editing';
166
- return [
167
- '---',
168
- `status: ${status}`,
169
- '---',
170
- '',
171
- `# reslop review ${name}`,
172
- '',
173
- '## Agent instructions',
174
- '',
175
- AGENT_INSTRUCTIONS,
176
- '',
177
- ];
178
- };
179
-
180
- const fenceFor = (text) => {
181
- let n = 3;
182
- for (const line of text.split('\n')) {
183
- const match = /^(`{3,})/.exec(line);
184
- if (!match) continue;
185
- if (match[1].length >= n) n = match[1].length + 1;
186
- }
187
- return '`'.repeat(n);
188
- };
189
-
190
- const emitCodeItem = (lines, note) => {
191
- const loc = feedbackKey(note);
192
- const mark = note.done ? 'x' : ' ';
193
- const fence = fenceFor(note.text);
194
- lines.push(`- [${mark}] code \`${loc}\``);
195
- lines.push(fence);
196
- if (note.text !== '') lines.push(note.text);
197
- lines.push(fence);
198
- };
199
-
200
- const emitReviewGroups = (lines, groups) => {
201
- for (const file of groups.keys()) {
202
- const group = groups.get(file);
203
- lines.push(`## ${file}`);
204
- lines.push('');
205
- for (const todo of group.todos) {
206
- lines.push(checkboxLine(todo.text, todo.done));
207
- }
208
- for (const item of group.feedback) {
209
- lines.push(feedbackLine(item.note));
210
- }
211
- for (const item of group.code) {
212
- emitCodeItem(lines, item.note);
213
- }
214
- lines.push('');
215
- }
216
- };
217
-
218
- const serializeReview = (notes) => {
219
- const lines = reviewHeader(notes);
220
- emitReviewGroups(lines, groupReviewNotes(notes));
221
- return `${lines.join('\n')}\n`;
222
- };
223
-
224
- const parseFeedbackHeading = (line) => {
225
- const match = FEED_HEAD.exec(line);
226
- if (!match) return null;
227
- const file = match[1];
228
- const newStart = toInt(match[2]);
229
- const rest = match[3];
230
- const only = FEED_BLOCK_ONLY.exec(rest);
231
- if (only) {
232
- return { file, newStart, header: '', blockId: toInt(only[1]) };
233
- }
234
- const withHead = FEED_BLOCK.exec(rest);
235
- if (!withHead) {
236
- return { file, newStart, header: rest, blockId: 0 };
237
- }
238
- const header = withHead[1];
239
- const blockId = toInt(withHead[2]);
240
- return { file, newStart, header, blockId };
241
- };
242
-
243
- const flushPendingFeedback = (builder, pending) => {
244
- if (!pending || !(pending.text ?? '').trim()) return null;
245
- storeFeedback(builder, pending, pending.key);
246
- return null;
247
- };
248
-
249
- const headingFile = (line) => {
250
- const quoted = FILE_QUOTE.exec(line);
251
- if (quoted) return quoted[1];
252
- if (line.startsWith('## ') && line !== '## Agent instructions') {
253
- return line.slice(3);
254
- }
255
- return null;
256
- };
257
-
258
- const startFeedbackPending = (heading, file) => ({
259
- file: heading.file || file,
260
- newStart: heading.newStart,
261
- header: heading.header,
262
- blockId: heading.blockId,
263
- oldStart: heading.newStart,
264
- origin: '',
265
- key: '',
266
- text: '',
267
- });
268
-
269
- const applyFeedMeta = (pending, raw) => {
270
- const loc = parseLoc(raw);
271
- if (!loc) return pending;
272
- pending.origin = loc.origin;
273
- pending.file = loc.file;
274
- pending.oldStart = loc.oldStart;
275
- pending.newStart = loc.newStart;
276
- pending.blockId = loc.blockId;
277
- pending.key = feedbackKey(loc);
278
- return pending;
279
- };
280
-
281
- const applyCheckItem = (builder, file, section, pending, textItem, done) => {
282
- if (section === 'todo' && file) {
283
- pushTodo(builder, file, textItem, done);
284
- return pending;
285
- }
286
- const parsed = parseFeedSuffix(textItem);
287
- if (parsed) {
288
- flushPendingFeedback(builder, pending);
289
- storeFeedback(builder, {
290
- file: parsed.file || file,
291
- oldStart: parsed.oldStart,
292
- newStart: parsed.newStart,
293
- blockId: parsed.blockId,
294
- origin: '',
295
- header: '',
296
- text: parsed.text,
297
- done,
298
- });
299
- return null;
300
- }
301
- if (pending) {
302
- pending.text = textItem;
303
- pending.done = done;
304
- return flushPendingFeedback(builder, pending);
305
- }
306
- if (file && section !== 'feedback') {
307
- pushTodo(builder, file, textItem, done);
308
- }
309
- return pending;
310
- };
311
-
312
- const applyReviewLine = (builder, file, section, pending, line) => {
313
- const nextFile = headingFile(line);
314
- if (nextFile !== null) {
315
- pending = flushPendingFeedback(builder, pending);
316
- return { file: nextFile, section: '', pending };
317
- }
318
- const nextSection = SECTION_LINE[line];
319
- if (nextSection) {
320
- pending = flushPendingFeedback(builder, pending);
321
- return { file, section: nextSection, pending };
322
- }
323
- const heading = parseFeedbackHeading(line);
324
- if (heading) {
325
- flushPendingFeedback(builder, pending);
326
- pending = startFeedbackPending(heading, file);
327
- return { file, section: 'feedback', pending };
328
- }
329
- const meta = FEED_META.exec(line);
330
- if (meta && pending) {
331
- pending = applyFeedMeta(pending, meta[1]);
332
- return { file, section, pending };
333
- }
334
- const item = CHECK_ITEM.exec(line);
335
- if (!item) return { file, section, pending };
336
- const done = isDoneMark(item[1]);
337
- pending = applyCheckItem(builder, file, section, pending, item[2], done);
338
- return { file, section, pending };
339
- };
340
-
341
- const startCodePending = (line) => {
342
- const match = CODE_HEAD.exec(line);
343
- if (!match) return null;
344
- const loc = parseLoc(match[2]);
345
- if (!loc) return null;
346
- return {
347
- done: isDoneMark(match[1]),
348
- origin: loc.origin,
349
- file: loc.file,
350
- oldStart: loc.oldStart,
351
- newStart: loc.newStart,
352
- blockId: loc.blockId,
353
- open: '',
354
- lines: [],
355
- };
356
- };
357
-
358
- const storeCodeNote = (builder, pending, text) => {
359
- storeCode(builder, {
360
- file: pending.file,
361
- oldStart: pending.oldStart,
362
- newStart: pending.newStart,
363
- blockId: pending.blockId,
364
- origin: pending.origin,
365
- header: '',
366
- text,
367
- done: pending.done,
368
- });
369
- };
370
-
371
- const flushPendingCode = (builder, pending) => {
372
- if (!pending) return;
373
- const text = pending.open ? pending.lines.join('\n') : '';
374
- storeCodeNote(builder, pending, text);
375
- };
376
-
377
- const takeCodeLine = (builder, pending, line) => {
378
- const fence = FENCE_LINE.exec(line);
379
- if (!pending.open) {
380
- if (fence) {
381
- pending.open = fence[1];
382
- return pending;
383
- }
384
- if (!line.trim()) return pending;
385
- storeCodeNote(builder, pending, '');
386
- return 'fallthrough';
387
- }
388
- if (fence && fence[1].length >= pending.open.length) {
389
- storeCodeNote(builder, pending, pending.lines.join('\n'));
390
- return null;
391
- }
392
- pending.lines.push(line);
393
- return pending;
394
- };
395
-
396
- const parseReview = (text, reviewPath, templates = []) => {
397
- const builder = createStore(reviewPath, templates);
398
- builder.status = parseFrontmatterStatus(text) || 'editing';
399
- let file = '';
400
- let section = '';
401
- let pending = null;
402
- let pendingCode = null;
403
- for (const line of text.split('\n')) {
404
- if (pendingCode) {
405
- const nextCode = takeCodeLine(builder, pendingCode, line);
406
- if (nextCode === 'fallthrough') {
407
- pendingCode = null;
408
- } else {
409
- pendingCode = nextCode;
410
- continue;
411
- }
412
- }
413
- const started = startCodePending(line);
414
- if (started) {
415
- pending = flushPendingFeedback(builder, pending);
416
- pendingCode = started;
417
- continue;
418
- }
419
- const next = applyReviewLine(builder, file, section, pending, line);
420
- file = next.file;
421
- section = next.section;
422
- pending = next.pending;
423
- }
424
- flushPendingCode(builder, pendingCode);
425
- flushPendingFeedback(builder, pending);
426
- builder.dirty = false;
427
- return builder;
428
- };
429
-
430
- module.exports = {
431
- parseFrontmatterStatus,
432
- serializeReview,
433
- parseReview,
434
- };
@@ -1,150 +0,0 @@
1
- 'use strict';
2
-
3
- const fs = require('node:fs');
4
- const path = require('node:path');
5
-
6
- const { REVIEW_DIR } = require('../files.js');
7
- const format = require('./format.js');
8
- const { serializeReview, parseReview, parseFrontmatterStatus } = format;
9
- const { hasNotes } = require('./store.js');
10
-
11
- const TEMPLATES_FILE = 'templates.json';
12
- const AUTOSAVE_MS = 3000;
13
- const REVIEW_NAME = /^(\d{4}-\d{2}-\d{2})-(\d+)\.md$/;
14
-
15
- const toInt = (text) => parseInt(text, 10);
16
-
17
- const pad2 = (n) => `${n}`.padStart(2, '0');
18
-
19
- const padIndex = (n) => (n < 100 ? pad2(n) : `${n}`);
20
-
21
- const dateStamp = (date) => {
22
- const y = date.getFullYear();
23
- const month = pad2(date.getMonth() + 1);
24
- const day = pad2(date.getDate());
25
- return `${y}-${month}-${day}`;
26
- };
27
-
28
- const allocateReviewPath = (dir, date, existingNames) => {
29
- const stamp = dateStamp(date);
30
- let max = -1;
31
- for (const name of existingNames) {
32
- const match = REVIEW_NAME.exec(name);
33
- if (!match) continue;
34
- if (match[1] !== stamp) continue;
35
- const n = toInt(match[2]);
36
- if (n > max) max = n;
37
- }
38
- const file = `${stamp}-${padIndex(max + 1)}.md`;
39
- return path.join(dir, REVIEW_DIR, file);
40
- };
41
-
42
- const listReviewNames = (dir, readdirSync = fs.readdirSync) => {
43
- const folder = path.join(dir, REVIEW_DIR);
44
- try {
45
- return readdirSync(folder);
46
- } catch {
47
- return [];
48
- }
49
- };
50
-
51
- const compareReviewNames = (left, right) => {
52
- const a = REVIEW_NAME.exec(left);
53
- const b = REVIEW_NAME.exec(right);
54
- if (!a && !b) return 0;
55
- if (!a) return -1;
56
- if (!b) return 1;
57
- if (a[1] < b[1]) return -1;
58
- if (a[1] > b[1]) return 1;
59
- return toInt(a[2]) - toInt(b[2]);
60
- };
61
-
62
- const latestReviewName = (names) => {
63
- let best = '';
64
- for (const name of names) {
65
- if (!REVIEW_NAME.test(name)) continue;
66
- if (!best || compareReviewNames(name, best) > 0) best = name;
67
- }
68
- return best;
69
- };
70
-
71
- const readReviewStatus = (reviewPath, readFileSync = fs.readFileSync) => {
72
- try {
73
- const text = readFileSync(reviewPath, 'utf8');
74
- return parseFrontmatterStatus(text);
75
- } catch {
76
- return '';
77
- }
78
- };
79
-
80
- const resolveReviewPath = (dir, date, existingNames, options = {}) => {
81
- const forceNew = options.forceNew ?? false;
82
- const readFileSync = options.readFileSync ?? fs.readFileSync;
83
- if (!forceNew) {
84
- const latest = latestReviewName(existingNames);
85
- if (latest) {
86
- const reviewPath = path.join(dir, REVIEW_DIR, latest);
87
- const status = readReviewStatus(reviewPath, readFileSync);
88
- if (status === 'editing') return { reviewPath, resume: true };
89
- }
90
- }
91
- const reviewPath = allocateReviewPath(dir, date, existingNames);
92
- const resume = false;
93
- return { reviewPath, resume };
94
- };
95
-
96
- const loadReview = (reviewPath, templates, readFileSync = fs.readFileSync) => {
97
- const raw = readFileSync(reviewPath, 'utf8');
98
- return parseReview(raw, reviewPath, templates);
99
- };
100
-
101
- const loadTemplates = (dir, readFileSync = fs.readFileSync) => {
102
- const file = path.join(dir, REVIEW_DIR, TEMPLATES_FILE);
103
- try {
104
- const raw = readFileSync(file, 'utf8');
105
- const data = JSON.parse(raw);
106
- if (!Array.isArray(data)) return [];
107
- const templates = [];
108
- for (const entry of data) {
109
- if (!entry || typeof entry.text !== 'string') continue;
110
- const count = toInt(entry.count);
111
- templates.push({
112
- text: entry.text,
113
- count: Number.isFinite(count) ? count : 1,
114
- });
115
- }
116
- return templates;
117
- } catch {
118
- return [];
119
- }
120
- };
121
-
122
- const flushReview = (notes, io = {}) => {
123
- const writeFileSync = io.writeFileSync ?? fs.writeFileSync;
124
- const mkdirSync = io.mkdirSync ?? fs.mkdirSync;
125
- if (!notes || !notes.dirty) return false;
126
- if (!hasNotes(notes) && !io.force) {
127
- notes.dirty = false;
128
- return false;
129
- }
130
- const folder = path.dirname(notes.reviewPath);
131
- mkdirSync(folder, { recursive: true });
132
- writeFileSync(notes.reviewPath, serializeReview(notes), 'utf8');
133
- const top = path.dirname(folder);
134
- const templatesFile = path.join(top, REVIEW_DIR, TEMPLATES_FILE);
135
- const body = `${JSON.stringify(notes.templates, null, 2)}\n`;
136
- writeFileSync(templatesFile, body, 'utf8');
137
- notes.dirty = false;
138
- return true;
139
- };
140
-
141
- module.exports = {
142
- AUTOSAVE_MS,
143
- allocateReviewPath,
144
- listReviewNames,
145
- latestReviewName,
146
- resolveReviewPath,
147
- loadReview,
148
- loadTemplates,
149
- flushReview,
150
- };