reslop 0.2.7 → 0.3.0

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 (158) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/README.md +16 -14
  3. package/bin/reslop.js +8 -5
  4. package/lib/agents/agents.js +504 -0
  5. package/lib/agents/allow.js +71 -0
  6. package/lib/agents/allow.json +16 -0
  7. package/lib/agents/models.js +460 -0
  8. package/lib/api.js +15 -12
  9. package/lib/cli.js +43 -68
  10. package/lib/{files.js → common/files.js} +48 -55
  11. package/lib/{find.js → common/find.js} +1 -1
  12. package/lib/common/format.js +101 -0
  13. package/lib/{utilities.js → common/process.js} +7 -95
  14. package/lib/common/tasks.json +27 -0
  15. package/lib/common/utilities.js +112 -0
  16. package/lib/dashboard/git.js +9 -16
  17. package/lib/dashboard/model.js +90 -49
  18. package/lib/dashboard/npm.js +17 -13
  19. package/lib/dashboard/tree.js +27 -30
  20. package/lib/{session → dashboard}/watch.js +36 -31
  21. package/lib/{workspace.js → dashboard/workspace.js} +23 -38
  22. package/lib/{deps.js → deps/deps.js} +31 -45
  23. package/lib/{deps-diff.js → deps/diff.js} +35 -25
  24. package/lib/{manifest.js → deps/manifest.js} +47 -30
  25. package/lib/diff/align.js +1 -2
  26. package/lib/diff/diff.js +2 -2
  27. package/lib/diff/display.js +29 -5
  28. package/lib/diff/inline.js +10 -14
  29. package/lib/diff/items.js +6 -4
  30. package/lib/diff/patch.js +39 -3
  31. package/lib/diff/unit.js +45 -16
  32. package/lib/{git-branches.js → git/branches.js} +53 -48
  33. package/lib/{git-deps.js → git/deps.js} +123 -96
  34. package/lib/git/git.js +71 -0
  35. package/lib/git/worktree.js +475 -0
  36. package/lib/highlight/bash.js +1 -2
  37. package/lib/highlight/csv.js +1 -2
  38. package/lib/highlight/dot.js +1 -2
  39. package/lib/{highlight.js → highlight/highlight.js} +42 -11
  40. package/lib/highlight/html.js +20 -18
  41. package/lib/highlight/json.js +1 -2
  42. package/lib/highlight/log.js +1 -2
  43. package/lib/highlight/txt.js +1 -2
  44. package/lib/{session → input}/actions.js +111 -48
  45. package/lib/{editor.js → input/editor.js} +7 -8
  46. package/lib/{keys.js → input/keys.js} +15 -43
  47. package/lib/input/line-edit.js +77 -0
  48. package/lib/input/menu-pick.js +70 -0
  49. package/lib/render/agents.js +640 -0
  50. package/lib/render/branches.js +4 -5
  51. package/lib/render/commits.js +54 -64
  52. package/lib/render/{dash-activity.js → dashboard/activity.js} +25 -40
  53. package/lib/render/{dash-blocks.js → dashboard/blocks.js} +131 -137
  54. package/lib/render/{dashboard.js → dashboard/dashboard.js} +25 -22
  55. package/lib/render/diff.js +166 -45
  56. package/lib/render/field.js +131 -0
  57. package/lib/render/files.js +9 -14
  58. package/lib/render/footer.js +383 -0
  59. package/lib/render/frame.js +123 -25
  60. package/lib/render/header.js +176 -0
  61. package/lib/render/log.js +319 -0
  62. package/lib/render/menu.js +60 -0
  63. package/lib/render/notes.js +16 -11
  64. package/lib/render/npm.js +322 -196
  65. package/lib/render/packages.js +9 -13
  66. package/lib/render/primitives.js +101 -15
  67. package/lib/render/render.js +7 -11
  68. package/lib/render/repos.js +13 -25
  69. package/lib/render/status.js +370 -0
  70. package/lib/render/status.json +85 -0
  71. package/lib/render/{dash-table.js → table.js} +13 -60
  72. package/lib/render/tiles.js +109 -48
  73. package/lib/render/unit.js +32 -13
  74. package/lib/{report-model.js → report/model.js} +4 -6
  75. package/lib/{report-parse.js → report/parse.js} +9 -14
  76. package/lib/{report-render.js → report/render.js} +46 -14
  77. package/lib/{report-run.js → report/run.js} +42 -30
  78. package/lib/{report-test.js → report/test.js} +56 -55
  79. package/lib/{report-tools.js → report/tools.js} +24 -33
  80. package/lib/review/agent-instructions.md +9 -0
  81. package/lib/review/format.js +426 -0
  82. package/lib/{review-merge.js → review/merge.js} +9 -8
  83. package/lib/review/review.js +190 -0
  84. package/lib/review/store.js +281 -0
  85. package/lib/review/templates.js +83 -0
  86. package/lib/runs/commands.js +14 -0
  87. package/lib/runs/logs.js +299 -0
  88. package/lib/runs/output.js +174 -0
  89. package/lib/runs/process.js +113 -0
  90. package/lib/{runs.js → runs/runs.js} +84 -36
  91. package/lib/runs/scripts.js +150 -0
  92. package/lib/session/agents/agents.js +958 -0
  93. package/lib/session/agents/job.js +320 -0
  94. package/lib/session/agents/jobs.js +355 -0
  95. package/lib/session/agents/options.js +153 -0
  96. package/lib/session/agents/plans.js +83 -0
  97. package/lib/session/branches.js +33 -39
  98. package/lib/session/change-actions.js +34 -100
  99. package/lib/session/commit.js +91 -52
  100. package/lib/session/compose.js +181 -145
  101. package/lib/session/dashboard.js +23 -22
  102. package/lib/session/dispatch.js +85 -21
  103. package/lib/session/files-pane.js +47 -26
  104. package/lib/session/find.js +16 -29
  105. package/lib/session/import.js +82 -0
  106. package/lib/session/items.js +8 -17
  107. package/lib/session/lifecycle.js +75 -72
  108. package/lib/session/load.js +2 -4
  109. package/lib/session/navigation.js +6 -3
  110. package/lib/session/npm/history.js +249 -0
  111. package/lib/session/npm/npm.js +815 -0
  112. package/lib/session/{packages.js → npm/packages.js} +21 -14
  113. package/lib/session/ops.js +125 -34
  114. package/lib/session/pointer.js +202 -10
  115. package/lib/session/prefs.js +112 -0
  116. package/lib/session/reads.js +109 -0
  117. package/lib/session/review.js +28 -10
  118. package/lib/session/run-panel.js +40 -0
  119. package/lib/{session.js → session/session.js} +156 -63
  120. package/lib/session/tasks.js +320 -65
  121. package/lib/session/templates.js +1 -1
  122. package/lib/session/terminal.js +94 -12
  123. package/lib/session/unit.js +35 -30
  124. package/lib/session/update.js +194 -6
  125. package/lib/session/view.js +65 -65
  126. package/lib/session/workspace.js +39 -78
  127. package/lib/{capabilities.js → source/capabilities.js} +3 -12
  128. package/lib/{github.js → source/github.js} +102 -32
  129. package/lib/{gitlab.js → source/gitlab.js} +87 -10
  130. package/lib/{remote.js → source/remote.js} +144 -40
  131. package/lib/source/review-threads.graphql +20 -0
  132. package/lib/source/source.js +74 -0
  133. package/lib/term/ansi.js +396 -0
  134. package/lib/{clipboard.js → term/clipboard.js} +3 -6
  135. package/lib/{select.js → term/select.js} +2 -2
  136. package/lib/term/themes/dark.json +122 -0
  137. package/lib/term/themes/light.json +122 -0
  138. package/lib/term/wide.txt +21 -0
  139. package/lib/{wrap.js → term/wrap.js} +4 -4
  140. package/package.json +2 -2
  141. package/lib/ansi.js +0 -545
  142. package/lib/detect.js +0 -34
  143. package/lib/diff/edit.js +0 -33
  144. package/lib/git-worktree.js +0 -455
  145. package/lib/git.js +0 -79
  146. package/lib/npm-commands.js +0 -522
  147. package/lib/render/chrome.js +0 -806
  148. package/lib/render/present.js +0 -19
  149. package/lib/render/report.js +0 -43
  150. package/lib/render/search.js +0 -25
  151. package/lib/review.js +0 -745
  152. package/lib/session/accessors.js +0 -26
  153. package/lib/session/edit-click.js +0 -57
  154. package/lib/session/npm.js +0 -452
  155. package/lib/session/progress.js +0 -41
  156. package/lib/source.js +0 -36
  157. package/lib/update.js +0 -192
  158. /package/lib/{git-reword-todo.js → git/reword-todo.js} +0 -0
@@ -1,455 +0,0 @@
1
- 'use strict';
2
-
3
- const fs = require('node:fs');
4
- const path = require('node:path');
5
-
6
- const utilities = require('./utilities.js');
7
- const { runProc, runProcSync, isAbort, oneLine } = utilities;
8
- const diff = require('./diff/diff.js');
9
- const { parseDiff, synthesizeNewFile, itemsFromFiles } = diff;
10
- const files = require('./files.js');
11
- const { itemPath, isReadOnlyOrigin, lineDelta, REVIEW_DIR } = files;
12
- const edit = require('./diff/edit.js');
13
- const { replaceBlockAdds } = edit;
14
-
15
- const GIT_CONFIG = [
16
- '-c',
17
- 'core.quotepath=false',
18
- '-c',
19
- 'i18n.logOutputEncoding=utf-8',
20
- ];
21
- const DIFF_OPTS = ['--no-color', '--no-ext-diff', '--no-renames', '-U3'];
22
- const BINARY_SIZE = 1000000;
23
-
24
- const gitOptions = (cwd, extra) => ({
25
- cwd,
26
- env: { ...process.env, GIT_OPTIONAL_LOCKS: '0', ...extra.env },
27
- input: extra.input,
28
- signal: extra.signal,
29
- });
30
-
31
- const gitResult = (result) => {
32
- if (!result.error) return result;
33
- if (isAbort(result.error)) throw result.error;
34
- if (result.error.code === 'ENOENT') throw new Error('git not found');
35
- throw result.error;
36
- };
37
-
38
- const requireOk = (result, fallback = 'git failed') => {
39
- if (result.status === 0) return result;
40
- const msg = result.stderr || result.stdout || fallback;
41
- throw new Error(oneLine(msg, fallback));
42
- };
43
-
44
- const runGit = (args, cwd, extra = {}) =>
45
- gitResult(runProcSync('git', args, gitOptions(cwd, extra)));
46
-
47
- const runGitAsync = (args, cwd, extra = {}) =>
48
- runProc('git', args, gitOptions(cwd, extra)).then(gitResult);
49
-
50
- const command = (args, extra = {}) => ({
51
- args,
52
- input: extra.input,
53
- env: extra.env,
54
- });
55
-
56
- const runSteps = (steps, top) => {
57
- try {
58
- let step = steps.next();
59
- while (!step.done) {
60
- step = steps.next(runGit(step.value.args, top, step.value));
61
- }
62
- return step.value;
63
- } finally {
64
- steps.return();
65
- }
66
- };
67
-
68
- const runStepsAsync = async (steps, top, signal) => {
69
- try {
70
- let step = steps.next();
71
- while (!step.done) {
72
- const extra = { ...step.value, signal };
73
- step = steps.next(await runGitAsync(step.value.args, top, extra));
74
- }
75
- return step.value;
76
- } finally {
77
- steps.return();
78
- }
79
- };
80
-
81
- const gitOp = (op) => ({
82
- sync: (top, ...args) => runSteps(op(...args), top),
83
- async: (top, ...args) => runStepsAsync(op(...args), top),
84
- });
85
-
86
- const pathArgs = (paths) => (paths.length ? ['--', ...paths] : []);
87
-
88
- const diffArgs = (revs, paths) => [
89
- ...GIT_CONFIG,
90
- 'diff',
91
- ...DIFF_OPTS,
92
- ...revs,
93
- ...pathArgs(paths),
94
- ];
95
-
96
- const commitDiffArgs = (commit, parent, paths) => {
97
- if (parent.status === 0) {
98
- return diffArgs([parent.stdout.trim(), commit], paths);
99
- }
100
- return [
101
- ...GIT_CONFIG,
102
- 'diff-tree',
103
- '--no-commit-id',
104
- '--root',
105
- '-p',
106
- ...DIFF_OPTS,
107
- commit,
108
- ...pathArgs(paths),
109
- ];
110
- };
111
-
112
- const untrackedArgs = (paths) => [
113
- 'ls-files',
114
- '-o',
115
- '--exclude-standard',
116
- '-z',
117
- ...pathArgs(paths),
118
- ];
119
-
120
- const isReviewFile = (rel) => rel.split(/[/\\]/)[0] === REVIEW_DIR;
121
-
122
- const isDirEntry = (rel) => rel.endsWith('/');
123
-
124
- const dropReviewItems = (items) =>
125
- items.filter((item) => !isReviewFile(itemPath(item)));
126
-
127
- const isBinaryBuffer = (buf) => buf.length > BINARY_SIZE || buf.includes(0);
128
-
129
- const namesFromLs = (stdout) => stdout.split('\0').filter(Boolean);
130
-
131
- const listScopeFiles = (top, paths = [], options = {}) => {
132
- const rev = options.commit;
133
- const args = rev
134
- ? ['ls-tree', '-r', '--name-only', '-z', rev, ...pathArgs(paths)]
135
- : ['ls-files', '-co', '--exclude-standard', '-z', ...pathArgs(paths)];
136
- const result = requireOk(runGit(args, top), 'ls-files failed');
137
- const names = namesFromLs(result.stdout).filter(
138
- (rel) => !isReviewFile(rel) && !isDirEntry(rel),
139
- );
140
- names.sort((left, right) => left.localeCompare(right, 'en'));
141
- return names;
142
- };
143
-
144
- const binaryNewFile = (rel) => ({
145
- oldPath: rel,
146
- newPath: rel,
147
- isNew: true,
148
- isDeleted: false,
149
- isBinary: true,
150
- preamble: [`diff --git a/${rel} b/${rel}`, 'new file mode 100644'],
151
- hunks: [],
152
- });
153
-
154
- const untrackedItemsFrom = (top, names) => {
155
- const files = [];
156
- for (const rel of names) {
157
- if (isReviewFile(rel) || isDirEntry(rel)) continue;
158
- let buf;
159
- try {
160
- buf = fs.readFileSync(path.join(top, rel));
161
- } catch (error) {
162
- if (error.code === 'ENOENT' || error.code === 'EISDIR') continue;
163
- throw error;
164
- }
165
- if (isBinaryBuffer(buf)) files.push(binaryNewFile(rel));
166
- else files.push(synthesizeNewFile(rel, buf.toString('utf8')));
167
- }
168
- return itemsFromFiles(files, 'untracked');
169
- };
170
-
171
- const countUntrackedAdded = async (top) => {
172
- try {
173
- const result = await runGitAsync(untrackedArgs([]), top);
174
- if (result.status !== 0) return 0;
175
- const items = untrackedItemsFrom(top, namesFromLs(result.stdout));
176
- let added = 0;
177
- for (const item of items) added += lineDelta(item).added;
178
- return added;
179
- } catch {
180
- return 0;
181
- }
182
- };
183
-
184
- const groupByPath = (items) => {
185
- const byPath = new Map();
186
- for (const item of items) {
187
- const rel = itemPath(item);
188
- const list = byPath.get(rel);
189
- if (list) list.push(item);
190
- else byPath.set(rel, [item]);
191
- }
192
- return byPath;
193
- };
194
-
195
- const gitText = (top, spec) => {
196
- const result = runGit(['show', spec], top);
197
- return result.status === 0 ? result.stdout : '';
198
- };
199
-
200
- const worktreeText = (top, rel) => {
201
- try {
202
- return fs.readFileSync(path.join(top, rel), 'utf8');
203
- } catch {
204
- return '';
205
- }
206
- };
207
-
208
- const fileText = (top, rel, rev) => {
209
- if (!rel) return '';
210
- if (rev) return gitText(top, `${rev}:${rel}`);
211
- return worktreeText(top, rel);
212
- };
213
-
214
- const readDepSides = (top, rev, origin, rel) => {
215
- if (origin === 'untracked') {
216
- return { oldText: '', newText: worktreeText(top, rel) };
217
- }
218
- if (origin === 'staged') {
219
- const oldText = gitText(top, `HEAD:${rel}`);
220
- return { oldText, newText: gitText(top, `:${rel}`) };
221
- }
222
- if (origin === 'unstaged') {
223
- const oldText = gitText(top, `:${rel}`) || gitText(top, `HEAD:${rel}`);
224
- return { oldText, newText: worktreeText(top, rel) };
225
- }
226
- if (origin === 'commit' && rev) {
227
- const oldText = gitText(top, `${rev}^:${rel}`);
228
- return { oldText, newText: gitText(top, `${rev}:${rel}`) };
229
- }
230
- return { oldText: '', newText: '' };
231
- };
232
-
233
- const toplevel = (cwd) => {
234
- const result = runGit(['rev-parse', '--show-toplevel'], cwd);
235
- if (result.status !== 0) throw new Error('not a git repository');
236
- return result.stdout.trim();
237
- };
238
-
239
- const resolveRev = (cwd, spec) => {
240
- if (!spec) return null;
241
- const args = ['rev-parse', '--verify', `${spec}^{commit}`];
242
- const result = runGit(args, toplevel(cwd));
243
- return result.status === 0 ? result.stdout.trim() : null;
244
- };
245
-
246
- const shortRev = (top, commit) => {
247
- const result = runGit(['rev-parse', '--short', commit], top);
248
- return result.status === 0 ? result.stdout.trim() : commit.slice(0, 7);
249
- };
250
-
251
- const currentBranch = (top) => {
252
- const result = runGit(['rev-parse', '--abbrev-ref', 'HEAD'], top);
253
- if (result.status !== 0) return '';
254
- const name = result.stdout.trim();
255
- return name === 'HEAD' ? '' : name;
256
- };
257
-
258
- const snapshotWorktree = (top, results) => {
259
- const outputs = results.map((result) => requireOk(result).stdout);
260
- const staged = itemsFromFiles(parseDiff(outputs[0]), 'staged');
261
- const unstaged = itemsFromFiles(parseDiff(outputs[1]), 'unstaged');
262
- const untracked = untrackedItemsFrom(top, namesFromLs(outputs[2]));
263
- const grouped = groupByPath([...staged, ...unstaged, ...untracked]);
264
- const parsed = dropReviewItems([...grouped.values()].flat());
265
- return { top, parsed, branch: currentBranch(top) };
266
- };
267
-
268
- const snapshotCommit = (top, commit, files) => {
269
- const parsed = dropReviewItems(itemsFromFiles(files, 'commit'));
270
- const revShort = shortRev(top, commit);
271
- return { top, parsed, rev: commit, revShort, branch: currentBranch(top) };
272
- };
273
-
274
- function* commitDiff(commit, paths) {
275
- const parent = yield command(['rev-parse', '--verify', `${commit}^`]);
276
- const result = yield command(commitDiffArgs(commit, parent, paths));
277
- return parseDiff(requireOk(result).stdout);
278
- }
279
-
280
- const worktreeCommands = (paths) => [
281
- diffArgs(['--cached'], paths),
282
- diffArgs([], paths),
283
- untrackedArgs(paths),
284
- ];
285
-
286
- const readSnapshot = (cwd, paths, options) => {
287
- const top = toplevel(cwd);
288
- const rev = options.commit;
289
- if (rev) {
290
- return snapshotCommit(top, rev, runSteps(commitDiff(rev, paths), top));
291
- }
292
- const results = worktreeCommands(paths).map((args) => runGit(args, top));
293
- return snapshotWorktree(top, results);
294
- };
295
-
296
- const readSnapshotAsync = async (cwd, paths, options) => {
297
- const top = toplevel(cwd);
298
- const { commit: rev, signal } = options;
299
- if (rev) {
300
- const files = await runStepsAsync(commitDiff(rev, paths), top, signal);
301
- return snapshotCommit(top, rev, files);
302
- }
303
- const running = worktreeCommands(paths).map((args) =>
304
- runGitAsync(args, top, { signal }),
305
- );
306
- return snapshotWorktree(top, await Promise.all(running));
307
- };
308
-
309
- const applyPatch = (cwd, patch, flags) => {
310
- const args = ['apply', ...flags, '--whitespace=nowarn', '-'];
311
- requireOk(runGit(args, cwd, { input: patch }), 'apply failed');
312
- };
313
-
314
- const addItem = (top, item) => {
315
- if (item.origin === 'staged' || item.origin === 'commit') return;
316
- if (item.origin === 'untracked' || item.file.isBinary) {
317
- return void requireOk(runGit(['add', '--', item.file.newPath], top));
318
- }
319
- applyPatch(top, item.patchAdd, ['--cached']);
320
- };
321
-
322
- const unstageItem = (top, item) => {
323
- if (item.origin !== 'staged') return;
324
- if (item.file.isBinary) {
325
- const args = ['restore', '--staged', '--', itemPath(item)];
326
- return void requireOk(runGit(args, top));
327
- }
328
- applyPatch(top, item.patchAdd, ['--reverse', '--cached']);
329
- };
330
-
331
- const revertOnePath = (top, rel, items) => {
332
- const origins = new Set(items.map((item) => item.origin));
333
- const isNew = items.some((item) => item.file?.isNew);
334
- if (isNew && origins.has('staged')) {
335
- return void requireOk(runGit(['rm', '-f', '--', rel], top));
336
- }
337
- const onlyUntracked = origins.size === 1 && origins.has('untracked');
338
- if (isNew || onlyUntracked) return void fs.unlinkSync(path.join(top, rel));
339
- const args = ['restore', '-s', 'HEAD', '--worktree', '--staged', '--', rel];
340
- requireOk(runGit(args, top));
341
- };
342
-
343
- const revertItem = (top, item) => {
344
- const rel = itemPath(item);
345
- if (item.origin === 'untracked') {
346
- return void fs.unlinkSync(path.join(top, rel));
347
- }
348
- if (item.file.isBinary) {
349
- const args = ['restore', '-s', 'HEAD', '--worktree'];
350
- if (item.origin === 'staged') args.push('--staged');
351
- return void requireOk(runGit([...args, '--', rel], top));
352
- }
353
- if (item.origin === 'unstaged') {
354
- return void applyPatch(top, item.patchRevert, ['--reverse']);
355
- }
356
- applyPatch(top, item.patchRevert, ['--reverse', '--cached']);
357
- try {
358
- applyPatch(top, item.patchRevert, ['--reverse']);
359
- } catch (error) {
360
- if (!error.message.includes('does not apply')) throw error;
361
- }
362
- };
363
-
364
- const indexMode = (top, rel) => {
365
- const result = requireOk(runGit(['ls-files', '--stage', '--', rel], top));
366
- const line = result.stdout.trim();
367
- if (line) return line.split(' ')[0];
368
- try {
369
- const stat = fs.statSync(path.join(top, rel));
370
- if (stat.mode & 0o111) return '100755';
371
- } catch (error) {
372
- if (error.code !== 'ENOENT') throw error;
373
- }
374
- return '100644';
375
- };
376
-
377
- const writeIndex = (top, rel, text) => {
378
- const hashArgs = ['hash-object', '-w', `--path=${rel}`, '--stdin'];
379
- const hashed = runGit(hashArgs, top, { input: text });
380
- const sha = requireOk(hashed, 'hash-object failed').stdout.trim();
381
- const mode = indexMode(top, rel);
382
- const args = ['update-index', '--add', '--cacheinfo', mode, sha, rel];
383
- requireOk(runGit(args, top), 'update-index failed');
384
- };
385
-
386
- const editStaged = (top, rel, abs, item, text) => {
387
- const shown = requireOk(runGit(['show', `:${rel}`], top), 'show failed');
388
- const source = shown.stdout;
389
- const next = replaceBlockAdds(source, item.hunk, item.blockId, text);
390
- writeIndex(top, rel, next);
391
- let work = null;
392
- try {
393
- work = fs.readFileSync(abs, 'utf8');
394
- } catch (error) {
395
- if (error.code !== 'ENOENT') throw error;
396
- }
397
- if (work === null || work === source) fs.writeFileSync(abs, next);
398
- };
399
-
400
- const editWorktree = (abs, item, text) => {
401
- const source = fs.readFileSync(abs, 'utf8');
402
- const next = replaceBlockAdds(source, item.hunk, item.blockId, text);
403
- if (next !== source) fs.writeFileSync(abs, next);
404
- };
405
-
406
- const editItem = (top, item, text) => {
407
- if (isReadOnlyOrigin(item.origin)) return;
408
- const rel = itemPath(item);
409
- if (!rel || !item.hunk) return;
410
- const abs = path.join(top, rel);
411
- if (item.origin === 'staged') {
412
- return void editStaged(top, rel, abs, item, text);
413
- }
414
- editWorktree(abs, item, text);
415
- };
416
-
417
- const writeFile = (top, rel, text) => {
418
- if (!rel) return;
419
- const abs = path.join(top, rel);
420
- fs.mkdirSync(path.dirname(abs), { recursive: true });
421
- fs.writeFileSync(abs, text);
422
- };
423
-
424
- const stagePath = (top, rel) => {
425
- if (!rel) return;
426
- requireOk(runGit(['add', '--', rel], top));
427
- };
428
-
429
- module.exports = {
430
- requireOk,
431
- runGit,
432
- runGitAsync,
433
- command,
434
- gitOp,
435
- groupByPath,
436
- gitText,
437
- worktreeText,
438
- readDepSides,
439
- revertOnePath,
440
- toplevel,
441
- resolveRev,
442
- currentBranch,
443
- fileText,
444
- countUntrackedAdded,
445
- listScopeFiles,
446
- readSnapshot,
447
- readSnapshotAsync,
448
- editItem,
449
- writeFile,
450
- writeIndex,
451
- stagePath,
452
- addItem,
453
- unstageItem,
454
- revertItem,
455
- };
package/lib/git.js DELETED
@@ -1,79 +0,0 @@
1
- 'use strict';
2
-
3
- const capabilities = require('./capabilities.js');
4
- const { capabilitiesFor, attachCapabilities } = capabilities;
5
- const worktree = require('./git-worktree.js');
6
- const branches = require('./git-branches.js');
7
- const gitDeps = require('./git-deps.js');
8
-
9
- const load = (cwd, paths = [], options = {}) => {
10
- const snapshot = worktree.readSnapshot(cwd, paths, options);
11
- return gitDeps.finishLoad(snapshot, { ...options, paths });
12
- };
13
-
14
- const loadAsync = async (cwd, paths = [], options = {}) => {
15
- const snapshot = await worktree.readSnapshotAsync(cwd, paths, options);
16
- const deferExtras = options.deferExtras ?? true;
17
- return gitDeps.finishLoad(snapshot, { ...options, paths, deferExtras });
18
- };
19
-
20
- const createGitRepo = () =>
21
- attachCapabilities(
22
- {
23
- load,
24
- loadAsync,
25
- loadExtras: gitDeps.loadExtras,
26
- toplevel: worktree.toplevel,
27
- resolveRev: worktree.resolveRev,
28
- listFiles: worktree.listScopeFiles,
29
- fileText: worktree.fileText,
30
- add: gitDeps.addItem,
31
- addAsync: gitDeps.addItemAsync,
32
- unstage: gitDeps.unstageItem,
33
- revert: gitDeps.revertItem,
34
- revertFile: gitDeps.revertFile,
35
- edit: worktree.editItem,
36
- writeFile: worktree.writeFile,
37
- stagePath: worktree.stagePath,
38
- commit: branches.commitChanges,
39
- commitAsync: branches.commitChangesAsync,
40
- hasStaged: branches.hasStaged,
41
- lastMessage: branches.lastMessage,
42
- commitMessage: branches.commitMessage,
43
- listBranches: branches.listBranches,
44
- listCommits: branches.listCommits,
45
- currentBranch: worktree.currentBranch,
46
- checkout: branches.checkoutBranch,
47
- checkoutAsync: branches.checkoutBranchAsync,
48
- createBranch: branches.createBranch,
49
- createBranchAsync: branches.createBranchAsync,
50
- rebase: branches.rebaseBranch,
51
- rebaseAsync: branches.rebaseBranchAsync,
52
- drop: branches.dropBranch,
53
- dropAsync: branches.dropBranchAsync,
54
- dropCommit: branches.dropCommit,
55
- dropCommitAsync: branches.dropCommitAsync,
56
- applyFixup: branches.applyFixup,
57
- applyFixupAsync: branches.applyFixupAsync,
58
- reword: branches.rewordCommit,
59
- rewordAsync: branches.rewordCommitAsync,
60
- pull: branches.pullChanges,
61
- pullAsync: branches.pullChangesAsync,
62
- push: branches.pushChanges,
63
- pushAsync: branches.pushChangesAsync,
64
- },
65
- capabilitiesFor('local'),
66
- );
67
-
68
- module.exports = {
69
- ...branches,
70
- currentBranch: worktree.currentBranch,
71
- editItem: worktree.editItem,
72
- load,
73
- loadAsync,
74
- loadExtras: gitDeps.loadExtras,
75
- addItem: gitDeps.addItem,
76
- unstageItem: gitDeps.unstageItem,
77
- revertItem: gitDeps.revertItem,
78
- createGitRepo,
79
- };